4 Replies Latest reply on Feb 6, 2015 8:56 PM by Chinnadk

    How to findout the achored text frame based on label and remove?

    Jackkistens

      Dear All,

       

      how to findout the anchored text frame based on Label [ex: textFrame.label = "ABC"] and remove this particular anchor frame. please suggest me.

       

      regards,

      Jack

        • 1. Re: How to findout the achored text frame based on label and remove?
          Sajeev Sridharan Level 4

          Try this,

           

          for (var idx = 0; idx < app.activeDocument.allPageItems.length; idx++)//this line will search all page items
          {
              var pageItem = document.allPageItems[idx];
              if(pageItem.label == "ABC")
              {
                  pageItem.select();
                  pageItem.remove();
             }
          }
          

           

           

          Vandy

          • 2. Re: How to findout the achored text frame based on label and remove?
            Laubender Adobe Community Professional & MVP

            @vandy88 – did you test your code?

             

            @Jack – if I get this right, you have three conditions:

             

            1. The object you want to remove is a TextFrame

            2. The TextFrame is anchored

            3. The TextFrame is labeled with a String: "ABC"

             

            Other conditions?
            Like: The TextFrame could be part of a group, that itself is anchored?

             

             

            Before iterating over all page items available, I think it would be better to iterate on all Stories and their text frames (textContainers) and check:

             

            1. Is the parent of the text frame a character? => THEN it's anchored

            2. And is there a label reading "ABC" ?

             

            If both conditions are met, remove the text frame.

            The question is: Should we do it immediately?
            Or should we mark it somehow and the user could decide on a later step to remove it?

             

            OR MAYBE BETTER:

            Do a GREP search on anchored objects by script and check, if the found item is a text frame and is labeled "ABC".

            The found anchor character is a texts object and inherits the text frame (or a different object).

             

            //Note: The variable myFoundCharacter is not defined yet.
            myFoundCharacter.pageItems[0].getElements()[0];
            

             

            would reveal the true nature of the anchored object.

             

            Of course the situation could be more difficult, because the labeled text frame could be part of a group, part of a nested object, that itself is anchored…

             

            Uwe

            • 3. Re: How to findout the achored text frame based on label and remove?
              Jackkistens Level 1

              Hi Uwe,

               

              Anchored textFrame, if contain the label value "ABC" should remove all. i think you got my point.

               

              Regards,

              ~jack

              • 4. Re: How to findout the achored text frame based on label and remove?
                Chinnadk Level 4

                Is this you need?

                 

                var doc = app.activeDocument,
                    _stories = doc.stories;
                
                for(var i =0;i<_stories.length;i++)
                {
                        var pi = _stories[i].textFrames;
                        for(var j=pi.length-1 ;j>=0;j--)
                        {
                                if(pi[j].parent instanceof Character && pi[j].label == "ABC")
                                {
                                         pi[j].remove();
                                    }
                            }
                    }
                

                 

                Regards,

                Chinna