Copy link to clipboard
Copied
Good people of the Adobe forums,
I am working on a script that performs a series of things on all of the artwork in a document. At one point, it needs to compare the fill color of every item to a sample color. The problem is, the artwork is a collection of compound path items and path items. When I look for pathItems
pageItem
pageItems
pageItems
They all seem to break.
Copy link to clipboard
Copied
Hi
The fillColor property is not valid for compoundPathItems. This is because the color of a compound path is determined by its interior paths. So, if you change the color of the paths inside a compound path, you actually change the color of the compound path. Consider the compound path like a structure, a container that takes the color of their components (its paths).
This is why you get a return "undefined" when you try to read the "fillColor" of a compoundPathItem.
Hope to be helped
Best Regards
Gustavo.
Copy link to clipboard
Copied
For example (did not test yet):
var doc = app.activeDocument;
var compounds = doc.compoundPathItems; //this will return an array of the CompoundPaths;
for (var g=0 ; g<compounds.length ; g++){
var interiorPaths = compounds
.pathItems; //it will give you an array of the paths inside the compoudPaths. So you can read the fillColor of the paths //now play with the interiorPaths array. You could declare here a new -for- statement to cycle between these paths.
};
This will allow you to work with the paths inside the compound paths.
This is only one way to work. There's other ways also to work.
Best Regards
Gustavo.
Message was edited by: Gustavo Del Vechio
Copy link to clipboard
Copied
P.S: I've just correct the above code.
Gustavo.
Copy link to clipboard
Copied
Gustavo,
Thank you for your quick response! Unfortunately, that doesn't address my big problem. I will try to explain a bit better..
I know about having to access the path items inside of a compound path. That's why I tried "pageItem
So, it brings me back to the problem of finding out the fill color of a page item whether it is a regular path item or a compound path item.
Copy link to clipboard
Copied
Hi ProfessorCal
Thank you. I think I understand you. So you want to work by looping between all pageItems. An idea, perhaps could help: what about if you insert an "if" statement inside your loop, so it first analyzes the kind of pageItem, and you have different codes for the different kinds of items (like paths or compoundPaths). Example:
if (pageItem
//your code here.
};
else
if (pageItem
//your code here
};
Would it help your code?
P.S: you could even evaluate if the current pathItem is inside or not any group. Example:
if (pageItem
//so its an isolated path not inside any group or compoundPath.
};
Abraços!
Gustavo.
Message was edited by: Gustavo Del Vechio
Copy link to clipboard
Copied
Actually, that's exactly what we're doing.
Later parts of the code have to look at the fill color of each item, check its type (gradient -vs- spot) and compare it to other colors. In order to avoid a series of 'if' statements every time, we have made a function that takes each page item and returns a path item from it so we can work with that within the rest of the code (it's easier to write all of these comparisons if your'e always expecting to get a path item, and the first path item of every compound path has properties that apply to the entire compound path..) SO... that function looks like this:
function getLeadItem(glPage) { //glPage is the Page Item
if (glPage.typename == 'CompoundPathItem'){
return glPage.pathItems[0] //returns the first path item of the compound path (...but does not work)
} else {
return glPage (if it is a normal page item, it just returns itself)
}
glPage = null
}
for all of the page items that are regular path items, the code later on that looks like this:
if(item.fillColor == '[GradientColor]'){
selectedColor = doc.activeLayer.pageItems
But any of the compound path ones break, which is why we made the function earlier, so that 'item' would ALWAYS be a path item, and not compound.
Copy link to clipboard
Copied
your function DOES work, are you dealing with Outlined text? text usually gets grouped once it's outlined
var idoc = app.activeDocument;
var glPage = idoc.pageItems[0];
var alert(glPage.typename);
var leadItem = getLeadItem (glPage);
alert(leadItem.fillColor.typename);
function getLeadItem(glPage) { //glPage is the Page Item
if (glPage.typename == 'CompoundPathItem'){
return glPage.pathItems[0] ; //returns the first path item of the compound path (...but does not work)
} else {
return glPage;// (if it is a normal page item, it just returns itself)
}
glPage = null
}
Copy link to clipboard
Copied
Carlos, Gustavo,
Thank you both for the help. Looks like I was misinterpreting my error messages. The problem seems to have more to do with the way data is being fed to the function and how our list of page items is changing over time as other parts of the code move things around.
Thanks again.
Copy link to clipboard
Copied
Then you may need to start at the back and work forward which reduces the chances of changing the index of the page item.
Copy link to clipboard
Copied
Morning Carlos,
I saw your comment related to getting the fillColor from a CompoundPath by checking the first item in the PathItems array ( compoundPath.pathItems
.fillColor ). I am familiar with this solution and use it frequently.
But you mention something about how when text is converted to outlines it's grouped. I am having difficulty querying the fillColor on these types of CompoundPaths?
Any thoughts?
Thanks!
Scott
Copy link to clipboard
Copied
Outlined text is a group where all characters are individual compound path items.
Assuming document has only one text item which was freshly converted to outlines:
alert(app.activeDocument.groupItems[0].compoundPathItems[0].pathItems[0].fillColor);
Copy link to clipboard
Copied
I think he means Outlined text turned into a compoundPath
Copy link to clipboard
Copied
do you want to query color or to apply color to compound paths?
Copy link to clipboard
Copied
Morning,
Here is a screenshot of a selected compoundPath that I assume was created by "expanding" the text, and the pathItems.length is strangely equal to zero? So I am unable to query the fillColor property?
I guess my question is, how does one query the fillColor of a selected compoundPath when the pathItems.length is zero?
I am stumped, and this issue is causing issue if a few of my scripts, so any suggestions what is going on would be great. I am staring to think this path was authored outside Illustrator... and Illustrator is unable to populate the pathItems array inside the object.
Thanks!
Scott
Copy link to clipboard
Copied
CompoundPathItem
A compound path. These objects are composed of multiple intersecting paths, resulting in transparent
interior spaces where the component paths overlap. The pathItems property provides access to the paths
that make up the compound path.
Paths contained within a compound path or group in a document are returned as individual paths when a
script asks for the paths contained in the document. However, paths contained in a compound path or
group are not returned when a script asks for the paths in a layer that contains the compound path or
group.
All paths within a compound path share property values. Therefore, if you set the value of a property of
any one of the paths in the compound path, the properties of all other component paths are updated with
the new value.
Copy link to clipboard
Copied
You must have the situation where your compound path contains a group. This is a bug for all us scripters as per what you are dealing with. There were some threads here on this issue:
Grouped paths inside of compound paths screws up script
Re: Dealing with Compound Paths made of Groups
So, one way to deal with this is to use a Flatten Transparency action which de-bugs all the items in such a way - if you have lots of stuff and don't care about what Flatten will do to the structure.
Another way is to use the plugin mentioned inside "Re: Dealing with Compound Paths made of Groups "
Or use the scripting work-arounds I talk about, etc.
Copy link to clipboard
Copied
HUGE thanks for everyone providing help! Glad to hear this is a known issue... and I am not crazy.
Silly-V the issue can be resolved by running the Flatten Transparency, and will need testing to see if this will not cause any issue down stream. It appears Flatten Transparency isn't available on a path as an operation... I am guessing I need to use the app.executeMenuCommand()?
Incase your curious...I wrote a HSV tool similar to Photoshop for my team, and this issue is the last bug I need to resolve.
Scott
Copy link to clipboard
Copied
It's got to be a recorded action you play back, the good thing is that you can control a lot with it such as converting spots to process and stuff.
Copy link to clipboard
Copied
I think it's more of an oversight rather than a bug, probably Adobe didn't think users would turn multiple compundPaths into one compound path. As mentioned above and in the links provided by silly v, the solution to query/set colors should be quite simple.
- move a copy of your compound path to top-most position
- query/set color of document's 1st pathItem
- move copy on above or below original compound path
- remove original compound path
Copy link to clipboard
Copied
I can't wait until my travels take me to your part of the world, because philosophizing on this and other issues over course of hours and hot tea would be an amazing dream come true..
But since we're here, I would say the oversight is synonymous with 'bug' because to me this is actual evidence of issues regarding the nomenclature and function behind the scenes.
Copy link to clipboard
Copied
really? you want to spend hours philosophizing about semantics? there are other more important topics to talk about, like the World Cup.
Copy link to clipboard
Copied
Sorry, I do not watch sports ball, but who knows you may awaken the old Russian spirit there.
No, not MAX - but I always come to the CreativePRO week which has a dev summit on Fridays, next one is 2019 in Seattle!
Copy link to clipboard
Copied
it's ok, we can talk about bugs vs oversights we're developers anyways we have our fare share of them in our programs.
CreativePRO is getting closer to home
Copy link to clipboard
Copied
are you coming to MAX?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now