2 Replies Latest reply on Jun 30, 2016 5:43 AM by JustOneBren

    Removing (deleting) all named (labelled) groups on a page

    JustOneBren Level 1

      Hoping someone can help to make the script below work as I can't seem too, I get the error: Object does not support the property or method 'itemByName'.

      I am trying to delete any groups in the document labelled "Text_Block", I can easily delete the last group with app.documents[i].pageItems.itemByName("Text_Block").remove(); but cannot create a loop to delete them all. I have tried quite a few variations and I know it will probably only be a small change but I just can't grasp it.


      var allItems = app.activeDocument.allPageItems;

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

          { if (allItems[i].itemByName == "Text_Block")

          { allItems[i].itemByName("Text_Block").remove(); }



      Many Thanks for any help with this, Bren

        • 1. Re: Removing (deleting) all named (labelled) groups on a page
          Jump_Over Level 5



          app.activeDocument.allPageItems collects graphics, images, eps..., etc as well.

          You may need to filter execution cause not every allItems[i] has a property "itemByName"


          Try modify "if" line like:

          { if (allItems[i].hasOwnProperty("itemByName") && allItems[i].itemByName == "Text_Block")



          1 person found this helpful
          • 2. Re: Removing (deleting) all named (labelled) groups on a page
            JustOneBren Level 1

            Thanks Jarek,


            Tried to use your replacement line and tried a few variations but it still wouldn't remove any of the groups (think this is more my experience than anything else).

            It did get me thinking a different way, and although i'm not sure it's the way to go, the script below seemed to work with no problems.


            for (i=0; i<30; i++)

                 { try {app.documents[0].pageItems.itemByName("Text_Block").remove();  }

                    catch (err) {""}  }


            I know there will never be more than 30 of these on the page so have set this as the max count, I don't foresee any problems but I haven't seen it done like this before so not 100% confident, please let me know if you think this isn't the way to go.


            Thank you for your help, Bren

            1 person found this helpful