Highlighted

How to apply pathstyle to CompoundPath

Community Beginner ,
Jun 09, 2020

Copy link to clipboard

Copied

Dear Friends, 

     We try to duplicate the Compound Path and Apply style to Duplicated Compound Path, 

We use these code but the code run, its Abort the illustrator. The Problem occur in applying st

yle to Compound Path.

 

ArtMatcher artMatch(1);
artMatch.SetSpec(0, kAnyArt, 0, 0);
artMatch.GetMatchingArt();
ASInt32 lLength, maxLength, ret;
char *buffer = NULL;
for (int nInd = 0; nInd < artMatch.GetNumMatches(); ++nInd)
{
       AIArtHandle art1 = artMatch.GetMatchedArt(nInd);
       result = sAIArt->GetArtType(art1, &type);
       if (type == kTextFrameArt)
       {
            TextRangeRef textrange;
            result = sAITextFrame->GetATETextRange(art1, &textrange);
            sTextRange->GetSize(textrange, &lLength);
            maxLength = lLength * 2;
            buffer = (char *)malloc(maxLength * sizeof(char));
            memset(buffer, 0, maxLength);
             ATETextDOM::Int32 ret = 0;
            sTextRange->GetContents_AsChar(textrange, buffer, maxLength, &ret);
            std::string str(buffer);
            ai::UnicodeString strkey = ai::UnicodeString(str, kAIUTF8CharacterEncoding);
            ai::UnicodeString strString;
            AIReal moveX = 0, moveY;

           for (int nInd = 0; nInd < strkey.length(); nInd++)
               {
               for (int nIndex = 0; nIndex < artMatcher.GetNumMatches(); ++nIndex)
                 {
                   short type;
                  AIArtHandle art = artMatcher.GetMatchedArt(nIndex);
                  result = sAIArt->GetArtType(art, &type);
                  if (type == kCompoundPathArt)
                    {
                     ai::UnicodeString LayerName = mapArtHandle[art];
                     char cStr[1024] = STRING_INIT_NULL;
                     strcat(cStr, LayerName.as_Platform().c_str());
                     AILayerHandle layer = NULL, layer1 = NULL;
                    moveX = moveX + 10;

                    sAIUnicodeString->InitializeUTF32Char(strString, 1, strkey.at(nInd));

                    sAILayer->GetCurrentLayer(&layer);
                    sAILayer->SetLayerEditable(layer, true);
                    sAILayer->SetLayerVisible(layer, true);
                    AIArtHandle preArt = NULL, tomboGroupArt = NULL;
                   sAIArt->GetFirstArtOfLayer(layer, &preArt);
                   AIArtHandle artTemp2;
                   AIRealRect ArtBounds = { 0, 0, 0, 0 };
                  sAIArt->GetArtBounds(art, &ArtBounds);
                  AIReal ArtWidth = ArtBounds.right - ArtBounds.left;

                  AIArtHandle artLeft, artRight;

                  AIArtHandle artTemp;
                  sAIArt->GetLayerOfArt(art, &layer);
                  sAIArt->GetFirstArtOfLayer(layer, &artTemp);
                  AIRealRect oldBounds = { 0, 0, 0, 0 }, newbounds = { 0,0,0,0 };
                  AIArtHandle art = mapLayerArt[strString];
                 if (art == NULL)
                   {
                      continue;
                   }
                if (LayerName == strString)
                  {
                     result = sAIArt->GetArtBounds(art, &oldBounds);
                    AIPathStyle pathStyle;
                    result = sAIArt->DuplicateArt(art, kPlaceInsideOnTop, artTemp, &artRight);
                    result = sAIPathStyle->SetPathStyle(artRight, &pathStyle);
                    result = sAIArt->GetArtBounds(artRight, &newbounds);
                    sAIDocument->RedrawDocument();
                    moveY = newbounds.top - oldBounds.top;
                   TransformArt(artRight, moveX, moveY, 0, 1, 1);
                   sAIDocument->RedrawDocument();
                   result = sAIArt->DisposeArt(art);
               }
           }
       }
    }
 }

 

 

Hmm, it looks like the error would be occuring because you're passing a NULL values (pathStyle is NULL, unless I've misunderstood your code) to SetPathStyle. I actually just responded to a similar question about applying a path style to art, perhaps try the code I put there?

Apply path style to compound path 

 

Additionally, SetPathStyle can't take some art types (kForeignArt, kLegacyTextArt, kUnknownArt), so you should eheck that your artRight is a compound path before applying the style:

short artType;
result = sAIArt->GetArtType(artRight, &artType);

if (result != kNoErr || artType != kCompoundPathArt)
	return result;

 

TOPICS
SDK

Views

121

Likes

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

How to apply pathstyle to CompoundPath

Community Beginner ,
Jun 09, 2020

Copy link to clipboard

Copied

Dear Friends, 

     We try to duplicate the Compound Path and Apply style to Duplicated Compound Path, 

We use these code but the code run, its Abort the illustrator. The Problem occur in applying st

yle to Compound Path.

 

