0

I'm trying to apply tags to all the EPS files in the document. My code:

 #target indesign
var allItems=app.activeDocument.pageItems.everyItem().getElements().slice(0);
for(var i=0;i<allItems.length;i++)
    { 
        var allInnerItems = allItems[i].allPageItems;
        for(var j=0;j<allInnerItems.length;i++)
        {
            (allInnerItems[j].toString() == "[object EPS]") ? 
                allInnerItems[j].parent.autoTag() : alert('false');
        }
    }

The code finds all EPS and applies to their Rectangle objects AutoTag method. But I was given the error: "The object or the parent story is already tagged or cannot be taged". Besides if i choose some rectangle object with EPS and click the function "AutoTag" in user interface, it will work. Maybe somebody knows, what should I do?

Thanks in advance!

only_dimon
  • 79
  • 2
  • 11

1 Answers1

0

I think this should work for what you are trying to do.

In the inner loop you forgot to change i++ to j++.

Also, you don't have to get the string value of an object to test against it (ie. .toString() == "[object EPS]"), you can just ask for its constructor.

Finally, if you don't want any more errors for elements that are already tagged, you can add a condition to your if statement that tests whether or not the pageItem has an associatedXMLElement before attempting to autoTag() it.

var allItems = app.activeDocument.pageItems.everyItem().getElements();
for(var i=0; i<allItems.length; i++)
{ 
   var allInnerItems = allItems[i].allPageItems;
   for(var j=0;j<allInnerItems.length; j++)
   {
      var item = allInnerItems[j];
      if (item.constructor == EPS && !item.parent.associatedXMLElement) {
         item.parent.autoTag()
      } else {
         alert('false');
      }
   }
}
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43