shspage.com/aijs/en/  
 

Scripts for Adobe Illustrator (JavaScript)

( Japanese page )
All the scripts are included in this archive.
download: aics_scripts_en.zip
-- 2018-07-20 : Modified the scripts which process selected objects so that locked/hidden objects included in the selected groups are excluded from processing. -- 2017-05-13 : "Arc Correction". Added new feature that corrects text paths in the selection as with normal paths. -- 2017-03-12 : "Join Reasonaboly". Add an option "conf.ignore_if_further_than". -- 2016-11-26 : "Metaball", "Metaball (Arc)", "Round Any Corner". Add try...finally statement around parts changing win.enabled property. -- 2015-07-07 : Add editText control to "Metaball" and "Metaball (Arc)". Add editText control and remove slider control from "Round Any Corner". -- 2013-12-31 : Moved some scripts in the doc/legacy_and_extras folder. Added the old version of the scripts that don't use scriptUI in this folder.

This archive includes following sample scripts (not well commented yet confused)
tested with Adobe Illustrator CC on Win/Mac.

Author : Hiroyuki Sato - [Contact] @shspage_en (Twitter) or Email Form.

Other Contents Related to Scripting:

License :
Copyright(c) 2013 Hiroyuki Sato, All Rights Reserved.
These scripts are distributed under the MIT License.
Free to use and distribute.
See the LICENSE.txt included in the archive for details.

# General Note For Usage

• How to Use the Scripts
Choose File>Scripts>Browse, and open the script to run.
Or place the script in the directory "Adobe Illustrator CS?\Presets\Scripts", then restart Illustrator.
Download the PDF documents for more information. http://www.google.com/search?q=site:www.adobe.com+illustrator+javascript+reference
"Illustrator CS? JavaScript Scripting Reference"
"Illustrator CS? Scripting Guide"
 
• Selection of part of a path
Some scripts work only for selected anchor points or sides (= lines, bezier curve segments). A side (= a line, a bezier curve segment) means one of each line segment drawn to connect a couple of anchor points. In other words, selected parts means targets for Cut or Copy command. Regular (or Group) Select Tool selects whole of a path. - [fig.]
 
• A Compound Path Issue
Some scripts don't work for some part of compound paths. When this occurs, please select part of the compound path or release the compound path and select them, then run script again. I still have not figured out how to get properties from grouped paths inside a compound path.
 
• Illustrator 10 Issue
All the scripts was written to be compatible with AI 10 through CC (or later?). (Excludes some scripts using scriptUI that requires CS3 or later.) Only problem is AI 10 lacks a prompt dialog that users can specify the optional values. For now, one of the solution for this is to edit the scripts manually to change the default value of these varibles. They are most often placed in the beginning of the scripts with the appropriate comments.
 

Archimedean Spiral


draws an (approximated) Archimedean spiral.
[]

Arc Correction


corrects free-hand drawn arc-like paths in the selection. To use, just select the paths and run this script.
For the (not need-to-know) detail of the method, please read the comments inside of the script with above figure.


2017-05-13: Added new feature that corrects text paths in the selection as with normal paths.
[]

Circumcircle


draws circumcircles for each selcted path
Method:
The major reason why I wrote this script is to draw a "circumcircle" for a star.
So the method to find the center and the radius for the circumcircle is rather incertitude.
  1. find out a perpendicular bisector for the line connecting 1st and 2nd anchor
  2. do the same for 1st and 3rd anchor (if the path is a triangle, 2nd and 3rd anchor)
  3. find out intersection point of 1 and 2. for the center of the circumcircle to draw
  4. find out the length of the line connecting the center and 1st anchor, then do the same for the center and 2nd anchor. define longer one as the radius of the circumcircle to draw.
The rightmost one in the figure above is a case of failure.
[]

Common Tangents


draws common tangents to the selected curved lines, if they are detected.
[]

Cut At Selected Anchors

cuts selected paths at each selected anchor
[]

Divide (length)


divides each selected segment into specified number. based on the length.
Length of each segment in each divided segments is equal.
[]

Dup At Selected Anchors


duplicates the foreground object in the selection at the locations of the rest of each selected anchor points.
[]

Join Reasonably

joins the open paths in the selection together with reasonable order
There are several settings can be edited inside the script. The followings are a list of them and their default values.

conf.close = true; // make a closed path. true/false (make closed paths when conf.ignore_if_further_than > 0)
conf.marge_if_nearer_than = 0.5; // merge the ends to connect within this distance. set 0 to be ignored (unit:mm)
conf.ignore_if_further_than = 0; // ignore to connect if distance between the ends exceeds this value. set 0 to be ignored (unit:mm)
conf.hanLen = 0.33; // ratio of handle length to connected line. set 0 to be ignored
conf.dontAddRevHan = 120; // do not generate a handle if the angle of the connecting part is more than this value. set 0 to be ignored (unit:degree, 0-180)
[]

Merge Overlapped Anchors

merges nearly overlapped anchor points.
also reports how many anchor points had been reduced.

USAGE: Select the path(es) and run this script.
[]

Metaball (Arc), Metaball



This script may help to create Metaball-like shapes
"Metaball (Arc)" uses arcs to connect. "Metaball" uses suitable bezier curves.

