XML Element -> get associated pageItem

Contributor ,
Mar 19, 2022 Mar 19, 2022

Copy link to clipboard

Copied

I have given XMLElements (that are already tagged) and i need to get the tagged pageItem from the xmlElement, no matter if its a textFrame, a rectangle with a placed graphic or a word in a story.

 

I tried it with

 

var pageItem = element.xmlContent.parent;
// Returns Rectangle for tagged Rectangle
// Returns Document for tagged TextFrame (i need the Texframe)
// Returns Story for tagged Text (i need the Text)

 

 

What's the best apporach to get the tagged PageItem for the XMLElement?

TOPICS
Scripting

Views

85

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Mar 20, 2022 Mar 20, 2022

Copy link to clipboard

Copied

Hi @patMorita the XMLElement object has a pageItems property that you could check. Here are the other XMLElement properties:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#XMLElement.html

 

Or you can go the other way and check for a pageItem’s or text’s associatedXMLElements property:

 

var p = app.activeDocument.selection[0].paragraphs;
var x;
for (var i = 0; i < p.length; i++){
    if (p[i].associatedXMLElements.length != 0) {
        x = p[i].associatedXMLElements;
        for (var j = 0; j < x.length; j++){
            $.writeln(x[j].markupTag.name)
        };   
    } 
};   

 

Likes

Translate

Translate

Report

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
Contributor ,
Mar 20, 2022 Mar 20, 2022

Copy link to clipboard

Copied

Thank you rob,

 

I tried pageItems before. But pageItems is always empty (length 0). The other approaches aren't suitable for what i'm planning to do. 😕

Thats why i checked all other properties and for xmlContent it says "The text content or page item referred to by the element. Can return: Text, Story, PageItem, Movie, Sound, Graphic, Table or Cell." But the returned objects aren't what they should be (check initial question)

Likes

Translate

Translate

Report

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
Contributor ,
Mar 20, 2022 Mar 20, 2022

Copy link to clipboard

Copied

LATEST

Urgs. my bad.

While writing the answer above i rechecked the code. And it has to be "xmlElement.xmlContent" and NOT "xmlElement.xmlContent.parent".

Likes

Translate

Translate

Report

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