Great Script for Simplifying Paths in Illustrator (Kelso)

[Editor's note: Cartographers looking for Douglas-Peucker type line simplication in Illustrator now have a solution to Illustrator's default simplify command when trying to generalize features like river oxbows. Jim started on the problem of fixing an Illustrator bug (see image above) where redundant points were created in the path outline command, and now has a more generalized solution.]

Jim Heck shared an amazing tool for Adobe Illustrator with me recently to deal with the irritating bug in versions CS3 and CS4 where redundant points (stacked on top of each other, illustrated above where the dupplicate points are pulled away from the basic shape) are created on outline or offset of a path’s stroke. The script (in Javascript) and Action set he created quickly remove these redundant points while still keeping the path shape. He does this with a bit of behind the scenes trigonometry wizardry. Please note this bug still exists in CS4 contray to rumors, though is lesser virulent form than CS3 (confirmed by me via email with Adobe engineers).

I’ve worked with Jim to refine it the last couple weeks. I think it’s ready for prime time now.

Screenshots:

Settings shown to remove redundant points for outlined path screenshot above. I used a tolerance of 12 points for the river ox bow screenshot below.

How it works:

  • Selected path points only or all document paths
  • Set distance tolerance in page units (optional)
  • Works in locked objects
  • Works in compound paths
  • Reporting, Selection, and Removal modes

Cartographic applications:

I illustrate below the result of using Jim’s generalization script on a typial river path and you can see in area 1a and 2b how the ox bow removal is light years above Illustrator’s default path simplify command which grossly distorts the shape in the pursuit of point removal. Jim’s script preserves the shape and removes the tiny, tight wiggles. It needs a little bit more programming work to fix areas 1b and 2a + 2c where the shape is loosing some fidelity for not keeping the trailing point in the series of removed points. And maybe needing to keep an intermediary point between 2a and 2c for shape since this is a longer removal?

With a little more tweaking, this tool will become popular for cartographers since we often want to simplify lines while keeping the overall geometry shape when reducing clustered points. The opposite may be achievable, too, when adding points selectively to long curves, but NOT to segments of the line that are already dense with points. But that’s for a 2.0 release ;)

Download the script and actions from Jim Heck’s site . . .

Tags: , , , , , , , , , , , , , , , , , , ,

8 Responses to “Great Script for Simplifying Paths in Illustrator (Kelso)”

  1. Patrick says:

    This sounds great, but I can’t seem to get the link to work.

  2. nathaniel says:

    @ Patrick: All the links work for me, what one are you having problems with?

  3. Jeff Clark says:

    Nice work Nathaniel – the simplify / generalization issue has constantly been a thorn in my side wrt contour (isolines in general) – your script is very timely. Thanks for putting it out to the masses.

  4. Jim Heck says:

    I’m glad that people are eager to try out my script. I’m open to suggestions on how to make it more generally usable. As Nathaniel says, when I started, I had no idea that it might prove more generally useful than to help with the dreaded duplicate point problems in CS3 (and I guess CS4) that plague such commands as Object->Path->Outline Stroke, Object->Path->Offset Path, Expand, etc.

    Right now the script keeps only the leading point (lowest index on the path) and copies the direction handle from the trailing point to that leading point. This works fairly well so long as the points are reasonably close together, but as the example above shows, it leads to distortions as the distance between the first and last point grows relative to the overall path geometry. After reading Nathaniel’s writeup, and looking at the referred link to Douglas-Peucker, I’d say that the script could pretty easily be adapted to use such an algorithm as an alternative. I’ll see if I can’t find some time to try to code that in (warning, however, my April has some deadlines, so it might be a bit).

    I have already made some more modifications to the script and can release a 1.4 version very soon. I just didn’t want to change it just as Nathaniel was reviewing it, and people were trying it out (in case heaven forbid I add a bad bug :-) Here are the highlights

    I added options to control position of remaining point on removal. The new choices are to keep the leading or trailing point, or to average the position of the points. I also fixed bugs in docGetSelectedPaths(). CompoundPathItem objects don’t seem to to have properly formed pathItems arrays when they contain what appear to be groups of paths, so when certain compound path objects were selected, no paths were found.

    One last note, older versions of the script are available at the wiki by clicking on the file link and selecting the link for the date/time of an earlier version, which will download that version.

    Enjoy,

    -Jim

  5. jonny says:

    Wow, Jim. Seriously life-saving stuff.

    We’re doing a big collaborative art project with alot CNC plywood work. The vector files that artists submit have to be prepped for the CNC machine and Offset Path is a necessity. The resulting files have been giving the CAM software fits because of the bug, and your java-script literally saved me tens to hundreds of hours of cleanup at a time when I cant afford it.

    Thank you so much!

    -jonny

  6. Justin says:

    Does anyone have a working link for this script? Maybe a mirror or something?

    Thanks,
    Justin

  7. Nathaniel says:

    I’ll dig up a copy on Sunday or Monday.

    _n

  8. Justin says:

    Thanks in advance! …much appreciated!