Answered
Help for Script modification, it creates selection copies , looking for limit width
Hello,
the following script create copies of selection, (user prompt for copies and margin, selected 20x20 cm rectangle)
Currently, there is no horizontal limit

Can someone adapt it, setting horizontal limit, eg to 110 cm
Setting e.g 110 cm horizontal limit result should be

(After reaching the width limit, the "copies" created at new row
The script
// A Script for Adobe Illustrator to Duplicate Items Hor/Ver with Margin
// Originally by https://github.com/hilukasz
// This https://gist.github.com/ExtremeGTX/2ca86e77c78153a3b43b6eb5088a426f
// Modified by Mohamed ElShahawi (ExtremeGTX)
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var doc = app.activeDocument;
var thislayer = app.activeDocument.activelayer;
var selected = doc.selection;
var selectedHeight = selected[0].height;
var selectedWidth = selected[0].width;
var OriginX = selected[0].position[0];
var OriginY = selected[0].position[1];
var repeatAmount,
myInput,
splitInput,
margin,
selectedPosition,
Direction;
// Run
userPrompt();
Direction == 'v' ? DuplicateVertical() : DuplicateHorizontal();
function DuplicateHorizontal(){
selectedPosition = selected.position;
var newItem = selected[0].duplicate( thislayer, ElementPlacement.INSIDE );
for(i=0; i< repeatAmount -1 ; i++){
var newPosX = selectedWidth + newItem.position[0] + margin;
newItem.position = [newPosX,newItem.position[1]];
doc.selection = null;
newItem.selected = true;
var selectedPosition = selected.position;
newItem.duplicate( thislayer, ElementPlacement.INSIDE );
// app.redraw();
}
newItem.remove();
app.redraw();
}
function DuplicateVertical(){
selectedPosition = selected.position;
var newItem = selected[0].duplicate( thislayer, ElementPlacement.INSIDE );
for(i=0; i< repeatAmount -1 ; i++){
var newPosY = selectedHeight - newItem.position[1] + margin;
newItem.position = [newItem.position[0],-newPosY];
doc.selection = null;
newItem.selected = true;
var selectedPosition = selected.position;
newItem.duplicate( thislayer, ElementPlacement.INSIDE );
}
newItem.remove();
app.redraw();
}
function userPrompt(){
myInput = prompt('Ποσότητα, Διάστημα','10 0.2');
splitInput = myInput.split(" ");
repeatAmount = Number(splitInput[0]);
margin = Number(splitInput[1]*28.346456693);
