Highlighted

Setting fill color for a compound path via script

Explorer ,
Mar 06, 2020

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?

TOPICS
Scripting

Views

313

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Setting fill color for a compound path via script

Explorer ,
Mar 06, 2020

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?

TOPICS
Scripting

Views

314

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 06, 2020 0
Most Valuable Participant ,
Mar 06, 2020

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;
    }

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 06, 2020 2
Adobe Community Professional ,
Mar 11, 2020

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.");
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2020 0