Created
June 18, 2017 00:57
-
-
Save ExtremeGTX/2ca86e77c78153a3b43b6eb5088a426f to your computer and use it in GitHub Desktop.
A Script for Adobe Illustrator to Duplicate Items Hor/Ver with Margin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A Script for Adobe Illustrator to Duplicate Items Hor/Ver with Margin | |
// Originally by https://github.com/hilukasz | |
// Modified by Mohamed ElShahawi (ExtremeGTX) | |
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; | |
var doc = app.activeDocument; | |
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( doc, ElementPlacement.PLACEATEND ); | |
for(i=0; i< repeatAmount ; 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( doc, ElementPlacement.PLACEATEND ); | |
} | |
} | |
function DuplicateVertical(){ | |
selectedPosition = selected.position; | |
var newItem = selected[0].duplicate( doc, ElementPlacement.PLACEATEND ); | |
for(i=0; i< repeatAmount ; 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( doc, ElementPlacement.PLACEATEND ); | |
} | |
newItem.remove(); | |
} | |
function userPrompt(){ | |
myInput = prompt('Margin, Repeat Amount, Horizontal/Vertical','10,5,v'); | |
splitInput = myInput.split(","); | |
margin = Number(splitInput[0]); | |
repeatAmount = Number(splitInput[1]); | |
Direction = splitInput[2].toLowerCase(); | |
} |
Hello,
it looks that script creates 2 more copies of the selection
12 instead of 10
And at the end of execution 2 shapes are selected
How i can fix it?
Regards
@SimoSP
Unfortunately, I don't have illustrator installed now, but make sure you are selecting only 1 object at time, may be there was another another object selected by mistake.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
it looks that script creates 2 more copies of the selection
12 instead of 10
And at the end of execution 2 shapes are selected
How i can fix it?
Regards