Skip to main content
Participating Frequently
July 1, 2024
Answered

Creating margins and columns via javascript

  • July 1, 2024
  • 1 reply
  • 424 views

Hello

I need help.
The idea is to build a page grid. Take an indent of 0.02 from the smallest side, set the margins equal to this indent. And set 6 columns with a gutter equal to 0.02 from the smallest side (the same as margin)

 

 

 

var myDocument = app.activeDocument;
var w = myDocument.documentPreferences.pageWidth;
var h = myDocument.documentPreferences.pageHeight;
var page = myDocument.pages.item(0);

if(h > w) {var mo = {left:w*0.02,right:w*0.02,top:w*0.02,bottom:w*0.02}};   
else {var mo = {left:h*0.02,right:h*0.02,top:h*0.02,bottom:h*0.02}}
myDocument.masterSpreads.everyItem().pages.everyItem().properties = {marginPreferences:mo}
myDocument.pages.everyItem().properties = {marginPreferences:mo}
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;

 

 

 

How to add column and gutter parameter?

This topic has been closed for replies.
Correct answer rob day

Hi @maxim.maximov , If you want to set the number of columns you will have to include the properties in your mo object.

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#MarginPreference.html#d1e315211

 

Something like this:

 

app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;

var myDocument = app.activeDocument;
var w = myDocument.documentPreferences.pageWidth;
var h = myDocument.documentPreferences.pageHeight;

if (h > w) {
	var mo = {left:w*0.02,right:w*0.02,top:w*0.02,bottom:w*0.02,columnCount:6, columnGutter:w*0.02};
} else {
    var mo = {left:h*0.02,right:h*0.02,top:h*0.02,bottom:h*0.02,columnCount:6, columnGutter:h*0.02}
}

myDocument.masterSpreads.everyItem().pages.everyItem().properties = {marginPreferences:mo}
myDocument.pages.everyItem().properties = {marginPreferences:mo}

app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

1 reply

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
July 1, 2024

Hi @maxim.maximov , If you want to set the number of columns you will have to include the properties in your mo object.

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#MarginPreference.html#d1e315211

 

Something like this:

 

app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;

var myDocument = app.activeDocument;
var w = myDocument.documentPreferences.pageWidth;
var h = myDocument.documentPreferences.pageHeight;

if (h > w) {
	var mo = {left:w*0.02,right:w*0.02,top:w*0.02,bottom:w*0.02,columnCount:6, columnGutter:w*0.02};
} else {
    var mo = {left:h*0.02,right:h*0.02,top:h*0.02,bottom:h*0.02,columnCount:6, columnGutter:h*0.02}
}

myDocument.masterSpreads.everyItem().pages.everyItem().properties = {marginPreferences:mo}
myDocument.pages.everyItem().properties = {marginPreferences:mo}

app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

Participating Frequently
July 1, 2024

Thanks a lot.
I tried as in the example scripts from the manual, but with wrong syntax