USAGE : Draw some circles and select them, then run this script.
Adjust the values in the dialog. Then click OK.
(it doesn't check in the script whether each path is really a circle)

# Combining the shapes using Pathfinder may results several overlapping
anchor points on the path. if it occurs, it may help to solve it to
use my another script "Merge Overlapped Anchors.js".
This is a simple sample script that merges overlapping anchors on the path.
[]

Ovalize

( modification of Circle.js )
for turning every selected path into an oval which fits the width and the height of the path.
If the width and the height are equal, it turns into a circle.
You can specify the number of the anchor points before the script modifies the paths.
You can use this script in the case if you want to draw a circle or an oval which has the number of the anchor points other than four.
Draw a circle with the ellipse tool, select it, run this script, input the number and you are done.
Please notice the case 3 of the above image. This is a feature for now.
[]

Path Length

finds out length of the each selected path, and total length of the selected paths.
Then write out them on the artboard as text object
This script uses JavaScript's "length" property of PathItem. if it is available (= CS3 or later). You can force calculate the length by "use_native_property" setting set to false. ( see inside the script )
NOTE:
The return values of "PathItem.length" property and the function in this script are slightly different especially in complex paths. It seems that the difference is 0.05 millimeter at most.
[]

Remove Anchors


removes selected anchor points
[]

Reverse

reverses the order of the anchor points of each selected paths
2009-05-23: comment-out showing alert part
[]

Round Any Corner


rounds selected corners of PathItems.
Especially for the corners at the intersection point of curves, this script may work better than "Round Corners" filter (but slower).

Test Env: Illustrator CC (Win/Mac)
(This script uses scriptUI. So it works only with CS3 or later. For CS2 or former, use the old version in doc/legacy folder)


## How To Use
1. Select the anchor(s) or whole path(s) to round.
2. Run this script. Adjust the values in the dialog. Then click OK.

## Rounding Method
Basically, the rounding method is compatible with the "Round Corners" filter. It is to add two anchors instead of the original anchor, at the points of specified line length from each selected corner. So if there're too many anchors on original path, this script can not round nicely.

## Radius
Actually, the specified "radius" is not for a radius of arcs which drawn. It is for the line length from each selected corner and is for the base to compute the length of handles. The reason calling it "radius" is for compatibility with the "Round Corners" filter.

This script does not round the corners which already rounded.
(for example, select a circle and run this script does nothing)

### notice
In the rounding process, the script merges anchors which nearly overlapped (when the distance between anchors is less than 0.05 points).

This script does not work for some part of compound paths. When this occurs, please select part of the compound path or release the compound path and select them, then run script again.
I still have not figured out how to get properties from grouped paths inside a compound path.
[]

Sine Curve


draws (approximate) sine curve at the origin of the artboard
The values of the coordinates are based on Don Lancaster's Guru's Lair Cubic Spline Library.
[]

Legacy And Extra

These scripts are placed in doc/legacy_and_extra folder in the archive for the following reasons.

Adjust Dashes (offset)


fig.1 : This script adjusts dashed lines in the selection in order to the center of the first dash comes at each anchor points.
For its purpose, when adjacent segments of an anchor of the target path have a difference in length -- a rectangle like above, for example --, this script splits the path at this anchor, applies a suitable dash setting for each splitted path, then put them into a group. This is a lockstep trick caused by an Illustrator path can have only one simple rule for dashes and gaps. This process also CLEARS FILL COLORS, if it needs, and if the pash has BUTT end cap, change it to PROJECTION end cap.
fig.2 : The left figure is splitted with pathfinder ( outline ), in order to make anchors at all intersection points.
[]

Adjust Dashes


adjusts the lengths of dashes and gaps of dashed lines
in order to the length of the path is divisible by
total length of dashes and gaps
[]

Arrow-A, Arrow-V


draws arrow for each selected end (anchor) of the selected paths.
"A" and "V" mean the shape of the head of the arrow.
The visible peaks of arrows exactly locate at each visible end of the selected paths.
The end of paths are trimmed in order to avoid sticking out from the head of the arrow.
The path with projection end cap is modified to but end cap.
[]

Ovalize (Circle)

The old version of Ovalize.
This script draws a circle that has specified number of anchor points at the center of the active artboard.

Dance


adds a new layer and draws dancing people on it

### notice
The dancers are made with various width of lines.
So please be careful about the setting of Scale Tool
when you want to scale them.
[]

Extend Handles


extends all handles of selected anchor points with specified rate.
100 : original size
120 : extend 20%
80 : shorten 20%
0 : remove handles
-100 : reverse handles
[]

Metaball (Arc), Metaball : old UI

The old version of Metaball (Arc) and Metaball that don't use scriptUI.

Round Any Corner : old UI

The old version of Round Any Corner that doesn't use scriptUI.

Tangents From A Point


draws tangent lines from a selected anchor point to selected curved segments.

This script tries to find a path with only 1 anchor selected,
from foreground to background. And specifies the selected point
of the path as starting point of tangents.
"the selected curved segments" means rest of the selected paths.

You can use an isolated point as the starting point.
In this case, starting isolated point is removed after drawing tangents.

Drawn tangents have handles at ends.
So you can move the starting side of anchor point with keeping tangency.
[]

Tree-like


draws a tree-like shape at the center of the artboard
### notice
The trees are made with various width of lines.
So please be careful about the setting of Scale Tool
when you want to scale them.
[]

(c)2005-2013, Hiroyuki Sato. All Rights Reserved.