3 Replies Latest reply on Aug 12, 2013 6:18 AM by frameexpert

    Tag Image with XML Tag

    frameexpert Level 4

      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

        • 1. Re: Tag Image with XML Tag
          frameexpert Level 4

          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");
          }
          
          • 2. Re: Tag Image with XML Tag
            Vamitul Level 4

            myDoc.allGraphics will get you an array of all the graphics in the document.

            Iterate it.

            if (myGraphics[i].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[i].markup(myXmlElement)

            • 3. Re: Tag Image with XML Tag
              frameexpert Level 4

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