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

Javascript to add Gradient to a polygon

New Here ,
May 20, 2019 May 20, 2019

Hello,

I am looking to add some more control to a script where I use a CSV file to create unique designs per page. For eample a csv file would have the shirt size, T Shirt color, and if any font is put on the shirt. The script works great but now I was thinking to add a gradient option. Ideally I would like to add the gradient to have 2 colors but not sure how to do thi. Below you can see I change the fill and color.

            myPage=app.activeDocument.pages.item(i).select();    

            myPageItems=app.documents.item(0).pages.item(i);

            myPolygon=myPageItems.polygons.item("frmLEFT-090-VAMP");

            myPolygon.visible=true;          

            myPolygon.fillColor="TEAM_YELLOW";

            myPolygon.strokeColor="BLACK_NB";

            myPolygon=myPageItems.polygons.item("frmRIGHT-090-VAMP");

            myPolygon.visible=true;    

            myPolygon.fillColor="TEAM_ROYAL";

            myPolygon.strokeColor="BLACK_NB";

I can add the gradient to the Polygon in InDesign but then I would need a way to turn on off if we have design wanting no gradient... Any help would be appreciated.

Thanks.

Bill

TOPICS
Scripting
981
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 ,
May 20, 2019 May 20, 2019

The myPolygon.fillColor could be the name of a gradient swatch, which you could also create via scripting—gradient, and gradient.gradientStops.stopColor

And then the positioning would be properties of the polygon object myPolygon.gradientFillAngle, myPolygon.gradientFillLength, myPolygon.gradientFillStart,

https://www.indesignjs.de/extendscriptAPI/indesign10/#Polygon.html

Also ask at the inDesign Scripting forum

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 Employee ,
May 24, 2019 May 24, 2019

Discussion moved to InDesign Scripting

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 ,
May 24, 2019 May 24, 2019
LATEST

If you have added the desired gradient to the swatch then applying it to the polygon object is just the same as using another swatch. Something like the following would work, where GS is the name of the gradient swatch

myPolygon.fillColor = app.documents[0].swatches.itemByName("GS")

If you want to even add the gradient to Swatches using scripting you can go through the following discussion

Add a Gradient as a Swatch?

-Manan

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