How to loop different textFrames having same name defined in layer?

Explorer ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

I have a few textboxes in a doc and want to set the content to "xx". But below script not working.

var myDoc = app.activeDocument;

var i;

var myFrames = myDoc.allPageItems;

for (i=0; i < myFrames.length; i++)

   {

      if(myFrames.itemByName == "Idea")

         {

               myFrames[i].content = "xx";

          }

 

   }

TOPICS
Scripting

Views

71

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 , Jul 26, 2022 Jul 26, 2022

Try the following

var myDoc = app.activeDocument;
var i;
var myFrames = myDoc.allPageItems;
for (i=0; i < myFrames.length; i++){
	if(myFrames.name == "Idea")
	{
	   myFrames[i].content = "xx";
	}
 }

-Manan

Likes

Translate

Translate
Community Expert ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Try the following

var myDoc = app.activeDocument;
var i;
var myFrames = myDoc.allPageItems;
for (i=0; i < myFrames.length; i++){
	if(myFrames.name == "Idea")
	{
	   myFrames[i].content = "xx";
	}
 }

-Manan

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
Explorer ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Hi Manan, thanks for the reply.

This works => myFrames.name == "Idea" but while running the script I receive error in follwoing line:

myFrames[i].content = "xx";  // Object does not support the property or method 'content'.

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
Community Beginner ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

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
Explorer ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

LATEST

oh yes, thank you. Thanks for noticing this typo.

now i have adjusted the script to loop only in textFrames. Maybe it save a fraction of second 🙂

var myFrames = myDoc.textFrames;

 

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