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

Script to move all objects to pasteboard

Community Beginner ,
May 03, 2018 May 03, 2018

Hi friends,

Was wondering if anyone could help me out. In our publications, we have content automatically generated and placed page by page throughout the InDesign file and was wondering if there was a way to write a script to automatically move all content onto the pasteboard (left or right side, depending on which side of the spread the content is on).  I'm very new to the scripting world and don't have much of a background in it at all, but what we've been using is the following script that I pieced together (it may not even be the most efficient way to accomplish this):

var myObj = new Array;

myObj = app.selection;

app.activeWindow.activeSpread.groups.add(myObj);

app.activeWindow.activeSpread.groups.item(0).select();

var s =app.activeDocument.selection[0];   

s.move([-8,-.25]) 

  s.ungroup(); 

Users just select all on the left side of the spread, run the script and it moves everything off the pasteboard. We have a similar one for the right side too. Is there a way to automate this so users don't have to go page by page running this to move everything onto the pasteboard

Thank you for your patience!

TOPICS
Scripting
1.8K
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 1 Correct answer

Participant , May 07, 2018 May 07, 2018

Hi joep,

I modified the script, though it could definitely use some cleanup as it is quite rough and dirty, but I hope it gets you going in the right direction. I would also suggest learning about loops, counting objects, and how to approach and solve these problems programmatically.

var doc = app.activeDocument;

var numOfPages = doc.pages.length;

for(var i = 0; i < numOfPages; i++) {

    if(i % 2 == 1) {

        var thisPage = doc.pages.item(i);

        if(thisPage.pageItems.length >= 2) {

           

...
Translate
Guide ,
May 03, 2018 May 03, 2018
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
Participant ,
May 03, 2018 May 03, 2018

Below is a short and simple script that will find the number of pages, and for each page it will find the number of items, group them, then move to the pasteboard left or right sides depending on if the page is odd or even, then ungroup and on to the next page. You will have to adjust the move parameters to fit your needs.

var doc = app.activeDocument;

var numOfPages = doc.pages.length;

for(var i = 0; i < numOfPages; i++) {

    if(i % 2 == 1) {

        var thisPage = doc.pages.item(i);

        var items = thisPage.pageItems.everyItem();

        var group = doc.groups.add(items);

        group.move([10, 0])

        group.ungroup();

   } else {

       var thisPage = doc.pages.item(i);

       var items = thisPage.pageItems.everyItem();

       var group = doc.groups.add(items);

       group.move([-6, 0])

       group.ungroup();

   }

}

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 Beginner ,
May 04, 2018 May 04, 2018

Thank you Benreyn, think I'm getting close. I have a follow-up question:

1) How would I set this up to work even if some pages are empty or there is only one item on the page? If I run this with a blank page (or a page with just one item) I'll get a "Cannot create page item. No valid parent found" error.

If I add 2 objects to all of the pages that script seems to work great and I can adjust the parameters accordingly. Just wondering if there's a way for it to A) ignore pages that have 0 objects and B) still move an object if it's the only one on the page.

Thanks again!

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
Participant ,
May 07, 2018 May 07, 2018

Hi joep,

I modified the script, though it could definitely use some cleanup as it is quite rough and dirty, but I hope it gets you going in the right direction. I would also suggest learning about loops, counting objects, and how to approach and solve these problems programmatically.

var doc = app.activeDocument;

var numOfPages = doc.pages.length;

for(var i = 0; i < numOfPages; i++) {

    if(i % 2 == 1) {

        var thisPage = doc.pages.item(i);

        if(thisPage.pageItems.length >= 2) {

            var items = thisPage.pageItems.everyItem();

            var group = doc.groups.add(items);

            group.move([10, 0]);

            group.ungroup();

        } else if (thisPage.pageItems.length == 1) {

            var item = thisPage.pageItems.item(0);

            item.move([10, 0]);

        } else {

            //do nothing

        }

   } else {

        var thisPage = doc.pages.item(i);

        if(thisPage.pageItems.length >= 2) {

            var items = thisPage.pageItems.everyItem();

            var group = doc.groups.add(items);

            group.move([-6, 0]);

            group.ungroup();

        } else if (thisPage.pageItems.length == 1) {

            var item = thisPage.pageItems.item(0);

            item.move([-6, 0]);

        } else {

            //do nothing

        }

   }

}

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 Beginner ,
May 07, 2018 May 07, 2018
LATEST

This looks to be exactly what we were looking for, thank you so much for your help! I'm learning one day at a time, as a graphic designer first, writing code has always been a struggle, so I appreciate the patience of users like yourself willing to help educate me!

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