Copy link to clipboard
Copied
In a document i have inserted a textframe and added myTextFrame into its Script Label.
When trying to get it by js using doc.textFrames.itemByName("myTextFrame"); is says the object is invalid.
When trying doc.textFrames[0] i get a textframe with label myTextFrame.
Having same issues with rectangels -> var rect = doc.rectangles.itemByName(rectName);
Copy link to clipboard
Copied
If I'm not mistaken, itemByName will get a frame according to its name in the Layers panel, not its script label.
Copy link to clipboard
Copied
Thx. ChatGPT isn't always right
Copy link to clipboard
Copied
You need to iterate either pageItems or allPageItems collections - for any item - or just textFrames collection of the document and check label property.
Copy link to clipboard
Copied
Philosophically, of course, ChatGPT is never right. It's just more or less lucky.
Copy link to clipboard
Copied
@Keld294028034yyk said: " … Thx. ChatGPT isn't always right"
Well, ChatGPT would be right, if your document would be opened with InDesign CS4 (version 6.0) or below 😉
So, Ariel ( @TᴀW ) is right.
@Robert at ID-Tasker is point on. The property you are looking for is the label property.
BUT:
To make it work with itemByName("ScriptLabelString") or item("ScriptLabelString") reset InDesign's version of the scripting environment to the one from InDesign CS4, find your text frame with item("ScriptLabelString"), store the result to a variable and reset the scripting environment to the current one.
Just tested my code with InDesign 2025 successfully that changes the fill color of all found text frames with "Yellow":
var doc = app.documents[0];
var myScriptLabel = "myTextFrame";
// Get current version of the scripting environment:
var scriptingEnvironmentVersion = app.scriptPreferences.version;
// Set the scripting environment version to the one of InDesign CS4:
app.scriptPreferences.version = "6.0";
// This could catch also MORE instances than 1 in the document:
var resultArray = app.documents[0].pageItems.item( myScriptLabel ).getElements();
// Reset the scripting environment version:
app.scriptPreferences.version = scriptingEnvironmentVersion;
// Loop the array for results to do something with the found text frames:
for( var n=0; n<resultArray.length; n++ )
{
resultArray[n].fillColor = "Yellow";
};
alert( app.scriptPreferences.version );
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
I really would like to upvote your post - but I can't... and on a lot of other threads as well - not only your replies... Is it only me?
Copy link to clipboard
Copied
Looks like it. I upvoted it just now.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Looks like it. I upvoted it just now.
By @TᴀW
I still can't... Maybe tomorrow?
By @Robert at ID-Tasker
Nope, still can't.
Copy link to clipboard
Copied
Hi Ariel,
recently, maybe for a couple of hours, I also had trouble with upvoting.
It went away…
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Were usually placing ICML files, but would like to test placing using xml and js script.
How do i parse formatted text into a textframe.
Our current ICML is <ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/D-OS" SpanColumnType="SpanColumns"><CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/bold"><Content>Nyt multiredskab sikrer ensartede græsmarker</Content><Br /></CharacterStyleRange></ParagraphStyleRange>
But we can send the content as HTML or anything else
Copy link to clipboard
Copied
ICML is a placeable format - you shouldn't be importing is as a "raw" text and then parse.
https://community.adobe.com/t5/indesign-discussions/how-do-i-load-an-icml-file/td-p/8773721
Copy link to clipboard
Copied
We do that know, but we would like to have more control over where what is placed. Creating the ICML from our CMS is a quite complex process and we cant put both content and images into the Indesign file in one flow.
We would therefor like to explore other oppotunities like opening a xml file, place content of ex. <root><textcontent><paragraph class="A-OS">Headline</paragraph><paragraph class="kommentar">Here is some <bold>Text</bold></paragraph ></textcontent> into a textFrame formatted paragraphstyle A-OS and characterstyle bold
Copy link to clipboard
Copied
We do that know, but we would like to have more control over where what is placed. Creating the ICML from our CMS is a quite complex process and we cant put both content and images into the Indesign file in one flow.
We would therefor like to explore other oppotunities like opening a xml file, place content of ex. <root><textcontent><paragraph class="A-OS">Headline</paragraph><paragraph class="kommentar">Here is some <bold>Text</bold></paragraph ></textcontent> into a textFrame formatted paragraphstyle A-OS and characterstyle bold
By @Keld294028034yyk
Why make your life so hard? 😉
Do it in two steps - import your text - in any form - TXT with pseudo tagging, RTF, InDesign Tagged Text, ICML, whatever - then process tagged images:
Bla bla [img]my-img.jpg[gmi] bla bla.
Copy link to clipboard
Copied
[...]
But we can send the content as HTML or anything else
By @Keld294028034yyk
If you generate text contents yourself - take a look at InDesign Tagged Text.
Copy link to clipboard
Copied
I would take a look into that
Copy link to clipboard
Copied
I would take a look into that
By @Keld294028034yyk
There is an old CS4 specification PDF - I think from CS4 - or you can just prepare a sample block of text - and export as InDesign Tagged Text and examine it.
OR - if you work on Windows and want to save time and money - you could use my ID-Tasker tool - isn't free - but would resolve ALL your problems...