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++
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');
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.