Copy link to clipboard
Copied
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
1 Correct answer
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Ok sure.
Will check it as first task tomorrow morning.
Many thanks
Virender
Copy link to clipboard
Copied
Thanks Manan. your point about loop iteration is correct.
Seems I created a script after a long time

