Copy link to clipboard
Copied
Hi All,
I want to tag all of my anchored images in a CS6 document with a particular XML Tag. I am using CS6 on Windows with JavaScript. Any advice would be appreciated. Thanks.
Rick
OK, it looks like I have to add the element to the structure and then use "markup" to apply the element to my image.
// Get the selected image.
var image = app.selection[0].getElements()[0];
// Get the Story element.
var root = doc.xmlElements.item(0);
var storyElem = root.xmlElements.item(0);
// Add the "Image" element to the Story element.
var imageElem = storyElem.xmlElements.add ("Image");
// Tag the selected image with the Image tag.
image.markup (imageElem);
Copy link to clipboard
Copied
Working through this as I go: First, I need to add the appropriate xmlTag to the document, if it doesn't exist:
#target indesign
var doc = app.activeDocument;
var imageTag = doc.xmlTags.item("Image");
if (imageTag.isValid === false) {
doc.xmlTags.add ("Image");
}
Copy link to clipboard
Copied
myDoc.allGraphics will get you an array of all the graphics in the document.
Iterate it.
if (myGraphics.parent.parent.constructor.name=='Character') you got an anchored image.
The parent of a image is a rectangle. If that rectangle's parent is a charater, you got yourself an achor. might get a bit tricky if you have a image inside a group, and that group is anchored, but even so, you can test parents until you get to a Character object - so it's a anchor or a Document object -> no anchor. Simplest way of doing it is recursively, but beware of possible speed penalties.
tag it:
myGraphics.markup(myXmlElement)
Copy link to clipboard
Copied
OK, it looks like I have to add the element to the structure and then use "markup" to apply the element to my image.
// Get the selected image.
var image = app.selection[0].getElements()[0];
// Get the Story element.
var root = doc.xmlElements.item(0);
var storyElem = root.xmlElements.item(0);
// Add the "Image" element to the Story element.
var imageElem = storyElem.xmlElements.add ("Image");
// Tag the selected image with the Image tag.
image.markup (imageElem);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now