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

Accessing the elements of a page item

Community Beginner ,
Jan 06, 2014 Jan 06, 2014

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.fillColor, it works fine.  When I look for compoundPathItem.fillColor, it comes back undefined.  So, I've moved to looking at page items, but I seem to be unable to get to the internals on the page items.  If I have a compound path item, how would I address its properties from its parent page item?  I tried:

pageItem.compoundPathItem.pathItems[0].fillColor,

pageItems.fillColor,   & 

pageItems.compoundPathItem.fillColor. 

They all seem to break.

TOPICS
Scripting
4.4K
Translate
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
Advocate ,
Jan 06, 2014 Jan 06, 2014

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.

Translate
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
Advocate ,
Jan 06, 2014 Jan 06, 2014

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

Translate
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
Advocate ,
Jan 06, 2014 Jan 06, 2014

P.S: I've just correct the above code.

Gustavo.

Translate
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 Beginner ,
Jan 06, 2014 Jan 06, 2014

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.compoundPathItem.pathItems[0].fillColor" (first option listed in my first post)..  The tough bit is that it appear I need to work my way through all of the art in terms of page items, instead of looping through the path items separately and the compound path items separately.  This helps keep things in proper order as the script goes on, after comparing, to move the items to new groups that have to be in a specific order.

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.

Translate
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
Advocate ,
Jan 06, 2014 Jan 06, 2014

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.typename == "PathItem"){

//your code here.

};

else

if (pageItem.typename == "CompoundPathItem"){

//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.typename == "PathItem" && pageItem.parent.typename == "Layer"){

//so its an isolated path not inside any group or compoundPath.

};

Abraços!

Gustavo.

Message was edited by: Gustavo Del Vechio

Translate
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 Beginner ,
Jan 06, 2014 Jan 06, 2014

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.fillColor.gradient

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.

Translate
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 ,
Jan 06, 2014 Jan 06, 2014

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

}

Translate
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 Beginner ,
Jan 06, 2014 Jan 06, 2014

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.

Translate
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 ,
Jan 07, 2014 Jan 07, 2014

Then you may need to start at the back and work forward which reduces the chances of changing the index of the page item.

Translate
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
Participant ,
Jul 26, 2018 Jul 26, 2018

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

Translate
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
Valorous Hero ,
Jul 26, 2018 Jul 26, 2018

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

Translate
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 ,
Jul 26, 2018 Jul 26, 2018

I think he means Outlined text turned into a compoundPath

Translate
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 ,
Jul 26, 2018 Jul 26, 2018

do you want to query color or to apply color to compound paths?

Translate
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
Participant ,
Jul 27, 2018 Jul 27, 2018

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

cmpPathLen0.JPG

Translate
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
Advocate ,
Jul 27, 2018 Jul 27, 2018

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.

Translate
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
Valorous Hero ,
Jul 27, 2018 Jul 27, 2018

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.

Translate
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
Participant ,
Jul 27, 2018 Jul 27, 2018

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

shiftHueSatVal.JPG

Translate
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
Valorous Hero ,
Jul 27, 2018 Jul 27, 2018

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.

Translate
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 ,
Jul 28, 2018 Jul 28, 2018

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

Translate
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
Valorous Hero ,
Jul 28, 2018 Jul 28, 2018

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.

  1. Obviously, the software allows groups to be encased into compound paths without any detrimental effect to regular UI-effected operations.
  2. The naming conventions of "compound" and "path" implies that it is only paths which are allowed inside this kind of item. How the scripting api refers to these via code (no compoundPathItem.groupItems) could be a result of whomever making the api following the naming conventions to produce their scripting conventions.
  3. Therefore, in my opinion they created a bug through their oversight.. so I guess it's one in the same; if we were to follow the literal description of 'bug' as software acting against expected results, I am seeing it in the way of their internal conflict/mistake on what the expected results should be (ie: if they were aware,  they may have added groupItems to the compoundPathItem object - or the compoundPathItems in case of multiple compound paths)
Translate
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 ,
Jul 28, 2018 Jul 28, 2018

really? you want to spend hours philosophizing about semantics? there are other more important topics to talk about, like the World Cup.

Translate
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
Valorous Hero ,
Jul 28, 2018 Jul 28, 2018

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!

Translate
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 ,
Jul 28, 2018 Jul 28, 2018
LATEST

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

Translate
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 ,
Jul 28, 2018 Jul 28, 2018

are you coming to MAX?

Translate
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