Copy link to clipboard
Copied
Hi,
I require javascript for a simple job like
I have an object size (w X h).
I need a rectangle outside of this object bigger than it. For creating this rectangle, i will input value separately to add with objects width & height.
This rectangle will be clip mask of object.
Both object and its rectangle selected and it it copy and move with its width value to add many multiups horizontly. need dialog box for input multiups.
all multi ups get selected and this time it copy and move with its height value to add many multi ups vertically. need dialog box for input multi ups.
Thanks for your kind help.
Copy link to clipboard
Copied
group your art. select it. then run this.
function vertical_layout(){
var gap = prompt("enter Gap between selected group and its new Clipping path in mm",5,"Set Clipping Size");
var qty = prompt("how many would you like?",5,"Set Qty");
gap = gap*2.83466796875; // convert mm to points for the script (for inches change to "gap*72")
var doc = app.activeDocument;
var sel = doc.selection;
if(sel.length<1){
alert("Please select a group before running this script");
return;
}
if(sel.length>1){
alert("Please group Items before selecting and running this script");
return;
}
var Ibounds = sel[0].visibleBounds;
var clip = doc.pathItems.rectangle(Ibounds[1]+gap,Ibounds[0]-gap,Ibounds[2]-Ibounds[0]+(gap*2),Ibounds[1]-Ibounds[3]+(gap*2));
clip.move(sel[0], ElementPlacement.PLACEATBEGINNING);
sel[0].clipped = true;
sel[0].pathItems[0].clipping = true;
sel[0].pathItems[0].selected = true;
var newSel = doc.selection;
var shift = Ibounds[1]-Ibounds[3]+(gap*2);
for(var i = 0; i<qty; i++){
var copy = newSel[0].duplicate(doc.activeLayer, ElementPlacement.PLACEATBEGINNING);
copy.translate(0,shift*(i+1),true,true,true,true);
}
}
vertical_layout();
Copy link to clipboard
Copied
oops I missed the horizontal.
this will, with default settings, create a 5 x 5 grid, but will leave the original at bottom left.
function vertical_layout(){
var gap = prompt("enter Gap between selected group and its new Clipping path in mm",5,"Set Clipping Size");
var qty = prompt("how many would you like UP?",5,"Set Qty");
var qty2 = prompt("how many would you like ACROSS?",5,"Set Qty");
gap = gap*2.83466796875; // convert mm to points for the script (for inches change to "gap*72")
var doc = app.activeDocument;
var sel = doc.selection;
if(sel.length<1){
alert("Please select a group before running this script");
return;
}
if(sel.length>1){
alert("Please group Items before selecting and running this script");
return;
}
var Ibounds = sel[0].visibleBounds;
var clip = doc.pathItems.rectangle(Ibounds[1]+gap,Ibounds[0]-gap,Ibounds[2]-Ibounds[0]+(gap*2),Ibounds[1]-Ibounds[3]+(gap*2));
clip.move(sel[0], ElementPlacement.PLACEATBEGINNING);
sel[0].clipped = true;
sel[0].pathItems[0].clipping = true;
sel[0].pathItems[0].selected = true;
var newSel = doc.selection;
var shift = Ibounds[1]-Ibounds[3]+(gap*2);
var shift2 = Ibounds[2]-Ibounds[0]+(gap*2);
for(var i = 0; i<qty; i++){
var copy = newSel[0].duplicate(doc.activeLayer, ElementPlacement.PLACEATBEGINNING);
copy.translate(0,shift*(i+1),true,true,true,true);
for(var j = 0; j<qty2-1; j++){
var copy2 = copy.duplicate(doc.activeLayer, ElementPlacement.PLACEATBEGINNING);
copy2.translate(shift2*(j+1),0,true,true,true,true);
}
}
}
vertical_layout();
Copy link to clipboard
Copied
the post stephen mentions looks like a more complex version.
it also includes some extra idiot proofing.
for a production robust script you should look at confirming that (gap, qty, qty2) variables are numbers and don't contain letters etc..
Copy link to clipboard
Copied
Thanks for your help. when I run the script after selecting my object, it giving me following error? what should be done.
Copy link to clipboard
Copied
sorry it was built to deal with groups.
press ctrl+G (guessing cmd+G on mac) to put your shape in a group, then run the script.
I can fix this in the script but am running late and will not be around for a few days...
Copy link to clipboard
Copied
Step and Repeat scripts are also covered here:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now