• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Setting fill color for a compound path via script

Explorer ,
Mar 06, 2020 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

2.2K

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
community guidelines
Adobe
Community Expert ,
Mar 06, 2020 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;
    }

Votes

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
community guidelines
Community Expert ,
Mar 11, 2020 Mar 11, 2020

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines