Created
August 8, 2016 14:28
-
-
Save randomize/84aaf01c413e8cf9e785661b344a0537 to your computer and use it in GitHub Desktop.
Little Adobe Illustrator script to fill automatically selected paths with selected swatches, used to help my art team saving some time
This file contains hidden or 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
mySelection = app.activeDocument.selection; | |
myDoc = app.activeDocument; | |
if (mySelection instanceof Array) | |
{ | |
selSwatches = myDoc.swatches.getSelected(); | |
if (selSwatches.length < mySelection.length) | |
alert ("Pleade make sure you have enough swathces you have " + selSwatches.length + " and you need " + mySelection.length) | |
else | |
{ | |
if(selSwatches.length != 0) | |
for (i=0; i<mySelection.length; i++) | |
{ | |
selItem = mySelection[i]; | |
if(mySelection[i].typename == "PathItem") | |
processPathItem(selItem, i) | |
else if ( mySelection[i].typename == "CompoundPathItem") | |
processCompoundPath(selItem, i) | |
else if ( mySelection[i].typename == "GroupItem") | |
processGroup(selItem, i) | |
} | |
} | |
} | |
function processPathItem(selItem, swatchIndex) | |
{ | |
selItem.filled = true; | |
selItem.fillColor = selSwatches[swatchIndex].color; | |
} | |
function processCompoundPath(ob, swatchIndex) | |
{ | |
for(var c = 0; c < ob.pathItems.length; c++) | |
{ | |
if(ob.pathItems[c].typename == 'PathItem'){ | |
processPathItem(ob.pathItems[c], swatchIndex); | |
} | |
} | |
} | |
function processGroup(ob, swatchIndex) | |
{ | |
for(var p = 0; p < ob.pageItems.length; p++){ | |
if(ob.pageItems[p].typename == 'PathItem'){ | |
processPathItem(ob.pageItems[p], swatchIndex); | |
} else if(ob.pageItems[p].typename == 'CompoundPathItem'){ | |
processCompoundPath(ob.pageItems[p], swatchIndex); | |
} else if(ob.pageItems[p].typename == 'GroupItem'){ | |
processGroup(ob.pageItems[p], swatchIndex); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment