Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Tag Image with XML Tag

Community Expert ,
Aug 12, 2013 Aug 12, 2013

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

TOPICS
Scripting
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 12, 2013 Aug 12, 2013

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);

Translate
Community Expert ,
Aug 12, 2013 Aug 12, 2013

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");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 12, 2013 Aug 12, 2013

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 12, 2013 Aug 12, 2013
LATEST

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines