TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Interested in some really terrific mobile apps? Visit www.turboapps.com for details.

VBScript to reduce number of nodes in 2D polylines
Read 5154 times
* June 30, 2011, 03:12:17 PM
The attached VB Script can drastically reduce the number of nodes (vertices) in the selected polyline(s) to a desired precision.

It uses two methods: The first removes nodes which are within a specified distance of the previous node in the list. The second is based on the Douglas Peucker Algorithm.

On my computer (which is rather slow) it took about 20 minutes to reduce about 3000 nodes down to about 200 nodes. Most of that time seems to be fetching the data from TurboCAD.

The script works on TurboCAD 17.2 Pro using the MacroRecorder palette: Select the objects to be processed, run the code, enter the tolerance and wait.

It seems to be a reliable program, but could be improved.
1. At the moment I haven't found a way to report progress (The MsgBox command will output strings, but then waits for the user to OK)
2. Objects which are not polylines (type "GRAPHIC") are ignored.
3. If a polyline contains a circular arc, it will be treated as a line (ie ignored)
3. It only handles 2D polylines.

It's my first TurboCAD/VBS program. Hope it is useful. Improvements are welcome.

The attached file has the extension ".txt" because the extension ".vbs" isn't allowed.
To use this file, change the extention to ".vbs".