Highlighted

## Is there an indesign script to arrange multiple objects in a matrix?

Explorer ,
Oct 25, 2020

Copied

can control the spacing and size.
The size can be controlled by calling the object style.
For example, I want to arrange 6 plates into: 2 columns and 3 rows.
The horizontal spacing is 4mm, and the vertical spacing is 8mm.

There are a lot of possible variables—are the objects different sizes, does their placement in the matrix matter, where is the position of the matrix on the page? This arranges a selection of same sized objects:

``````
#target indesign

app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

var s = app.activeDocument.selection;

//number of columns and rows
var col = 2; var row = 3;

//space between the frames
var xgut = 4;
var ygut = 8;

var colw = getPos(s)[0];
var colh = getPos(s)[1];
var xoff = getPos(s)[2];
var yoff = getPos(s)[3] - (colh + ygut);
var startX = xoff;

//make matrix using modulo to set the columns
for (var i = 0; i < s.length; i++){
if (i % col > 0) {
xoff = xoff + colw + xgut;
}else{
xoff = startX;
yoff = yoff + colh + ygut;
}
s[i].move( [xoff, yoff] );
};

/**
* Get matrix tile position
* @Param the selection to arrange
* @Return an array with colwidth, rowheight, x, and y
*
*/
function getPos(sel){
var x = sel[0].geometricBounds[1];
var y = sel[0].geometricBounds[0];

var w = 0;
var h = 0;
var a = []
for (var i = 0; i < sel.length; i++){
var b = sel[i].geometricBounds;
if (b[1] < x) {
x = b[1]
}
if (b[0] < y) {
y = b[0]
}
if (b[3]-b[1] > w) {
w = b[3]-b[1]
}
if (b[2]-b[0] > h) {
h = b[2]-b[0]
}
};
a=[w, h, x, y];
return a
}``````

TOPICS
Bug, How to, Import and export, Scripting, Server developers

Views

127

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

## Is there an indesign script to arrange multiple objects in a matrix?

Explorer ,
Oct 25, 2020

Copied

can control the spacing and size.
The size can be controlled by calling the object style.
For example, I want to arrange 6 plates into: 2 columns and 3 rows.
The horizontal spacing is 4mm, and the vertical spacing is 8mm.

There are a lot of possible variables—are the objects different sizes, does their placement in the matrix matter, where is the position of the matrix on the page? This arranges a selection of same sized objects:

``````
#target indesign

app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

var s = app.activeDocument.selection;

//number of columns and rows
var col = 2; var row = 3;

//space between the frames
var xgut = 4;
var ygut = 8;

var colw = getPos(s)[0];
var colh = getPos(s)[1];
var xoff = getPos(s)[2];
var yoff = getPos(s)[3] - (colh + ygut);
var startX = xoff;

//make matrix using modulo to set the columns
for (var i = 0; i < s.length; i++){
if (i % col > 0) {
xoff = xoff + colw + xgut;
}else{
xoff = startX;
yoff = yoff + colh + ygut;
}
s[i].move( [xoff, yoff] );
};

/**
* Get matrix tile position
* @Param the selection to arrange
* @Return an array with colwidth, rowheight, x, and y
*
*/
function getPos(sel){
var x = sel[0].geometricBounds[1];
var y = sel[0].geometricBounds[0];

var w = 0;
var h = 0;
var a = []
for (var i = 0; i < sel.length; i++){
var b = sel[i].geometricBounds;
if (b[1] < x) {
x = b[1]
}
if (b[0] < y) {
y = b[0]
}
if (b[3]-b[1] > w) {
w = b[3]-b[1]
}
if (b[2]-b[0] > h) {
h = b[2]-b[0]
}
};
a=[w, h, x, y];
return a
}``````

TOPICS
Bug, How to, Import and export, Scripting, Server developers

Views

128

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 25, 2020 0
6 Replies 6
Oct 25, 2020

Copied

Can you share some screenshots for better understanding?

Sunil

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 25, 2020 0
Explorer ,
Nov 01, 2020

Copied

Sorry, I was a bit busy lately and did not reply in time.
Like this, 6 different pictures, I want to quickly get 2 columns, 3 rows, the spacing is 4mm.

There are hundreds of such pictures, if the number of columns, rows, and spacing may also change

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 01, 2020 0
Contributor ,
Oct 25, 2020

Copied

What type of objects?

Maybe "MakeGrid" which comes with InDesign is kind of what you're looking for?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 25, 2020 1
Nov 01, 2020

