Skip to main content
Bedazzled532
Inspiring
January 5, 2023
Answered

Target specific TextFrame with a particular name

  • January 5, 2023
  • 1 reply
  • 324 views

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

This topic has been closed for replies.
Correct answer rob day

Hi @Bedazzled532 , 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.

1 reply

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
January 5, 2023

Hi @Bedazzled532 , 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.

Bedazzled532
Inspiring
January 5, 2023

@rob day Thank you so much. It worked.