Question
Create swatch group from selection
Hi,
I managed to create a swatch group from javascript, now I am trying to get the selection colors to add to that swatch. I know I can add a swatch, take that swatch and put it to the swatch group using :
var swGrp = docRef.swatchGroups.add();
swGrp.name = "ColorsToList";
var newSwatch = docRef.swatches.add();
newSwatch.name = color.toString();
swGrp.addSwatch(newSwatch);
what I am having issue with is to make a for loop to loop through the colors of my selected group/object.
Here's what I tried so far:
#target illustrator
app.preferences.setBooleanPreference("ShowExternalJSXWarning", false);
var docRef = app.activeDocument;
function main(){
SwatchGroup();
function SwatchGroup(){
var swGrp = docRef.swatchGroups.add();
swGrp.name = "ColorsToList";
for(i = 0; i <= docRef.pathItems[i].length; i++){
var itemColor = docRef.pathItems[i].fillColor;
var newSwatch = docRef.swatches.add();
newSwatch.color = itemColor;
newSwatch.name = "test" + i;
swGrp.addSwatch(newSwatch);
return;
}
};
}
main();
it simply create the group and a white color with "test1" as the name - my selected item has 5colors.
Any idea how I could make it?
thanks.
