Skip to main content
NexusFred
Inspiring
Feb 14, 2024 11:34 AM UTC
Answered

Script to Group all items on a page

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

 

rob day
rob dayCorrect answer
Community Expert
Feb 14, 2024 5:17 PM UTC

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

7 replies

rob day
Community Expert
Community Expert
Feb 14, 2024 2:16 PM UTC

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);
  }
}
Translate
NexusFred
NexusFredAuthor
Inspiring
Feb 14, 2024 3:48 PM UTC

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.

 

Translate
Thanks :-)
rob day
Community Expert
Community Expert
Feb 14, 2024 4:04 PM UTC

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);
  }
}

 

 

Translate
Community Expert
Feb 14, 2024 1:56 PM UTC

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?

Translate
Community Expert
Feb 14, 2024 1:56 PM UTC

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

Translate