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

Target specific TextFrame with a particular name

Contributor ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

My Indesign file has few hundred pages.

On the master page I have created one text frame and named it as "myframe"

A paragraph style of "apage_no" is applied to this text frame. Currently it does not have any content exept the style of "apage_no" is applied.

 

apage_no style description

--------------------------------

Font: Adobe Arabic

Size: 14pts

Bullets and Numbering : Numbers with ^#

Alignment : Centre

 

I have unlocked the textframe ("myframe") on document pages.

 

Now I am running this script to add a hair space to this particular text frame ("myframe") using the following script. Its not giving any error but its not working either.

 

=== Script ===

myDoc = app.documents[0];
var txtFrame = myDoc.textFrames.everyItem().getElements();
for(var i = 0 ; i < tf.length; i++)
{
if(txtFrame.name == "myframe")
{ txtFrame.insertionPoints[-1].contents = "hair space"; }
}

##i will use unicode of hairspace which I dont have handy

=== End ===

 

What am I missing ?

Thanks

TOPICS
How to , Scripting

Views

61

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

correct answers 1 Correct answer

Community Expert , Jan 05, 2023 Jan 05, 2023

Hi @shahidr100 , the first line of your for loop has the wrong variable name—tf isn’t defined. Try this

 

 

 

 

myDoc = app.documents[0];
var txtFrame = myDoc.textFrames.everyItem().getElements();
for(var i = 0 ; i < txtFrame.length; i++){
    if(txtFrame[i].name == "myframe"){ 
        txtFrame[i].insertionPoints[-1].contents = SpecialCharacters.HAIR_SPACE; 
    }
}

 

 

 

 

EDIT: You also need to include the i count variable, should be txtFrame[i] inside the loop.

Likes

Translate

Translate
Community Expert ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

Hi @shahidr100 , the first line of your for loop has the wrong variable name—tf isn’t defined. Try this

 

 

 

 

myDoc = app.documents[0];
var txtFrame = myDoc.textFrames.everyItem().getElements();
for(var i = 0 ; i < txtFrame.length; i++){
    if(txtFrame[i].name == "myframe"){ 
        txtFrame[i].insertionPoints[-1].contents = SpecialCharacters.HAIR_SPACE; 
    }
}

 

 

 

 

EDIT: You also need to include the i count variable, should be txtFrame[i] inside the loop.

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 ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

LATEST

@rob day Thank you so much. It worked.

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