Skip to main content
Inspiring
August 23, 2023
Answered

C++-SDK: How to get the colors of a Pattern?

  • August 23, 2023
  • 1 reply
  • 409 views

I'm currently writing a Plugin which should get the colors out of different Arts.

The basic function I'm using for this is from AIPathStyleSuite

 

sAIPathStyle->AdjustObjectAIColors(_art, this->ShowColorAdjustColorFunc, &data, visitFlags, &modified);


with the following call:

void searchForColors(AIArtHandle _art)
{
   VisitAIColorFlags visitFlags = (kVisitColorsSolidOnly | kVisitGlobalObjectsOnceOnly | kVisitColorsSelectedOnly);
   Colors data = Colors();
   ASBoolean modified = false;
   sAIPathStyle->AdjustObjectAIColors(_art, this->ShowColorAdjustColorFunc, &data, visitFlags, &modified);
}



The callback-function is the following:

/**Callback-function for ShowColor**/
void ShowColorAdjustColorFunc(AIColor* color, void* userData, AIErr* reportResult, ASBoolean* modifiedColor)
{
//Do something
}


This works perfectly with normal kPathArt, also for Art with Gradients and Pattern. If this art is filled wih a pattern, I get all the colors from the Pattern back when I call AdjustObjectAIColors() for this art

 

However, when I try to do the same for kTextFrameArt, where the Fill-Color of the Text is a Pattern, I get only the information that the color is a pattern.
From the color-structure I can get the Art-Handle of the pattern, by calling:

AIColor _Color;
....

AIPatternHandle handle = _Color.c.p.pattern;
AIArtHandle arthandle;
sAIPattern->GetPatternArt(handle, &arthandle);

 

This arthandle is a pointer to a group of arts, which I examine to get includes kPathArts. When I find such an art, I call my searchForColors()-Function with that art.
However, in this case, the callback-function ShowColorAdjustColorFunc() is never called from sAIPathStyle->AdjustObjectAIColors().

 

So my question is:

 

Why do I not get back colors in this case and how can I get (and manipulate) the colors of a pattern?


Thanks for any help

This topic has been closed for replies.
Correct answer JohnGoodman

Seems like an Illustrator bug: when kVisitColorsSelectedOnly is on, the callback function is never called for text objects.

But since you decide which art objects are sent to searchForColors( ), I would leave this flag off and simply pass only selected objects to the function.

1 reply

JohnGoodmanCorrect answer
Participant
August 27, 2023

Seems like an Illustrator bug: when kVisitColorsSelectedOnly is on, the callback function is never called for text objects.

But since you decide which art objects are sent to searchForColors( ), I would leave this flag off and simply pass only selected objects to the function.

Inspiring
September 13, 2023

That made it, thanks

 

To be honest, even with the documentation, I do not fully understand the meaning of all of these Flags
I anyway work currently only with Elements(Arts) selected by the User. The plan for "The User does not select any element" would be to internally select all elements (Arts)