Highlighted

Script to loop all selected frames and math.round geometrcBounds

New Here ,
Oct 06, 2020

Copy link to clipboard

Copied

Hi

I need a script that arranges thousands of frames. The geometricBonds of these frames should be rounded
to the nearest 5mm.

Applied to an object, the script works great.

But when I try to apply it to all selected frames, error code 11270 appears.

 

for(var i = 0; i < app.activeDocument.selection.length; i++) {

var y1 = app.activeDocument.selection[i].geometricBounds[0];
var x1 = app.activeDocument.selection[i].geometricBounds[1];
var y2 = app.activeDocument.selection[i].geometricBounds[2];
var x2 = app.activeDocument.selection[i].geometricBounds[3];

app.activeDocument.selection[i].geometricBounds = [Math.round(y1 / 5) * 5, Math.round(x1 / 5) * 5, Math.round(y2 / 5) * 5, Math.round(x2 / 5) * 5];

}

 

Thanks, 

Adobe Community Professional
Correct answer by Laubender | Adobe Community Professional

Hi David,

why is this not necessary?

I would be surprised if your script will work without any loop if you want to address more than one text frame.

 

You could store "all" text frames of a document in an array with:

app.documents[0].textFrames.everyItem().getElements();

If you want to avoid text frames on masters address all text frames on document spreads:

app.documents[0].spreads.everyItem().textFrames.everyItem().getElements();

If you want to avoid text frames on masters and pasteboards:

app.documents[0].pages.everyItem().textFrames.everyItem().getElements();

 

But this will not get text frames in nested structures like groups, anchored frames etc.pp.

 

To get really all the text frames ( and text paths ) of a document, also the nested ones, you could concat all textContainers of all stories of a document.

 

Loop the result array to

[1] Filter text paths from text frames ( if you concat textContainers )

[2] Filter frames on pasteboards or master pages

[3] Do your math with the geometric bounds of the frames.

 

Regards,
Uwe Laubender

( ACP )

TOPICS
Scripting

Views

54

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

Script to loop all selected frames and math.round geometrcBounds

New Here ,
Oct 06, 2020

Copy link to clipboard

Copied

Hi

I need a script that arranges thousands of frames. The geometricBonds of these frames should be rounded
to the nearest 5mm.

Applied to an object, the script works great.

But when I try to apply it to all selected frames, error code 11270 appears.

 

for(var i = 0; i < app.activeDocument.selection.length; i++) {

var y1 = app.activeDocument.selection[i].geometricBounds[0];
var x1 = app.activeDocument.selection[i].geometricBounds[1];
var y2 = app.activeDocument.selection[i].geometricBounds[2];
var x2 = app.activeDocument.selection[i].geometricBounds[3];

app.activeDocument.selection[i].geometricBounds = [Math.round(y1 / 5) * 5, Math.round(x1 / 5) * 5, Math.round(y2 / 5) * 5, Math.round(x2 / 5) * 5];

}

 

Thanks, 

Adobe Community Professional
Correct answer by Laubender | Adobe Community Professional

Hi David,

why is this not necessary?

I would be surprised if your script will work without any loop if you want to address more than one text frame.

 

You could store "all" text frames of a document in an array with:

app.documents[0].textFrames.everyItem().getElements();

If you want to avoid text frames on masters address all text frames on document spreads:

app.documents[0].spreads.everyItem().textFrames.everyItem().getElements();

If you want to avoid text frames on masters and pasteboards:

app.documents[0].pages.everyItem().textFrames.everyItem().getElements();

 

But this will not get text frames in nested structures like groups, anchored frames etc.pp.

 

To get really all the text frames ( and text paths ) of a document, also the nested ones, you could concat all textContainers of all stories of a document.

 

Loop the result array to

[1] Filter text paths from text frames ( if you concat textContainers )

[2] Filter frames on pasteboards or master pages

[3] Do your math with the geometric bounds of the frames.

 

Regards,
Uwe Laubender

( ACP )

TOPICS
Scripting

Views

55

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
Oct 06, 2020 0
New Here ,
Oct 06, 2020

Copy link to clipboard

Copied

Stupid me!

 

please delete thread... it is of course not necessary to take the way over 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
Reply
Loading...
Oct 06, 2020 0
Adobe Community Professional ,
Oct 06, 2020

Copy link to clipboard

Copied

Hi David,

why is this not necessary?

I would be surprised if your script will work without any loop if you want to address more than one text frame.

 

You could store "all" text frames of a document in an array with:

app.documents[0].textFrames.everyItem().getElements();

If you want to avoid text frames on masters address all text frames on document spreads:

app.documents[0].spreads.everyItem().textFrames.everyItem().getElements();

If you want to avoid text frames on masters and pasteboards:

app.documents[0].pages.everyItem().textFrames.everyItem().getElements();

 

But this will not get text frames in nested structures like groups, anchored frames etc.pp.

 

To get really all the text frames ( and text paths ) of a document, also the nested ones, you could concat all textContainers of all stories of a document.

 

Loop the result array to

[1] Filter text paths from text frames ( if you concat textContainers )

[2] Filter frames on pasteboards or master pages

[3] Do your math with the geometric bounds of the frames.

 

Regards,
Uwe Laubender

( ACP )

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
Reply
Loading...
Oct 06, 2020 1
New Here ,
Oct 06, 2020

Copy link to clipboard

Copied

You're absolutely right.

There must have been an error when saving the script or applying it in Indesign itself. When I restarted InDesign, my script worked perfectly and I thought it had returned to pre-loop status. I was wrong.

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
Reply
Loading...
Oct 06, 2020 0