• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• A script to make pies (and more)

# A script to make pies (and more)

Community Expert ,
Mar 26, 2012 Mar 26, 2012

Copied

As a sort of dare from our friendly neighbours in the Illustrator forum, I wrote this script that might be useful for InDesign users as well.

It creates a pie chart by asking for the series of values, and then slicing up a circle that you must have selected. Fun thing is, it doesn't "just" work with circles; you can select about anything, enter your values at the prompt (comma separated), and get the correct result! (Which depends on the shape; of course it's only mathematically correct when using a circle.)

`//DESCRIPTION:Make me a pie// A Jongware script, 25-mar-2012if (app.selection.length == 1){  val = prompt ("Values: ", "1,2,3");  if (val != null)  {    values = val.split(",");    total = 0;    for (i=0; i<values.length; i++)    {      values = Number(values);      total += values;    }    for (i=0; i<values.length; i++)    {      values = values*2*Math.PI/total;    }    circleCenter = [ (app.selection[0].geometricBounds[3]+app.selection[0].geometricBounds[1])/2,      (app.selection[0].geometricBounds[2]+app.selection[0].geometricBounds[0])/2 ];    circleRadius = Math.max ( (app.selection[0].geometricBounds[3]-app.selection[0].geometricBounds[1])/2,      (app.selection[0].geometricBounds[2]-app.selection[0].geometricBounds[0])/2);    startangle = 0;    for (i=0; i<values.length; i++)    {      endangle = startangle + values;      // warning: math! (though this is SIMPLE compared to what I've bin doing today)      segstart = [ circleCenter[0]+ 2*circleRadius*Math.sin(startangle), circleCenter[1]- 2*circleRadius*Math.cos(startangle) ];      segend = [ circleCenter[0]+ 2*circleRadius*Math.sin(endangle), circleCenter[1]- 2*circleRadius*Math.cos(endangle) ];      cutoff = app.activeDocument.graphicLines.add();      // create surrounding border      path = [ circleCenter, segstart ];      for (j=startangle; j<endangle; j += (values/16))        path = path.concat ([[ circleCenter[0]+2*circleRadius*Math.sin(j),circleCenter[1]-2*circleRadius*Math.cos(j)]] );      path = path.concat ([segend]);      cutoff.paths[0].entirePath = path;      cutoff.paths[0].pathType = PathType.CLOSED_PATH;      cutoff.intersectPath(app.selection[0].duplicate()).fillTint = (i+1)*100/values.length;      startangle = endangle;    }  }}`
TOPICS
Scripting

Views

12.1K

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
15 Replies 15
Enthusiast ,
Mar 26, 2012 Mar 26, 2012

Copied

Amazing..... Using "Math" you showed me that there is a long........ way to go.

 15% interesting25% fascinating60% just paragraph filling

100% worth reding this....

----------

Green4ever

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 Expert ,
Mar 26, 2012 Mar 26, 2012

Copied

Combine your scripts in creative ways!

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 Expert ,
Mar 26, 2012 Mar 26, 2012

Copied

Nice one!

Peter

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
May 07, 2024 May 07, 2024

Copied

Now this post is VERY old. I copied the script but when I run it it produces nothing. Tried updating the for loops so that the values subscripts are correct (values [i] instead of just values). Then I get the "Pathfinder results defines empty region" error. Any suggestions?

``````//DESCRIPTION:Make me a pie
// A Jongware script, 25-mar-2012
if (app.selection.length == 1)
{
val = prompt ("Values: ", "70|30");
if (val != null)
{
values = val.split("|");
total = 0;
for (i=0; i<values.length; i++)
{
values[i] = Number(values[i]);
total += values[i];
}
for (i=0; i<values.length; i++)
{
values[i] = values[i]*2*Math.PI/total;
}
circleCenter = [ (app.selection[0].geometricBounds[3]+app.selection[0].geometricBounds[1])/2,
(app.selection[0].geometricBounds[2]+app.selection[0].geometricBounds[0])/2 ];
(app.selection[0].geometricBounds[2]-app.selection[0].geometricBounds[0])/2);
startangle = 0;
for (i=0; i<values.length; i++)
{
endangle = startangle + values[i];
// warning: math! (though this is SIMPLE compared to what I've bin doing today)
// create surrounding border
path = [ circleCenter, segstart ];
for (j=startangle; j<endangle; j += (values[i]/16)) path = path.concat ([[ circleCenter[0]+2*circleRadius*Math.sin(j),circleCenter[1]-2*circleRadius*Math.cos(j)]] );
path = path.concat ([segend]);
cutoff.paths[0].pathType = PathType.CLOSED_PATH;
cutoff.intersectPath(app.selection[0].duplicate()).fillTint = (i+1)*100/values.length;
startangle = endangle;
}
}
}``````

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 Expert ,
May 07, 2024 May 07, 2024

Copied

Hi @Tim Sheasby ,

If not, I'd test this. See my reply from 2019:

Regards,
Uwe Laubender

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
May 07, 2024 May 07, 2024

Copied

LATEST

Was working on first (only) page of the document. Added:

'cutoff.paths[0].entirePath = path;'
before line 35 and now it works!

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Mar 27, 2012 Mar 27, 2012

Copied

Very cool!

He he. Don't get those Illy guys too jealous! (I feel like pulling out my hair every time I try to script Illy. So limited...)

Harbs

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Enthusiast ,
Feb 06, 2017 Feb 06, 2017

Copied

thx for sharing Peter! great stuff

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 Expert ,
Feb 06, 2017 Feb 06, 2017

Copied

That was Jongware, not me!

P.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Mar 30, 2019 Mar 30, 2019

Copied

Hi.  Awesome script.
I know it's and old post but I hope I can get an answers.
Script work perfectly until I change fill and tint amount of created slices by script.
Then it give this error if I try to run it again.

I open new document, and create pie chart at there when I get this error.
Is there any way you could help me with fixing this error?
Thank you very much.

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 Beginner ,
Apr 06, 2019 Apr 06, 2019

Copied

Genius!

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jun 28, 2019 Jun 28, 2019

Copied

wow, this is great, works in CC 2019 and is even more precise than pie charts in AI. Now if I could feed it a text file with values for pies on different line and it would create those automatically it would be heaven;-) Like you put the width of the circle, and chose the text file and boom, it does all the pies. Oh well, still faster than doing it in AI.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jun 28, 2019 Jun 28, 2019

Copied

hmm, I get an error as soon as I try to run the script on a circle that is NOT on the first page of the document.

Anybody else got this error when run on other page then first page of document?

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 Expert ,
Jun 29, 2019 Jun 29, 2019

Copied

Hi Jeff,

the real problem is in line 35:

That graphic line is always added to the first spread of the document.

So later cutoff.intersectPath() cannot work.

Why? You cannot intersect two paths that are positioned on different spreads.

You could try to work around this by writing:

Or perhaps better:

Regards,
Uwe

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jul 02, 2019 Jul 02, 2019

Copied

Thanks Uwe! took the first solution and it works great!