3 Replies Latest reply on Jul 16, 2009 11:17 AM by Peter Kahrel

    Help too selecting object [JS]

    (MightyJack) Level 1

      Hi there

       

      I am problems selecting an object by it id or label. In my script a list items on on page and if the text are using ParagraphStyleName "Itembox 9" i save it in array.

       

      But how do i select the object by id or label ?

       

      I have to do this to make changes on the object later.

       

      Does anyone know about good books on indesign scripting  with javascript ?

       

      Regards

      TT.

       

       

       

      test()

       

      function test(){

       

      var myDocument = app.documents.item(0);

      var myElement = myDocument.pages.item(0).pageItems;

       

      var myObjectsToSelect = new Array;

       

       

      for(myItemCounter = 0; myItemCounter < myElement.length; myItemCounter ++){

       

            var myElementID = myElement[myItemCounter].id;

       

       

         try {

          var myTextParagraphStyleName = myElement[myItemCounter].parentStory.appliedParagraphStyle.name;

       

             if(myTextParagraphStyleName == "item_box_9"){

                 $.writeln("Element Id ", myElementID);

                var myTextContents = myElement[myItemCounter].contents;

               $.writeln("Text  ", myTextContents);

               myObjectsToSelect.push(myElementID);

                } 

            }

            catch (Error) {

      // error

       

                }     

       

        }

       

       

      }

        • 1. Re: Help too selecting object [JS]
          Peter Kahrel Adobe Community Professional & MVP

          In contrast with the interface, in scripting you rarely need to select objects in order to do something with them. You collect certain text frames in your array myObjectsToSelect. If e.g. you want to move them, you'd do something like this:

           

          for (i = 0; i < myObjectsToSelect.length; i++)

              myObjectsToSelect[i].move (...);

           

          What do you want to do with them?

           

          Peter

          • 2. Re: Help too selecting object [JS]
            (MightyJack) Level 1

            Hi Peter

             

            I have  to find the OrderNumber (in a text frame) there are on top of the image and save the imagename, link and the OrderNumber in a text file.

             

            I just had problems referred to the object by label or script, to read the geometricBounds after i have found them.

             

            Tonny

            • 3. Re: Help too selecting object [JS]
              Peter Kahrel Adobe Community Professional & MVP

              >I just had problems referred to the object by label or script, to read the geometricBounds after i have found them.

               

              There's no need to refer to the objects by script label or id, just use the object references. To do something with each object's geometric bounds, do this:


              for (i = 0; i < myObjectsToSelect.length; i++)

                  myObjectsToSelect[i].geometricBounds = ....

               

              Peter