3 Replies Latest reply on Mar 10, 2011 1:42 AM by DuffelBoat

    getting textFramePreferences when identifying a text frame by its script label

    DuffelBoat

      Hi guys,

       

      Long time lurker, first time poster. I've just spent an hour or so trying to work something out and am a bit stumped, so thought I'd post here. Should be easy for someone who knows the answer so I'm hitting my head against the wall!

       

      I'm trying to count the number of columns of a text frame using JS. If I identify the text frame by its index, it works. i.e.:

       

      var myDocument = app.activeDocument;

      var myPage = myDocument.pages.item(0);

      var myTextFrame = myPage.textFrames.item(0);

      var myFrameColumns = myTextFrame.textFramePreferences.textColumnCount;

      alert (myFrameColumns);

       

      But if I try to identify the textframe by its script label (in this case, Textarea0), it doesn't work - object invalid

       

      var myDocument = app.activeDocument;

      var myPage = myDocument.pages.item(0);

      var myTextFrame = myPage.textFrames.itemByName("Textarea0");

      var myFrameColumns = myTextFrame[0].textFramePreferences.textColumnCount;

      alert (myFrameColumns);

       

      Any ideas?

       

      Thanks,

       

      Dan

        • 1. Re: getting textFramePreferences when identifying a text frame by its script label
          DuffelBoat Level 1

          I've just found the answer myself - to do with the difference between script labels and names between cs4 and cs5. For anyone who's interested, CS5 uses Names for objects instead of Script Labels. Probably could have found that out elsewhere here but didn't know what I was looking for!

          • 2. Re: getting textFramePreferences when identifying a text frame by its script label
            csm_phil Level 4

            Hi Duffel Boat,

             

            i have found the answer to get the textFrame column count for every object (including grouped);

            i hope you expect this?

             

            var myDoc = app.activeDocument;
            var myPageItems = myDoc.allPageItems;

             

            for (var i =0; i<myPageItems.length; i++){
                app.select(myPageItems[i]);
                var mySel = app.selection[0];
                if(mySel.constructor.name == "TextFrame"){
                    if(mySel.label =="textframe"){
                        var myFrameColumns = app.selection[0].textFramePreferences.textColumnCount;
                        alert (myFrameColumns);
                        app.selection=null;
                        }
                    app.selection = null;
                    }
                }

             

            regards

            CSM_PHIL

            1 person found this helpful
            • 3. Re: getting textFramePreferences when identifying a text frame by its script label
              DuffelBoat Level 1

              Hi Phil,

               

              Thanks very much for taking the time to find a solution for me! It actually turned out that the problem was a lot simpler than that - I didn't realise that in CS5, script labels no longer work in quite the same way, and have been 'replaced' somewhat by Names, in the Layers box. So I was trying to reference an itemByName using its script label, when in the Layers box it didn't have a 'Name'. When I changed it so the Name of the frame I was trying to reference was Textarea0, my script worked.

               

              Cheers,

               

              Dan