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

Can't find textframe using doc.textFrames.itemByName("myTextFrame");

Community Beginner ,
Apr 03, 2025 Apr 03, 2025

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

 Skærmbillede 2025-04-03 110119.png

TOPICS
Scripting
294
Translate
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
People's Champ ,
Apr 03, 2025 Apr 03, 2025

If I'm not mistaken, itemByName will get a frame according to its name in the Layers panel, not its script label.

Translate
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 ,
Apr 03, 2025 Apr 03, 2025

Thx. ChatGPT isn't always right

Translate
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 ,
Apr 03, 2025 Apr 03, 2025

@Keld294028034yyk

 

You need to iterate either pageItems or allPageItems collections - for any item - or just textFrames collection of the document and check label property. 

 

Translate
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
People's Champ ,
Apr 03, 2025 Apr 03, 2025

Philosophically, of course, ChatGPT is never right. It's just more or less lucky.

Translate
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 ,
Apr 03, 2025 Apr 03, 2025

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

Translate
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 ,
Apr 03, 2025 Apr 03, 2025

@Laubender

 

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? 

 

Translate
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
People's Champ ,
Apr 03, 2025 Apr 03, 2025

Looks like it. I upvoted it just now.

Translate
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 ,
Apr 03, 2025 Apr 03, 2025
quote

Looks like it. I upvoted it just now.


By @TᴀW

 

I still can't... Maybe tomorrow? 

 

Translate
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 ,
Apr 04, 2025 Apr 04, 2025
LATEST
quote
quote

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. 

 

Translate
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 ,
Apr 04, 2025 Apr 04, 2025

Hi Ariel,

recently, maybe for a couple of hours, I also had trouble with upvoting.

It went away…

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Translate
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 ,
Apr 03, 2025 Apr 03, 2025

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

Translate
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 ,
Apr 03, 2025 Apr 03, 2025

@Keld294028034yyk

 

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

 

Translate
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 ,
Apr 03, 2025 Apr 03, 2025

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

Translate
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 ,
Apr 03, 2025 Apr 03, 2025
quote

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. 

 

 

Translate
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 ,
Apr 03, 2025 Apr 03, 2025
quote

[...] 
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.

 

Translate
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 ,
Apr 03, 2025 Apr 03, 2025

I would take a look into that 

Translate
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 ,
Apr 03, 2025 Apr 03, 2025
quote

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... 

 

Translate
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