2 Replies Latest reply on Sep 22, 2009 12:46 AM by Kasyan Servetsky

    Add textframe in a Layer

    kumar1981 Level 1

      Hi,

       

       

          I am unable to add textframe on layer. I have used the following code

       

       

      app.documents.add()
      app.documents[0].layers.add()
      app.documents[0].layers[0].textFrames.add()

       

       

      It throws the following error :

      "cannot create an additional item.Operation not permitted on this object."

       

      Please suggest me.

       

       

       

      Regards

      Kumar

        • 1. Re: Add textframe in a Layer
          Kasyan Servetsky Level 5

          var myDoc = app.documents.add();
          var myLayer = myDoc.layers.add({name:"My new layer"});
          var myTextFrame = myDoc.textFrames.add(myLayer);

          • 2. Re: Add textframe in a Layer
            Martin Fischer Level 2

            Hi Kumar,

             

            a textFrame is not a child of a layer but of a page or a spread.

            You can address the textFrames of a layer (as a collection of textFrames).

            But this collection is read only. So you cannot add a textFrame to a layer.

             

             

            ItemLayer is a property of a textFrame.

             

            So you will have to add a layer (like you did).

            Then you will have to add a textFrame to a page or a spread or the document.

            Finally you can set itemLayer of the new textFrame to the layer you have added.

             

            Example:

             

            var myDoc = app.documents.add();
            

            var myLayer = myDoc.layers.add();

            var myTextFrame = myDoc.pages.firstItem().textFrames.add({geometricBounds : [5,10, 200, 80]});

            myTextFrame.itemLayer = myLayer;

             

             

            Or you add the textframe with parameters like Kasyan told above. ;-)

             

            TextFrame add ([layer: Layer][, at: LocationOptions=LocationOptions.UNKNOWN][, reference: {Document | Spread | MasterSpread | Page | Layer | PageItem} ][, withProperties: Object])

             

             

            Kind regards

            Martin Fischer

            1 person found this helpful