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!
I think this should work for what you are trying to do.
In the inner loop you forgot to change
i++toj++.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 itsconstructor.Finally, if you don’t want any more errors for elements that are already tagged, you can add a condition to your
ifstatement that tests whether or not thepageItemhas anassociatedXMLElementbefore attempting toautoTag()it.