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

Using array to format text in text frames

Engaged ,
Jan 22, 2019 Jan 22, 2019

Dear all,

In below code, i want to apply formatting to different text boxes but when I run it, i got error at below line. I used normal para and square bracket.

Frame(i).paragraphs.everyItem().pointSize = 9; or Frame.paragraphs.everyItem().pointSize = 9;

Please note i can only check and mark correct tomorrow morning India time.

This is the code:

var myDoc = app.documents.item(0);

var myFrame3 = myDoc.pageItems.itemByID(48127); 

var myFrame4 = myDoc.pageItems.itemByID(48425); 

var myFrame5 = myDoc.pageItems.itemByID(49442); 

var myFrame6 = myDoc.pageItems.itemByID(42930); 

var Frame = new Array (myFrame3, myFrame4, myFrame5, myFrame6);

for (var i=1; i < 5; i++)

{

Frame(i).paragraphs.everyItem().pointSize = 9;

//Frame.paragraphs.everyItem().pointSize = 9;

}

  

alert("Done")

Message was edited by: Virender Negi

TOPICS
Scripting
494
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

correct answers 1 Correct answer

Community Expert , Jan 22, 2019 Jan 22, 2019

There are multiple issue with your code

  • You run the loop from index 1 to 5, but the first index starts from 0 so the loop should be for(var i = 0; i < Frame.length; i++)
  • In order to access the array element you need to use the [] operator, () calls a method and Frame is not a method and hence you would get an error. So comment out the line with ( i ) and uncomment the line with .

After these changes things should work, if something still does not work revert back with more details.

-Manan

Translate
Community Expert ,
Jan 22, 2019 Jan 22, 2019

There are multiple issue with your code

  • You run the loop from index 1 to 5, but the first index starts from 0 so the loop should be for(var i = 0; i < Frame.length; i++)
  • In order to access the array element you need to use the [] operator, () calls a method and Frame is not a method and hence you would get an error. So comment out the line with ( i ) and uncomment the line with .

After these changes things should work, if something still does not work revert back with more details.

-Manan

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
Engaged ,
Jan 22, 2019 Jan 22, 2019

Hi Manan,

I can't check now as I am away from Mac but the main error i get at this line:

Frame.paragraphs.everyItem().pointSize = 9;

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 ,
Jan 22, 2019 Jan 22, 2019

Thats because the index you pass it in the last iteration of the loop is 4 which does not point to a valid element in the array. If you follow both my suggestions things should work.

-Manan

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
Engaged ,
Jan 22, 2019 Jan 22, 2019

Ok sure.

Will check it as first task tomorrow morning.

Many thanks

Virender

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
Engaged ,
Jan 23, 2019 Jan 23, 2019
LATEST

Thanks Manan. your point about loop iteration is correct.
Seems I created a script after a long time

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