ArtMatcher artMatch(1);
artMatch.SetSpec(0, kAnyArt, 0, 0);
artMatch.GetMatchingArt();
ASInt32 lLength, maxLength, ret;
char *buffer = NULL;
for (int nInd = 0; nInd < artMatch.GetNumMatches(); ++nInd)
{
       AIArtHandle art1 = artMatch.GetMatchedArt(nInd);
       result = sAIArt->GetArtType(art1, &type);
       if (type == kTextFrameArt)
       {
            TextRangeRef textrange;
            result = sAITextFrame->GetATETextRange(art1, &textrange);
            sTextRange->GetSize(textrange, &lLength);
            maxLength = lLength * 2;
            buffer = (char *)malloc(maxLength * sizeof(char));
            memset(buffer, 0, maxLength);
             ATETextDOM::Int32 ret = 0;
            sTextRange->GetContents_AsChar(textrange, buffer, maxLength, &ret);
            std::string str(buffer);
            ai::UnicodeString strkey = ai::UnicodeString(str, kAIUTF8CharacterEncoding);
            ai::UnicodeString strString;
            AIReal moveX = 0, moveY;

           for (int nInd = 0; nInd < strkey.length(); nInd++)
               {
               for (int nIndex = 0; nIndex < artMatcher.GetNumMatches(); ++nIndex)
                 {
                   short type;
                  AIArtHandle art = artMatcher.GetMatchedArt(nIndex);
                  result = sAIArt->GetArtType(art, &type);
                  if (type == kCompoundPathArt)
                    {
                     ai::UnicodeString LayerName = mapArtHandle[art];
                     char cStr[1024] = STRING_INIT_NULL;
                     strcat(cStr, LayerName.as_Platform().c_str());
                     AILayerHandle layer = NULL, layer1 = NULL;
                    moveX = moveX + 10;

                    sAIUnicodeString->InitializeUTF32Char(strString, 1, strkey.at(nInd));

                    sAILayer->GetCurrentLayer(&layer);
                    sAILayer->SetLayerEditable(layer, true);
                    sAILayer->SetLayerVisible(layer, true);
                    AIArtHandle preArt = NULL, tomboGroupArt = NULL;
                   sAIArt->GetFirstArtOfLayer(layer, &preArt);
                   AIArtHandle artTemp2;
                   AIRealRect ArtBounds = { 0, 0, 0, 0 };
                  sAIArt->GetArtBounds(art, &ArtBounds);
                  AIReal ArtWidth = ArtBounds.right - ArtBounds.left;

                  AIArtHandle artLeft, artRight;

                  AIArtHandle artTemp;
                  sAIArt->GetLayerOfArt(art, &layer);
                  sAIArt->GetFirstArtOfLayer(layer, &artTemp);
                  AIRealRect oldBounds = { 0, 0, 0, 0 }, newbounds = { 0,0,0,0 };
                  AIArtHandle art = mapLayerArt[strString];
                 if (art == NULL)
                   {
                      continue;
                   }
                if (LayerName == strString)
                  {
                     result = sAIArt->GetArtBounds(art, &oldBounds);
                    AIPathStyle pathStyle;
                    result = sAIArt->DuplicateArt(art, kPlaceInsideOnTop, artTemp, &artRight);
                    result = sAIPathStyle->SetPathStyle(artRight, &pathStyle);
                    result = sAIArt->GetArtBounds(artRight, &newbounds);
                    sAIDocument->RedrawDocument();
                    moveY = newbounds.top - oldBounds.top;
                   TransformArt(artRight, moveX, moveY, 0, 1, 1);
                   sAIDocument->RedrawDocument();
                   result = sAIArt->DisposeArt(art);
               }
           }
       }
    }
 }

 

 

Hmm, it looks like the error would be occuring because you're passing a NULL values (pathStyle is NULL, unless I've misunderstood your code) to SetPathStyle. I actually just responded to a similar question about applying a path style to art, perhaps try the code I put there?

Apply path style to compound path 

 

Additionally, SetPathStyle can't take some art types (kForeignArt, kLegacyTextArt, kUnknownArt), so you should eheck that your artRight is a compound path before applying the style:

short artType;
result = sAIArt->GetArtType(artRight, &artType);

if (result != kNoErr || artType != kCompoundPathArt)
	return result;

 

TOPICS
SDK

Views

122

Likes

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
Jun 09, 2020 0
New Here ,
Jun 10, 2020

Copy link to clipboard

Copied

Hmm, it looks like the error would be occuring because you're passing a NULL values (pathStyle is NULL, unless I've misunderstood your code) to SetPathStyle. I actually just responded to a similar question about applying a path style to art, perhaps try the code I put there?

Apply path style to compound path 

 

Additionally, SetPathStyle can't take some art types (kForeignArt, kLegacyTextArt, kUnknownArt), so you should eheck that your artRight is a compound path before applying the style:

short artType;
result = sAIArt->GetArtType(artRight, &artType);

if (result != kNoErr || artType != kCompoundPathArt)
	return result;

 

Likes

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
Reply
Loading...
Jun 10, 2020 0
Resources