Copy link to clipboard
Copied
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!
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) {
...
Copy link to clipboard
Copied
Hi,
Already written:
https://www.dropbox.com/s/23lg0uimzrd7sv2/InDesign_PlayWithThePasteboard.mp4?dl=0
Best,
Michel, from FRIdNGE
Copy link to clipboard
Copied
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();
}
}
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
}
}
}
Copy link to clipboard
Copied
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!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now