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

[JavaScript] Iterate through pathItems

Community Beginner ,
Feb 08, 2022 Feb 08, 2022

Copy link to clipboard

Copied

I have converted some text to a groupItem using createOutline(), and now I am trying to apply a gradient to the converted text. My attempt to iterate through the pathItems in the groupItem resulted in an invalid object error on the loop line:

nametext.selected = true;
nametext.createOutline();

for(i = 0; i < nametext.pathItems.length; i++){

    nametext.pathItems[i].filled = true;
    nametext.pathItems[i].fillColor = colorOfGradient;
}

 

So I tried this instead, but the gradient was not applied:

nametext.selected = true;
var nameObj = nametext.createOutline();

for(i = 0; i < nameObj.pathItems.length; i++){

    nameObj.pathItems[i].filled = true;
    nameObj.pathItems[i].fillColor = colorOfGradient;
}

What am I doing wrong?

 

Thanks! 

TOPICS
Scripting

Views

108
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
community guidelines
Adobe
Community Expert ,
Feb 08, 2022 Feb 08, 2022

Copy link to clipboard

Copied

LATEST

You're very close! The problem is that outlined text create a GroupItem of CompoundPathItems. So:

nametext.selected = true;
var nameObj = nametext.createOutline();

for (i = 0; i < nameObj.compoundPathItems.length; i++) {
    nameObj.compoundPathItems[i].pathItems[0].filled = true;
    nameObj.compoundPathItems[i].pathItems[0].fillColor = colorOfGradient;
}

A quirk is that you seem to have to apply appearance to one of the pathItems of the CompoundPathItem.

- Mark

Votes

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
community guidelines