🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
10 messages
10 total messages Started by Tim_Judy Fri, 20 Feb 2009 15:52
Help with syntax: Adding pages JS CS3
#1027
Author: Tim_Judy
Date: Fri, 20 Feb 2009 15:52
16 lines
1339 bytes
I'm fairly new to scripting and I'm trying to write a script to add pages, inserting one after each existing page. We're doing postcards using a 4-up data merge. On the back of each card is the data merge/address (again, 4 to a page). Since the merge doesn't work on alternating pages, we want to do the merge first, then add the face pages afterward.
This is my code thus far:

var myPages = app.activeDocument.pages;
var myCounter = myPages.length-1;

for (i = myCounter; i >= 0; i--){

	myPages.add(LocationOptions.AFTER)...;

	}

On the line "myPages.add(LocationOptions.AFTER)..." I have tried every combination I can think of based on the CS3 Object Model that comes with Extend Script. Every one except the right one.

Many thanks for you help.
-Tim
Re: Help with syntax: Adding pages JS CS3
#1028
Author: Peter Kahrel
Date: Fri, 20 Feb 2009 15:54
7 lines
759 bytes
You add pages to a document:

app.activeDocument.pages.add()

Pages are added at the end of the document by default.

Peter
Re: Help with syntax: Adding pages JS CS3
#1029
Author: Peter Kahrel
Date: Fri, 20 Feb 2009 15:55
7 lines
766 bytes
You add pages to a document, not to another page:

app.activeDocument.pages.add()

Pages are added at the end of the document by default.

Peter
Re: Help with syntax: Adding pages JS CS3
#1052
Author: Timblin_Judy
Date: Sun, 22 Feb 2009 17:13
5 lines
1121 bytes
Thanks, but I already knew that. This line from the ID Object model:
Pages.add(at:LocationOptions, reference:any, withProperties:Object):Page
would seem to imply that I can specify where to add pages. But I can't figure out how to make use of it.
To further clarify what I'm want to do, using a deck of cards as an analogy: Say I'm starting with all red cards. I want to add a black card after each red so that when I'm finished and you flip thru the deck you alternate between red and black.
-Tim
Re: Help with syntax: Adding pages JS CS3
#1076
Author: Jeremy_Bowman
Date: Mon, 23 Feb 2009 17:27
11 lines
1081 bytes
I'm a beginner too (so take what Peter says more seriously than what I say!) but this works for me (select a text frame on the page you want to add a page after):

var myDocument = app.activeDocument;
var mySelection = app.selection[0];
var myPage = mySelection.parent;
myPages = myDocument.pages;
myPages.add(1634104421, myPage);

BTW, in my brief scripting career I've always found those numbers more reliable than the keyword enumerations.

Jeremy
Re: Help with syntax: Adding pages JS CS3
#1079
Author: Jeremy_Bowman
Date: Mon, 23 Feb 2009 19:05
7 lines
1007 bytes
I wonder if this works?

var myDocument = app.activeDocument;
var myPages = myDocument.pages;
var myCounter = 0;
for (var myHowMany = 0; myHowMany < myPages.length; myHowMany++){ myPage = myPages[myCounter]; myPages.add(LocationOptions.AFTER, myPage); myCounter = myCounter+2; if (myCounter > myPages.length-1) break;
       }
Re: Help with syntax: Adding pages JS CS3
#1083
Author: Peter Kahrel
Date: Mon, 23 Feb 2009 19:59
11 lines
1067 bytes
Tim,

Every time you add a page to the document, you change the myDoc.pages collection, and therefore, the value of myDoc.pages.length as well. To guard yourself against that, start at the back of the document and work your way to the front. This example adds a page before evry page in the document:

p = app.activeDocument.pages; 
for (i = p.length-1; i > -1; i--) 
   app.activeDocument.pages.add (LocationOptions.before, p[i]);



Peter
Re: Help with syntax: Adding pages JS CS3
#1085
Author: Peter Kahrel
Date: Mon, 23 Feb 2009 20:01
10 lines
686 bytes

      I wonder if this works?




There's only one way to find out...

Peter
Re: Help with syntax: Adding pages JS CS3
#1094
Author: Jeremy_Bowman
Date: Mon, 23 Feb 2009 21:51
3 lines
695 bytes
As I expected, Peter's solution is much more elegant than my own!

Jeremy
Re: Help with syntax: Adding pages JS CS3
#966
Author: Timblin_Judy
Date: Tue, 24 Feb 2009 16:47
3 lines
644 bytes
I got it working now.
Thanks guys!
-Tim
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads