Skip to main content
NexusFred
Inspiring
February 14, 2024
Answered

Script to Group all items on a page

  • February 14, 2024
  • 2 replies
  • 661 views

Hello, 

I'm looking for a script to be able to create a group of all items on page and to do it for all page in the document. I found a script here https://community.adobe.com/t5/indesign-discussions/group-all-items-on-page-in-a-document/td-p/8710941 but on line :

if (spreads.pageItems.length > 1) {

I get an "undefined is not an object"

Configuration :

Windows 11

Indesign 2022 / 17.2.1 X64

Thanks

 

Correct answer rob day

So to make it easier to do, I'm trying to group the content of each page so that I only have to move one block on each page.

 

Just note that the script will take all the page items and move them onto a single Layer—grouped objects can not have pageitems on different layers

2 replies

rob day
Community Expert
Community Expert
February 14, 2024

Hi @NexusFred , Some older form posts can get corrupter. The [i] variable in Peter’s script is missing should be:

 

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

for (i = 0; i < spreads.length; i++) {
  if (spreads[i].pageItems.length > 1) {
    spreads[i].pageItems.everyItem().locked = false;
    spreads[i].groups.add (spreads[i].pageItems);
  }
}
NexusFred
NexusFredAuthor
Inspiring
February 14, 2024

Hello, @rob day  I can understant why you reply is flag as correct answer because your code for the ligne  spreads[i].groups.add (spreads.pageItems); return "Invalid value for parameter 'groupItems' of methode 'add'. Expected Array of PageItems, but received nothing." ? 🙂

 

Hello @Eugene Tyson

By pages I mean :

All items of page 1 grouped as a single group

All items of page 2 grouped as a single group

All items of page 3 grouped as a single group

... One page, One group of all item in the page.

 

In fact my problem is that I have to move all items on odd pages by 3mm to the left, and all items on even pages by 3mm to the right. So to make it easier to do, I'm trying to group the content of each page so that I only have to move one block on each page.

 

Thanks :-)
rob day
Community Expert
Community Expert
February 14, 2024

I missed a [i]—this should work:

 

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

for (i = 0; i < spreads.length; i++) {
  if (spreads[i].pageItems.length > 1) {
    spreads[i].pageItems.everyItem().locked = false;
    spreads[i].groups.add (spreads[i].pageItems);
  }
}

 

 

Community Expert
February 14, 2024

By pages - you mean 1,2,3,4 etc. in single pages

or do you need page 1 grouped

then page 2-3 in a spread? 
And so on?

Community Expert
February 14, 2024

Or if it's spreads - just page 2 items, then page 3 items - or group all of them together.