0

I am trying to look through all frames in my document and determine if they are tagged with a "copy" tag. If they are, I want to create an XML structure, and remove it's associated copy tag. This was working until yesterday. I woke up and it started saying, "myTextFrames[i].untag is not a function. I have spent a few hours trying to figure out why and I cannot. I was hoping you guys had some ideas. Thanks! -Nathan

var myTextFrames = app.activeDocument.textFrames;
var myTextFramesNo = myTextFrames.length;


for (i = 0; i < myTextFramesNo; i++)
{

if (myTextFrames[i].properties.associatedXMLElement.markupTag.name == "copy")
{
//create structure
myTextFrames[i].untag();
}

}
Natetown
  • 1
  • 1

1 Answers1

1

That's because untag is a method of an XMLElement object, not a pageItem object such as a text frame.

var myTextFrames = app.activeDocument.textFrames;
var i = myTextFrames.length;


while (i--)
{

if (myTextFrames[i].properties.associatedXMLElement instanceof XMLElement
   && myTextFrames[i].associatedXMLElement.markupTag.name == "copy")
{
//create structure
myTextFrames[i].associatedXMLElement.untag();
}

}

IU would also recommend looping backwards anytime you remove or undo things ;)

Loic
  • 2,173
  • 10
  • 13
  • Thank you sir! I'm still having a tough time navigating the InDesign object model hierarchy as it isn't clear to me how to drill down from Application to Document to Text Frame, to its methods without finding other people's examples online. Are you recommending looping backwards to avoid off-by-one errors? – Natetown Aug 25 '15 at 18:27
  • I would first suggest strongly to read the Official Adobe Scripting Guide. It deeply introduces the Object Model and the underlaying concepts. Jongware's help is a great tool that I am very fond of and used for years but it's mostly useful once you get experienced with the object model and objects hierachy within InDesign. For me it works more as a reminder that as a starter ;) – Loic Aug 26 '15 at 12:44