4 Replies Latest reply on Nov 11, 2012 11:25 PM by dulajun

    Select an object from a selected text.

    dulajun Level 2

      Using Javascript:

       

      First how to select the container textframe of a selected text?

       

      Second how to select the anchored object of a selected anchor marker character?

        • 1. Re: Select an object from a selected text.
          Laubender Adobe Community Professional & MVP

          First question:

          The "parentTextFrames" property is the one you are looking for. It is returning an array of text frames (and/or text paths). Explanation: if your selected text is threaded between two or more text frames (or text paths), "parentTextFrames" contains more than one text frame or text paths.

           

          If your selected text is one single character "parentTextFrames[0]" will do. If your selected character is part of a text path the parentTextFrames property will return a textPath object.

           

          The second question is a bit more trickier:

           

          Loop through the "pageItems" collection in the "parentTextFrames[0]" of your selected character.
          Check if their parent's (yes, that's a character!)  index number is the same as your selected character's index number.
          End the loop then. You found your object.
          Select it then. Or do what you like to do with it.

           

          See sample code:

           

          //A single character is selected:
          var mySelIndex = app.selection[0].index; 
          var myPageItems = app.selection[0].parentTextFrames[0].pageItems;
          
          
          for(var n=0;n<myPageItems.length;n++){
              if(myPageItems[n].parent.index === mySelIndex){
                  //Doing something to the found page item:
                  myPageItems[n].fillColor = "Yellow";    
                  //We found the wanted pageItem, so we could end the loop:
                  break;
                  };  
              };
          

          Uwe

          • 2. Re: Select an object from a selected text.
            dulajun Level 2

            The second question is a bit more trickier:

             

            Loop through the "pageItems" collection in the "parentTextFrames[0]" of your selected character.
            Check if their parent's (yes, that's a character!)  index number is the same as your selected character's index number.
            End the loop then. You found your object.
            Select it then. Or do what you like to do with it.

             

            See sample code:

             

            //A single character is selected:
            var mySelIndex = app.selection[0].index; 
            var myPageItems = app.selection[0].parentTextFrames[0].pageItems;
             
             
            for(var n=0;n<myPageItems.length;n++){
                if(myPageItems[n].parent.index === mySelIndex){
                    //Doing something to the found page item:
                    myPageItems[n].fillColor = "Yellow";    
                    //We found the wanted pageItem, so we could end the loop:
                    break;
                    };  
                };
            

            Uwe

            Before I wasn't know this, but now I can asure you that there is no need for looping because the Character object have pageItems property:

             

            //A single character is selected:

            var mySelIndex = app.selection[0].index;

            //var myPageItems = app.selection[0].parentTextFrames[0].pageItems;

            app.select(app.selection[0].pageItems[0]);


            • 3. Re: Select an object from a selected text.
              rajnikids Level 1

              hi there,

               

              i tested this script, the result is...only i could see the script runs very well.

               

              How can i make use of this script.. what is it actually doing... sorry i m not able to understand what the script is about.

              • 4. Re: Select an object from a selected text.
                dulajun Level 2

                I had used it in the past to select the anchored marker to copy it and reseve the anchored object location values.

                But now I used it in this broadly purpose scripting collection.

                Please join me here:

                http://forums.adobe.com/message/4832260#4832260