Copy link to clipboard
Copied
I'm trying to set the .fillColor property of a compound path to be a color I specify, but it doesn't seem to be working. The function works for PathItems but not CompoundPathItems.
Here's the code:
// Specify Color
var testColor = new RGBColor();
testColor.red = 45;
testColor.green = 255;
testColor.blue = 115;
// Create a variable that references the selected object
var object = app.activeDocument.selection[0]
// Set the fill color. Works on paths, but not compound paths
object.fillColor = testColor;
Any ideas?
Copy link to clipboard
Copied
Did you know that a compound pathItems can contains more than one pathItem or groups or other compound paths?
Try this snippet on a simple (selected) compound path in a RGB Ai file:
// select one compound pathItem in a RGB Ai file before running this snippet
// regards pixxxelschubser
// Specify Color
var testColor = new RGBColor();
testColor.red = 45;
testColor.green = 255;
testColor.blue = 115;
var aDoc = app.activeDocument;
var sel = aDoc.selection;
if (sel[0].typename == 'CompoundPathItem') {
alert ("selection contains " + sel[0].pathItems.length + " paths");
alert (sel[0].pathItems[0].fillColor);
sel[0].pathItems[0].fillColor = testColor;
}
Copy link to clipboard
Copied
fillColor is not a property of compoundPathItem.
You need to first check that the compound path has at least one pathItem, then set the fillColor of that pathItem and the color will be applied to the entire compoundPath. try this:
// Specify Color
var testColor = new RGBColor();
testColor.red = 45;
testColor.green = 255;
testColor.blue = 115;
// Create a variable that references the selected object
var object = app.activeDocument.selection[0]
// Set the fill color. Works on paths, but not compound paths
if(object.pathItems.length)
{
object.pathItems[0].fillColor = testColor;
}
else
{
alert("The selection has no child path items.");
}