Step and Repeat Script help
Copy link to clipboard
Copied
I'm a scripting virgin and was wondering if someone could help with what I imagine is a simple bit of script to add two fields in the dialogue box - no of copies horizontal and vertical:
I've got a step and repeat script, but this works the same as CS3 step and repeat from the Edit menu, where you get n copies of a placed object on an offset of x and y. What I'd like is to make n by m copies of a placed object in one go (i.e. impose a grid of objects on a defined offset to get a sheet full of copies).
Any takers? Thanx in advance if you have any eye-deers... :D
The step and repeat script I've got is as follows:
--
tell application "Adobe InDesign CS3"
if (count documents) > 0 then
set mySelection to selection
if (count mySelection) > 0 then
set myObjects to {}
repeat with myCounter from 1 to (count mySelection)
if class of item myCounter of mySelection is rectangle or ¬
class of item myCounter of mySelection is oval or ¬
class of item myCounter of mySelection is polygon or ¬
class of item myCounter of mySelection is graphic line or ¬
class of item myCounter of mySelection is text frame then
copy item myCounter of mySelection to end of myObjects
end if
end repeat
if (count myObjects) > 0 then
my myDisplayDialog(myObjects)
end if
else
display dialog "Please select an object and try again."
end if
else
display dialog "Please open a document, select an object, and try again."
end if
end tell
on myDisplayDialog(myObjects)
set myProxyList to {"TopLeft", "Top", "TopRight", "Left", "Center", "Right", "BottomLeft", "Bottom", "BottomRight"}
tell application "Adobe InDesign CS3"
set myDialog to make dialog with properties {name:"StepAndRepeat"}
tell myDialog
tell (make dialog column)
make static text with properties {static label:"Repeat Count:"}
--Spacer.
make static text
make static text with properties {static label:"Horizontal Offset:"}
make static text with properties {static label:"Vertical Offset:"}
--Spacer.
make static text
make static text with properties {static label:"Rotation:"}
make static text with properties {static label:"Skew:"}
--Spacer.
make static text
make static text with properties {static label:"Fill Tint:"}
make static text with properties {static label:"Stroke Tint:"}
end tell
tell (make dialog column)
set myRepeatField to make integer editbox with properties {edit value:2}
--Spacer.
make static text
set myXOffsetField to make measurement editbox with properties {edit value:0}
set myYOffsetField to make measurement editbox with properties {edit value:0}
--Spacer.
make static text
set myRotationField to make angle editbox with properties {edit value:0}
set mySkewField to make angle editbox with properties {edit value:0}
--Spacer.
make static text
set myFillTintField to make real editbox with properties {edit value:0}
set myStrokeTintField to make real editbox with properties {edit value:0}
end tell
tell (make dialog column)
--Spacer.
make static text
--Spacer.
make static text
make static text with properties {static label:"Stroke Weight:"}
make static text with properties {static label:"Opacity:"}
--Spacer.
make static text
make static text with properties {static label:"Horizontal Scale:"}
make static text with properties {static label:"Vertical Scale:"}
--Spacer.
make static text
--Spacer.
make static text
make static text with properties {static label:"Proxy:"}
end tell
tell (make dialog column)
--Spacer.
make static text
--Spacer.
make static text
set myStrokeWeightField to make measurement editbox with properties {edit value:0}
set myOpacityField to make real editbox with properties {edit value:0}
--Spacer.
Copy link to clipboard
Copied
Take a look at the MakeGrid.applecript example script that was installed with your copy of CS3. That should get you started.
Thanks,
Ole
Copy link to clipboard
Copied
I've made this script which duplicates the selected object in both x and y directions, but does not complete the grid - how can I set myObjects to be all the x duplicates BEFORE it runs the y duplicates?
thanks for your help so far!
-------
tell application "Adobe InDesign CS3"
if (count documents) > 0 then
set mySelection to selection
if (count mySelection) > 0 then
set myObjects to {}
repeat with myCounter from 1 to (count mySelection)
if class of item myCounter of mySelection is rectangle or ¬
class of item myCounter of mySelection is oval or ¬
class of item myCounter of mySelection is polygon or ¬
class of item myCounter of mySelection is graphic line or ¬
class of item myCounter of mySelection is text frame then
copy item myCounter of mySelection to end of myObjects
end if
end repeat
if (count myObjects) > 0 then
my myDisplayDialog(myObjects)
end if
else
display dialog "Please select an object and try again."
end if
else
display dialog "Please open a document, select an object, and try again."
end if
end tell
on myDisplayDialog(myObjects)
tell application "Adobe InDesign CS3"
set myDialog to make dialog with properties {name:"StepAndRepeat"}
tell myDialog
tell (make dialog column)
make static text with properties {static label:"Rows:"}
make static text with properties {static label:"Cols:"}
--Spacer.
make static text
make static text with properties {static label:"Horizontal Offset:"}
make static text with properties {static label:"Vertical Offset:"}
end tell
tell (make dialog column)
set myRowsField to make integer editbox with properties {edit value:2}
set myColsField to make integer editbox with properties {edit value:2}
--Spacer.
make static text
set myXOffsetField to make measurement editbox with properties {edit value:0}
set myYOffsetField to make measurement editbox with properties {edit value:0}
end tell
end tell
set myResult to show myDialog
if myResult is true then
--Gather the user input from the dialog controls.
set myNumberOfRows to edit value of myRowsField
set myNumberOfCols to edit value of myColsField
set myXOffset to edit value of myXOffsetField
set myYOffset to edit value of myYOffsetField
destroy myDialog
my myStepAndRepeat(myObjects, myNumberOfRows, myNumberOfCols, myXOffset, myYOffset)
else
destroy myDialog
end if
end tell
end myDisplayDialog
on myStepAndRepeat(myObjects, myNumberOfRows, myNumberOfCols, myXOffset, myYOffset)
tell application "Adobe InDesign CS3"
repeat with myCounter from 1 to myNumberOfRows
repeat with myObjectCounter from 1 to (count myObjects)
set myObject to item myObjectCounter of myObjects
set myObject to duplicate myObject
tell myObject
move by {myXOffset * myCounter, 0}
end tell
end repeat
end repeat
repeat with myCounter from 1 to myNumberOfCols
repeat with myObjectCounter from 1 to (count myObjects)
set myObject to item myObjectCounter of myObjects
set myObject to duplicate myObject
tell myObject
move by {0, myYOffset * myCounter}
end tell
end repeat
end repeat
end tell
end myStepAndRepeat
Copy link to clipboard
Copied
Copy link to clipboard
Copied
//StepAndRepeatImposition.jsx
//An InDesign CS JavaScript
//www.theonconnection.com
//Duplicates objects in a grid. Useful to impose for print.
if (app.documents.length != 0){
if (app.selection.length > 0){
myObjects = app.selection;
if(myObjects.length > 0){
myDisplayDialog(myObjects);
}
else{
alert("Please select a rectangle, polygon, graphic line, oval, or text frame and try again.");
}
}
else{
alert("Please select an object and try again.");
}
}
else{
alert("Please open a document, select an object, and try again.");
}
//Display dialog.
function myDisplayDialog(myObjects){
myDialog = app.dialogs.add();
myDialog.name = "Step And Repeat Imposition";
//myProxyColumn = myDialog.dialogColumns.add();
myLabelsColumn1 = myDialog.dialogColumns.add();
myLabelsColumn1.staticTexts.add({staticLabel:"Rows:"});
myLabelsColumn1.staticTexts.add({staticLabel:"Columns:"});
//Spacer.
myLabelsColumn1.staticTexts.add();
myLabelsColumn1.staticTexts.add({staticLabel:"Horizontal Offset:"});
myLabelsColumn1.staticTexts.add({staticLabel:"Vertical Offset:"});
//Spacer.
myControlsColumn1 = myDialog.dialogColumns.add();
myRowsField = myControlsColumn1.integerEditboxes.add({editValue:2});
myColumnsField = myControlsColumn1.integerEditboxes.add({editValue:2});
myControlsColumn1.staticTexts.add();
myXOffsetField = myControlsColumn1.measurementEditboxes.add({editValue:0});
myYOffsetField = myControlsColumn1.measurementEditboxes.add({editValue:0});
//Spacer.
myResult = myDialog.show();
if(myResult == true){
//Gather the user input from the dialog controls.
myNumberOfRows = myRowsField.editValue;
myNumberOfColumns = myColumnsField.editValue;
myXOffset = myXOffsetField.editValue;
myYOffset = myYOffsetField.editValue;
myDialog.destroy();
myStepAndRepeat(myObjects, myNumberOfRows, myNumberOfColumns, myXOffset, myYOffset);
}
else{
myDialog.destroy();
}
}
function myStepAndRepeat(myObjects, myNumberOfRows, myNumberOfColumns, myXOffset, myYOffset){
//looping here for the rows
for (myYCounter = 0; myYCounter <= myNumberOfRows-1; myYCounter++){
//looping here for the cols
for (myXCounter = 0; myXCounter <= myNumberOfColumns-1; myXCounter++){
if (myXCounter!=0 || myYCounter !=0) {
for (myObjectCounter=0; myObjectCounter < myObjects.length; myObjectCounter++){
myObject = myObjects[myObjectCounter];
myObject = myObject.duplicate();
myObject.move(undefined, [myXOffset*myXCounter, myYOffset*myYCounter]);
}
}
}
}
}
Copy link to clipboard
Copied
Hello, i know this is an old post, but maybe somebody can help me.
How can i use Kasicki's script and add a script that center the full arrange on the page?
thanks
Copy link to clipboard
Copied
1) copy, paste, and save it as a plain text file (e.g. in Notepad) with jsx or js extension.
Copy/move it to your Scripts Panel folder.
Select an object and run the script like so:
2) I don't know what exactly you want to achieve: how to align -- by page borders, margins, etc.
Here's an example. First, I make a group from all page items on the 1st page and then center it both horizontally and vertically relative to the page border. And finally I ungroup it.
main();
function main() {
var doc = app.activeDocument;
var page = doc.pages[0]; // the 1-st page
var items = doc.allPageItems;
var group = doc.groups.add(items);
doc.align(group, AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
doc.align(group, AlignOptions.VERTICAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
group.ungroup();
}
Here are details for the align method.
Hope it helps!
— Kas
Copy link to clipboard
Copied
Thanks a lot!
Copy link to clipboard
Copied
Sadly..doesnt work. it says:
var group = doc.groups.add(items);
error 30477. "parámetro no valido" i'm using Indesing CC.
i try paste and copy severals scripts. but everytime i obtain the same result. Just center the first item (even if i group all the items in my script) or center just the first page.
Copy link to clipboard
Copied
I gave you an example of how to do this by script using a simple test file in the screenshot above. I can't tell you what goes wrong in your doc without having it.
Copy link to clipboard
Copied
Thanks! i try to do it better, and follow your instructions. I'm sure i make something wrong. thanks for your time.
Copy link to clipboard
Copied
Look at this, it might help...
https://www.marspremedia.com/software/indesign/step-and-repeat
Copy link to clipboard
Copied
Hello Mr Campbell! i test you script several weeks ago, and follow your youtube indesign script tutorials!..
but i'm just a worker, not an owner of the business, so...you know.. 😞 . thanks for your time and help.
Pd. Your indesing Swatch script is my favorite!
Copy link to clipboard
Copied
Great to hear. Thanks for watching the channel.
Copy link to clipboard
Copied
Hi, I hope someone can help me. How can I make this script work on a multi-page document? (for example, with a two faces businesscard). thanks
Copy link to clipboard
Copied
you have to create a loop on every page and have it select all page items
Copy link to clipboard
Copied
Thanks. I was trying to figure out write a step and repeat script and this really helpful for me to reference to complete mine. Cant believe this was posted back in 2008 and i was able to find it.

