Hello,

This script allow to round the coordinates of the points in a polyline to the given number of decimals.

Only XYZ coordinates are rounded, the bulge value is not affected.

The number of decimals is set to 5 by default, but you can change it in the code ; change the value in the line:

* dim nbdeci as integer = 5*Only polylines are modified.

`'Round the coordinates of points in a polyline `

' to the given number of decimals.

' DH42 - 16/09/13 - V1.00

sub main

CamBamConfig.Defaults.ReloadTreeAfterScript = false

dim ent as Entity

dim pli as Polyline

dim plitem as PolylineItem

dim NewPoint as point3F

dim blg as double

dim nbdeci as integer = 5

dim ct as integer

dim nbpoints as integer

dim rep as string

app.Clearlog()

'ask for nb of decimals

rep = inputbox("Number of decimals","Round points coordinates",trim(str(nbdeci)))

if rep <> "" 'if not canceled

nbdeci=val(rep)

'if reply is out of range

if nbdeci < 0 or nbdeci > 15

msgbox("Nb of decimals must be between 0 - 15")

exit sub

end if

'scan selected entities

for each ent in view.SelectedEntities

if typeof ent is Polyline 'if polyline

pli = ent

if pli.Closed = True 'if polyline is closed nb points = nb segmentss - 1

nbpoints = pli.NumSegments-1

else

nbpoints = pli.NumSegments

end if

for ct = 0 to nbpoints 'scan all points in the polyline

plitem = pli.Points(ct)

' store the rounded values of the current point in a temp variable (Point3F)

NewPoint.x = Math.round(plitem.point.x,nbdeci)

NewPoint.y = Math.round(plitem.point.y,nbdeci)

NewPoint.z = Math.round(plitem.point.z,nbdeci)

' store the Bulge (not rounded)

blg = plitem.Bulge

'remove the current polylineitem

pli.Points.RemoveAt(ct)

' add the modified polylineitem at the same position

pli.InsertSegmentBefore(ct, new PolylineItem(NewPoint,blg))

next

end if

next

view.ClearSelections()

view.RefreshView()

end if

end sub

Thanks to pstemari for is help

I (want) use this script when I've problem with leadmove (wrong direction), or missing toolpath in pockets, I discover that mostly, if I round the values of the points, the bug go away ... but it's long to do manually ...

++

David