7 Replies Latest reply on Oct 9, 2015 7:26 AM by ivanmmmmm

    How to change brush color?

    ivanmmmmm

      I have selected art (calligraphic brush) on a layer, and I need to change its color. How should I do that using SDK? What suite/function should I use?

        • 1. Re: How to change brush color?
          ivanmmmmm Level 1

          A little clarification: not "calligraphic" but "art" brush.

          • 2. Re: How to change brush color?
            LeoTaro Level 4

            Isn't it just the same as changing the stroke colour of any path object (i.e. using AIPathStyleSuite)?

            • 3. Re: How to change brush color?
              ivanmmmmm Level 1

              LeoTaro thanks for your answer. I've tried the following code with paintbrush, pencil and path tools. The art selects, but no changes to color or stroke width. Where is the mistake? I feel like I still need to update the stroke object with new settings.

                      error = sAILayer->GetCurrentLayer( &layerHandle );
                      CHECK_ERROR
                      error = sAILayer->SelectArtOnLayer( layerHandle );
                      CHECK_ERROR
                      
                      AIArtHandle path;
                      AIPathStyle style;
                      AIPathStyleMap pathStyleMap;
                      AIDictionaryRef advStrokeParams = NULL;
              
                      error = sAIArt->GetFirstArtOfLayer( layerHandle, &path );
                      CHECK_ERROR
              
                      error = sAIPathStyle->GetCurrentPathStyle( &style, &pathStyleMap, &advStrokeParams );
                      CHECK_ERROR
              
                      style.strokePaint = true;
                      style.stroke.color.kind = kThreeColor;
                      style.stroke.color.c.rgb.red = 0;
                      style.stroke.color.c.rgb.green = 1.0;
                      style.stroke.color.c.rgb.blue = 0;
                      style.stroke.width = 10;
              
                      error = sAIPathStyle->SetPathStyle( path, &style );
                      CHECK_ERROR
              
              • 4. Re: How to change brush color?
                LeoTaro Level 4

                You are applying the style to the path variable which is the result of a call to GetFirstArtOfLayer. This will be the group art object that contains all the art in the layer. You need to apply the style to the path art objects themselves.

                • 5. Re: How to change brush color?
                  ivanmmmmm Level 1

                  Too bad, I'm completely new to AI SDK and C, several hours of searching gave no result. I've tried AdjustObjectAIColors, AIArtStyleSuite, AIGroupSuite, but no luck. How do I iterate through the art objects of a group object that you've mentioned? Could you please point me to a suite/method.

                  • 6. Re: How to change brush color?
                    LeoTaro Level 4

                    You could use code like this to modify all the path art within a group art object:

                     

                    void StylePathArt(AIArtHandle item)

                    {

                      short type;

                      sAIArt->GetArtType(item,&type);

                      switch (type)

                      {

                      case kGroupArt:

                      {

                      AIArtHandle child = NULL;

                      sAIArt->GetArtFirstChild(item,&child);

                      while (NULL != child)

                      {

                      StylePathArt(child);

                      sAIArt->GetArtSibling(child,&child);

                      }

                      }

                      break;

                      case kPathArt:

                      {

                      AIPathStyle style;

                      sAIPathStyle->GetPathStyle( item, &style );

                            style.strokePaint = true;

                            style.stroke.color.kind = kThreeColor;

                            style.stroke.color.c.rgb.red = 0;

                            style.stroke.color.c.rgb.green = 1.0;

                            style.stroke.color.c.rgb.blue = 0;

                            style.stroke.width = 10;

                      sAIPathStyle->SetPathStyle( item, &style );

                      }

                      break;

                      }

                    }

                     

                    Alternatively you could use the AIMatchingArtSuite to extract the path art objects from a group art object.

                    • 7. Re: How to change brush color?
                      ivanmmmmm Level 1

                      LeoTaro thank you! It seems like the right solution, I think I'll use it in not far future. Shame to say, I've just solved my problem by changing SetPathStyle to SetCurrentPathStyle in my code above.