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

Not getting property of xml element within overset text

Community Beginner ,
Jul 10, 2021 Jul 10, 2021

Copy link to clipboard

Copied

Hi All,

 

I am trying to find out XML element name within the overset text, here below is the code.

 
var doc = app.documents[0];
var allStoriesArray = app.documents[0].stories.everyItem().getElements();
for(var n=0; n<allStoriesArray.length; n++)
{
var currentStory = allStoriesArray[n];
var myresult = getOversetText(currentStory);
for(var ov=0; ov<myresult.paragraphs.length; ov++)
{
var myXMLelem = myresult.paragraphs[ov].associatedXMLElements
alert(myXMLelem[0].markupTag.name)
}
}
 
function getOversetText(textFlow) {
if (!textFlow.overflows) return null;
var start = textFlow.characters[0];
if (textFlow instanceof Cell) {
if (textFlow.characters.length > 0) {
start = textFlow.texts[0].characters[textFlow.contents.length];
}
} else {
if (Number(String(app.version.split(".")[0])) > 4) {
var myTFs = textFlow.textContainers;
} else {
var myTFs = textFlow.textFrames;
}
for (var j = myTFs.length - 1; j >= 0; j--) {
if (myTFs[j].characters.length > 0) {
start = textFlow.characters[myTFs[j].characters[-1].index + 1];
break;
}
}
}
return textFlow.texts.itemByRange(start, textFlow.texts[0].characters[-1]);
}
 
Please help with what is wrong in the above code, or is there any other way to find out XML markup name of overset paragraphs.
 
Thanks,
Shonky
 
TOPICS
Scripting

Views

206

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

correct answers 1 Correct answer

Community Expert , Jul 11, 2021 Jul 11, 2021

Alternatively you can change your return value to the following

return textFlow.texts.itemByRange(start, textFlow.texts[0].characters[-1]).getElements()[0];

-Manan

Votes

Translate

Translate
Community Expert ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

Looking at the returned value of associatedXMLElements in the debugger, the following seems to work

alert(myXMLelem[0][0].markupTag.name)

-Manan

Votes

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
Community Expert ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

Alternatively you can change your return value to the following

return textFlow.texts.itemByRange(start, textFlow.texts[0].characters[-1]).getElements()[0];

-Manan

Votes

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
Community Beginner ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

Thanks it's helped!

Votes

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
Community Expert ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

Hi Shonky,

thank you for bringing up this issue.

Amazing, that associatedXMLElements throws error 45 with message "Object is invalid" when the text is in overset.

Just tested that with InDesign 2021.

 

Is this a bug or as expected?

 

Hm. We could walk through all xmlElements and look for texts[0] of every individual xmlElement.

You should be able to find the parentStory of the text and also if parentTextFrames[0] returns an error which is an indication for overset.

 

Or: You are able, at least temporarily, to resolve the overset situation by adding text frames to the story or to change point size etc.pp.

 

Regards,
Uwe Laubender

( ACP )

Votes

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
Community Beginner ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

LATEST

Thanks Uwe for looking into it. I am not sure if it's a bug or not. The solution provided by Manan is working fine.

 

Thanks,

Shonky

Votes

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