Categories
code Tips and Guides

Part- 3 Illustrator Scripting Looping the shape within layer

Below is couple of functions that takes parameter of active layer and process individual element to change color.

function iterateOverGroup(groupCoreItem,colorIs){
for (var ai = 0; ai < groupCoreItem.pathItems.length; ai++) {
colorShape(groupCoreItem.pathItems[ai],colorIs);
}
for (var gi = 0; gi <groupCoreItem.groupItems.length; gi++) {
iterateOverGroup(groupCoreItem.groupItems[gi],colorIs);
}
for (var ci = 0; ci <groupCoreItem.compoundPathItems.length; ci++) {
var compoundPath = groupCoreItem.compoundPathItems[ci];
var pathItems = compoundPath.pathItems;
for (j=0; j< pathItems.length; j++) {
var pathItem = pathItems[j];
colorShape(pathItem,colorIs);
}
}
}

function colorShape(shapeItemCore, replaceThisColor){
if(shapeItemCore.filled==true){
shapeItemCore.fillColor = replaceThisColor;
//if(shapeItemCore.fillColor!=white){ FILL it }
}
if(shapeItemCore.stroked==true){
shapeItemCore.strokeColor=replaceThisColor;
//if(shapeItemCore.strokeColor!=white){ FILL it }
}
}

Note: there are three types of elements within layer that are being checked in first function i.e item can be PathItem, GroupItem or CompondPathItem.

FOR ANY EXTENSION / SCRIPT / PLUGIN WORK DON’T HESITATE TO LEAVE ME A MESSAGE OR CONTACT ME at mr.bunt@gmail.com