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

Scripting polygons

Participant ,
Dec 27, 2019 Dec 27, 2019

Happy Holidays to all!

 

I am in need to create a script that creates a ui wherein you choose the number of sides to your polygon and the script floods the page with polygons next to each other given a margin of sorts.

Now, I do have some programming experience, however I'm a bit struggling, being new at this ExtendScript/Adobe/Javascript combo, in finding examples for polygons. I'm at ease with the UI part, having done one before for a previous project. It's really scripting polygons that I need help with here, if I may ask kindly of you all.

 

Could someone kindly show me the basic code for creating, say, a hexagon, given some basic properties such as color, stroke thickness, size, position, etc. 

 

The Jongware http://jongware.mit.edu/idcs6js/pc_Polygon.html is quite extensive however it appears better suited either for experts, or for Lt. Data perhaps. Any help is appreciated and I will continue now my search. 

 

Thank you kindly again!

 

Antoine 

 

 

TOPICS
Scripting
2.0K
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

correct answers 1 Correct answer

Community Expert , Dec 27, 2019 Dec 27, 2019

Jongware's work is the best resource for understanding the InDesign Document Object Model and APIs available to you as a scripter. All of the properties you can set are available to you on the page you link. First order of business though is how do you create a Polygon? How do you access the document where these polygons will live? 

 

Most objects have a collection class. In this case, Polygon has Polygons. Polygons are accessible through the Document, which is accessible through the Application (

...
Translate
Community Expert ,
Dec 27, 2019 Dec 27, 2019

Jongware's work is the best resource for understanding the InDesign Document Object Model and APIs available to you as a scripter. All of the properties you can set are available to you on the page you link. First order of business though is how do you create a Polygon? How do you access the document where these polygons will live? 

 

Most objects have a collection class. In this case, Polygon has Polygons. Polygons are accessible through the Document, which is accessible through the Application (or app), where most things start. 

 

Doing some research would show that most documents are accessed via the following: 

 

var myDoc = app.activeDocument; 

 

Or 

 

var myDoc = app.documents[0]; 

 

Since Polygons is a child of Document, you can use the following method available to the Polygons class (info of which is available in Jongware's directory): 

 

var myPol = myDoc.polygons.add();

 

You'll note in the add description (https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Polygons.html#d1e231505__d1e231554) that you can pass optional arguments when you add a polygon. The first is the layer that the polygon will be on, and the second is the sides of the polygon. So you would enhance your add function with:

 

var myPol = myDoc.polygons.add("Layer 1", 6); 

 

to create a hexagon on Layer 1. 

 

You can set lots of properties during .add(), such as: 

 

... .add("Layer 1", 6, {geometricBounds: [100,200,300,400]});

 

Or you can set the properties after you create the object: 

 

myPol.geometricBounds = [100,200,300,400];

 

(Geometric bounds indicate where an item is on a spread). 

 

The rest is up to your imagination and LOTS of trial and error, using Jongware's resource as a guide. Hope that helps.  

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
Participant ,
Dec 28, 2019 Dec 28, 2019

Hi Brian,

 

Hey, thanks for your answer. I got it sorted it out except for one thing. It turned out somehow InDesign 2020 (PC) wasn't refreshing when I ran the code. Rebooted and it worked.

 

Hey, you wouldn't know off the top of your head how to tell a polygon to apply a mixed ink swatch, would you?

 

Yes... lots of experimenting! 🙂

 

Cheers from Vancouver, and happy new year to you and yours,

 

Antoine

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 ,
Dec 28, 2019 Dec 28, 2019

Take a look at Jongware's resource. Search for Swatch. You can apply swatches to fills and strokes (among other things I believe). You'll find a property called "fillColor". It accepts a String or a Swatch. It has read/write abilities, so you can set the color dynamically via scripting. Hence: 

 

myPoly.fillColor = "Swatch name"; 

 

will give you a Polygon filled with the designated Swatch color. 

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
Participant ,
Dec 28, 2019 Dec 28, 2019

Hey Brian, thanks again for contributing! Yes, I'm there and it works for spots or cmyk but mixed inks its not working I'll share once I figure it out. Have a great weekend.

 

 

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 ,
Dec 28, 2019 Dec 28, 2019
LATEST

If you set up a mixed ink Swatch it should work to set the poly to that Swatch name. Or you can create Polys in the same position on two different layers (your spot and cmyk layers). More info on setting up a single mixed ink Swatch, if you are unaware: 

 

https://www.creativebloq.com/how-to/create-mixed-inks-with-indesign

 

 

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