6 Replies Latest reply on Feb 6, 2017 6:42 AM by Peter Kahrel

# A script to make pies (and more)

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-2012

if (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[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 ([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;
}
}
}
```
• ###### 1. Re: A script to make pies (and more)

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

15% interesting

25% fascinating

60% just paragraph filling

100% worth reding this....

----------

Green4ever

• ###### 2. Re: A script to make pies (and more)

Combine your scripts in creative ways!

• ###### 3. Re: A script to make pies (and more)

Nice one!

Peter

• ###### 4. Re: A script to make pies (and more)

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

• ###### 5. Re: A script to make pies (and more)

thx for sharing Peter! great stuff

• ###### 6. Re: A script to make pies (and more)

That was Jongware, not me!

P.