Checking if an object exists on a page
Hi,
I'm trying to automate adding commonly-used elements on existing documents and I want to be able to check if an object already exists on the page so that it doesn't get added twice. I'm pretty new to JavaScript but pretty confident in Indesign CC.
Here is the script fragment that I want to do the job:
// add address window
if(!doesObjectExist(myAddressWindow)){
var myAddressWindow=myDocument.pages.item(0).textFrames.add();
var myCorners=CornerOptions.ROUNDED_CORNER;
myAddressWindow.properties={name:"myAddressWindow",geometricBounds:["33mm", "20mm", "78mm", "110mm"],strokeWeight:0.5,strokeColor:"Magenta",topLeftCornerOption:myCorners,topRightCornerOption:myCorners,bottomLeftCornerOption:myCorners,bottomRightCornerOption:myCorners};
}
function doesObjectExist(objectName){
with(myDocument.pages.everyItem){
if(name==objectName){
return true;
}
}
the myAddressWindow element always get added, even if it already exists and I can't figure out why.
Thanks and regards,
Malcolm