Copied

There are a lot of possible variables—are the objects different sizes, does their placement in the matrix matter, where is the position of the matrix on the page? This arranges a selection of same sized objects:

``````
#target indesign

app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

var s = app.activeDocument.selection;

//number of columns and rows
var col = 2; var row = 3;

//space between the frames
var xgut = 4;
var ygut = 8;

var colw = getPos(s)[0];
var colh = getPos(s)[1];
var xoff = getPos(s)[2];
var yoff = getPos(s)[3] - (colh + ygut);
var startX = xoff;

//make matrix using modulo to set the columns
for (var i = 0; i < s.length; i++){
if (i % col > 0) {
xoff = xoff + colw + xgut;
}else{
xoff = startX;
yoff = yoff + colh + ygut;
}
s[i].move( [xoff, yoff] );
};

/**
* Get matrix tile position
* @Param the selection to arrange
* @Return an array with colwidth, rowheight, x, and y
*
*/
function getPos(sel){
var x = sel[0].geometricBounds[1];
var y = sel[0].geometricBounds[0];

var w = 0;
var h = 0;
var a = []
for (var i = 0; i < sel.length; i++){
var b = sel[i].geometricBounds;
if (b[1] < x) {
x = b[1]
}
if (b[0] < y) {
y = b[0]
}
if (b[3]-b[1] > w) {
w = b[3]-b[1]
}
if (b[2]-b[0] > h) {
h = b[2]-b[0]
}
};
a=[w, h, x, y];
return a
}``````

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 01, 2020 2
Explorer ,
Nov 01, 2020

Copied

Thanks Rob Day
You are very nice

This is exactly what i want

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 01, 2020 0
LATEST
Nov 03, 2020

Copied

This seems like a useful script so I added a dialog. It defaults to millimeters, but you can use any InDesign measurement unit, i.e. 1in. Haven’t tested much.

``````#target indesign
#targetengine "session"

//check for a doc
var s = app.activeDocument.selection;
if (s.length > 1) {
makeDialog();

//result variables
var xoff, syoff, col, row, xgut, ygut;

/**
* Make the export settings dialog
* @Return
*
*/
function makeDialog(){
var mw = 90;

//the dialog name
var theDialog = app.dialogs.add({name:"Arrange Matrix", canCancel:true});
with(theDialog){
}
var matrixX = measurementEditboxes.add({editUnits:MeasurementUnits.MILLIMETERS, editValue:0, minWidth:mw});
var matrixY = measurementEditboxes.add({editUnits:MeasurementUnits.MILLIMETERS, editValue:0, minWidth:mw});
var colGutter = measurementEditboxes.add({editUnits:MeasurementUnits.MILLIMETERS, editValue:0, minWidth:mw});
var rowGutter = measurementEditboxes.add({editUnits:MeasurementUnits.MILLIMETERS, editValue:0, minWidth:mw});
}
}
}
}

var dResult = theDialog.show();
if(dResult == true){
xoff = matrixX.editValue;
syoff = matrixY.editValue;
col = nCol.editValue;
row = nRow.editValue;
xgut = colGutter.editValue;
ygut = rowGutter.editValue
theDialog.destroy();
makeMatrix();
}else{
theDialog.destroy();
}
}

/**
* Discription
* @Return void
*
*/
function makeMatrix(){

var ohm = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
var ovm = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;

var colw = getPos(s)[0];
var colh = getPos(s)[1];
var yoff = syoff - (colh + ygut);
var startX = xoff;

//make matrix using modulo to set the columns
for (var i = 0; i < s.length; i++){
if (i % col > 0) {
xoff = xoff + colw + xgut;
}else{
xoff = startX;
yoff = yoff + colh + ygut;
}
s[i].move( [xoff, yoff] );
};

app.activeDocument.viewPreferences.horizontalMeasurementUnits = ohm;
app.activeDocument.viewPreferences.verticalMeasurementUnits = ovm;
}

/**
* Get matrix tile position
* @Param the selection to arrange
* @Return an array with colwidth, rowheight
*
*/
function getPos(sel){
var w = 0;
var h = 0;
var a = []
for (var i = 0; i < sel.length; i++){
var b = sel[i].geometricBounds;
if (b[3]-b[1] > w) {
w = b[3]-b[1]
}
if (b[2]-b[0] > h) {
h = b[2]-b[0]
}
};
a=[w, h];
return a
}``````

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 03, 2020 0
Resources
Learn and Support
Resources
Features