Skip to main content
Known Participant
March 7, 2008
Question

[JS CS3] Loading master pages from one ID file into another

  • March 7, 2008
  • 5 replies
  • 612 views
I'm having trouble working this out...

I'm trying to create a script that will assume 1 document is open when the script is run. It will then create a new document, and load the master pages from the first document into the new document. I can't figure out how to reference the original document once the new document has been created. Here is what I have so far...

var oldDocument = app.activeDocument;
// Create a new document with the correct page size, etc.
var newDocument = app.documents.add();
newDocument.documentPreferences.pageWidth = 7.625;
newDocument.documentPreferences.pageHeight = 10;
// Load masters from old document
newDocument.loadMasters(app.documents.item(0).fullName);

The last line is not correct, obviously. How do I reference the first document while working on the second? Thx.
This topic has been closed for replies.

5 replies

Inspiring
March 10, 2008
Ah, in that case:

newDocument.LoadMasters(oldDocument.fullName)

would have done the trick.

Dave
Known Participant
March 10, 2008
newDocument.LoadMasters(oldDocument) doesn't work. I get the error "Invalid value for paramenter 'from' of event 'loadMasters'. Expected File, but received Document". So I guess loadMasters expects a reference to a file name.

The approach suggested by Kasyan works great. Thank you to you both, Dave and Kasyan!
Participant
March 8, 2008
Thanks Dave

http://www.kobimedya.com
Kasyan Servetsky
Legend
March 8, 2008
var oldDocName = app.activeDocument.name;
// Create a new document with the correct page size, etc.
var newDocument = app.documents.add();
newDocument.documentPreferences.pageWidth = 7.625;
newDocument.documentPreferences.pageHeight = 10;
// Load masters from old document
newDocument.loadMasters(app.documents.item(oldDocName).fullName);
Inspiring
March 7, 2008
It's still oldDocument:

newDocument.loadMasters(oldDocument);

Doesn't that work? I didn't actually realize there was a loadMasters method for documents!

Dave