Copy link to clipboard
Copied
Hi gang,
I am looking for a script that will make it possible to generate new master (parent) pages within the ID document along with margins and columns. In script code they are referred to as MasterSpreads, I believe.
Thanks for any guidance you might add!
--Mike Witherell
Copy link to clipboard
Copied
Bit more context needed.
app.activeDocument.masterSpreads.add()
will add one. You can pass lots of different properties to it.
Copy link to clipboard
Copied
Hi @Mike Witherell,
Try the following
var ms = app.documents[0].masterSpreads.add()
for(var i = 0; i < ms.pages.length; i++)
{
var mp = ms.pages[i].marginPreferences
mp.top = 20
mp.bottom = 15
mp.left = 10
mp.right = 10
mp.columnGutter = 5
mp.columnCount = 2
}
Other properties that you can use can be referenced at the following link
https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#MarginPreference.html
-Manan
Copy link to clipboard
Copied
Hi Mike,
it's a bit unclear where the parameters for margins and columns should come from.
From the document setup?
From a parent spread that is already there?
From a document spread that is already there?
From a different document's parent spread?
Fixed values like Manan is doing this?
Do you need a UI to type in the margin and column values?
( Why do you need a script then? )
Something else?
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Many thanks to you all, Manan, Uwe, Brian.
So far, I have added a few lines to declare the measurement units as PICAS.
Further, I have wrapped it in a bit of code to undo in 1 undo.
I have realized I don't need to declare the margins, because it will inherit those.
I have successfully repeated the code to make 3 new masterSpreads.
What I need to figure out is how to name each new master as it is being made. Is it name = or baseName = , and how is that written? My various attempts are all incorrect. (I'm an under-experienced scripter, as you doubtless know).
Copy link to clipboard
Copied
Away from my computer, but I think you can do it when you make the spread like so: app.activeDocument.masterSpreads.add({name: "myName"})
Edit: I'm wrong. See Uwe's response.
Copy link to clipboard
Copied
Hi Mike,
look into the list of available properties.
Here we have namePrefix and baseName. So you can do this like that:
app.documents[0].masterSpreads.add
(
{
namePrefix : "Z" ,
baseName : "Hello Mike"
}
);
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Uwe, thank you. I searched in the ExtendScript (16.) but didn't get uncover that info.
I will put this in my emerging script and report back to you later what my results are.
Copy link to clipboard
Copied
Hi Mike,
here the document object model description compiled by Gregor Fellenz:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#MasterSpread.html
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Uwe,
Thanks, yes, that is the reference I have been studying (a bit of a slow learner, I am afraid).
Hooray! I got this to work:
var ms = app.documents[0].masterSpreads.add({namePrefix : "2C" , baseName : "2-Column"})
Copy link to clipboard
Copied
var ms = app.documents[0].masterSpreads.add({namePrefix : "2C" , baseName : "2-Column"})
for(var i = 0; i < ms.pages.length; i++)
{
var mp = ms.pages[i].marginPreferences
mp.columnGutter = 1.5
mp.columnCount = 2
}
I just repeated this 3 times changing the columnCount = to 2, 3, and 4 in order to get 3 new master page sets.
Many thanks for the education Uwe and Manan!