Hello,
can anybody tell me? how to add new page with specific marginal preferences?is it possible to add margin setting at time adding page?
Hi Govind,
Please try the below 2 JS code.
1. This below JS code is will create a new document and adding margin preferences.
myDocument = app.documents.add();
with (myDocument.pages.item(0).marginPreferences){
columnCount = 3;
//columnGutter can be a number or a measurement string.
columnGutter = "1p";
bottom = "6p"
//When document.documentPreferences.facingPages == true,
//"left" means inside; "right" means outside.
left = "6p"
right = "4p"
top = "4p"
}
2. The below JS code is working in active Document.
var myDoc = app.activeDocument;
var myPg = myDoc.pages[-1];
var myLastPage = myDoc.pages.add(LocationOptions.AT_END, myPg);
with(myLastPage.marginPreferences){
bottom = "6p"
left = "6p"
right = "4p"
top = "4p"
}
thx
csm_phil
FWIW, "with" is generally frowned on as bad practice (for a number of reasons). This is a much better way to set many properties at once:
myDocument = app.documents.add();
myDocument.pages.item(0).marginPreferences.properties = {
columnCount : 3,
//columnGutter can be a number or a measurement string.
columnGutter : "1p",
bottom : "6p",
//When document.documentPreferences.facingPages == true,
//"left" means inside; "right" means outside.
left : "6p",
right : "4p",
top : "4p"
}
and:
var myDoc = app.activeDocument;
var myPg = myDoc.pages.item(-1);
var myLastPage = myDoc.pages.add(LocationOptions.AT_END, myPg);
myLastPage.marginPreferences.properties = {
bottom : "6p",
left : "6p",
right : "4p",
top : "4p"
}
Hi Harbs,
We know your genius, i agree with your feedback becasue, i learnt from you lot of things,
May i know if you said "with" is bad practice then why should adobe realsed the InDesign Scripting guide using more places in "with" concepts. So in this case still Adobe don't know "with" is the bad concepts so adobe need to change the InDesign CS5 scripting guide, "properties" instead of "with".
please clarify to me and also explain the problems i want to learn.
thx
csm_phil
Part of Harbs' genius comes from using Google when needed. (I think
)
http://blog.boyet.com/blog/javascriptlessons/javascript-for-c-programm ers-the-with-statement-considered-harmful/ .. and many more can be found with "with statement considered harmful".
There is nothing wrong with setting the properties in one line, except that it gets progressively harder to read, understand, maintain, and update:
myDoc = app.activeDocument;
var myLastPage = myDoc.pages.add(LocationOptions.AT_END, undefined, {marginPreferences:{bottom:"6p", left:"6p", right:"4p", top:"4p"} });
Note that since you are using 'LocationOptions.AT_END', you don't have to use a reference to any page. That is only required when you want to insert a page anywhere except at the end or the start.
csm_phil wrote:
.. May i know if you said "with" is bad practice then why should adobe realsed the InDesign Scripting guide using more places in "with" concepts. So in this case still Adobe don't know "with" is the bad concepts so adobe need to change the InDesign CS5 scripting guide, "properties" instead of "with".
If you read the articles on why "with" is considered harmful, you can see that Adobe's usage in the example scripts is perfectly alright.
I use "with" myself all the time, as it is a convenient shortcut when used properly. There is an added penalty in the form of a slightly longer running time, but use it I mainly to construct dialogs -- hardly a "time critical" function, and using "with" they are considerably easier to read, maintain, etc.
Yes. Google is everyone's friend... ![]()
Part of the reason I say not to use with particularly in InDesign comes from experience.
"with" performs poorly performance-wise and jumps through all kinds of hoops to work at all. I once had a really obscure issue with InDesign dialogs, "with" and local variables. I don't remember all the details but the solution was to get rid of "with"...
The reason Ole used "with" for the script samples was to retain consistancy between the different languages in the examples -- not because it was inherently good... ![]()
When setting multiple properties, "properties" has the advantage that you only need to interact with the C++ level once, so it's inherently more efficient than any other method. The fact that it's easy to read is just an added plus... ![]()
Harbs
Hi Harbs,
The bleow you said you faced some probelms while using the "with" now you said you recommended don't use "with" its okay. When you faced the problems why you not to intimate to Adobe if you tell the problems to Adobe they will alert to modify and realsed the Scripting Guide for your method like "propeties" so in this case you have not identify to adobe now you said i faced the problems. Anyway now you please highlight to adobe and next version Adobe InDesign CS6 they have to use your way. So easily to beginner to learn this is my suggestion.
When setting multiple properties, "properties" has the advantage that you only need to interact with the C++ level once, so it's inherently more efficient than any other method. The fact that it's easy to read is just an added plus...
thx
csm_phil
North America
Europe, Middle East and Africa
Asia Pacific