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

Script to Group all items on a page

Explorer ,
Feb 14, 2024 Feb 14, 2024

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/87109... 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

 

Thanks 🙂
TOPICS
Scripting
538
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 2 Correct answers

Community Expert , Feb 14, 2024 Feb 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);
  }
}
Translate
Community Expert , Feb 14, 2024 Feb 14, 2024

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

Translate
Community Expert ,
Feb 14, 2024 Feb 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?

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 ,
Feb 14, 2024 Feb 14, 2024

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

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 ,
Feb 14, 2024 Feb 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);
  }
}
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
Explorer ,
Feb 14, 2024 Feb 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 🙂
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 ,
Feb 14, 2024 Feb 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);
  }
}

 

 

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 ,
Feb 14, 2024 Feb 14, 2024
LATEST

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

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