Author Topic: Remove Stairs (VBS Script)  (Read 7464 times)

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7597
    • View Profile
    • Cambam V1.0 French Doc
Remove Stairs (VBS Script)
« on: May 26, 2023, 20:54:37 pm »
Hello

This VBS script remove on point on two on the selected polylines, this remove the "stairs" effect resulting of a bitmap digitizing.

Simple but efficient ;)

Prior to use it, create a new layer so the new created polylines can be easily separated from the source polylines.

Code: [Select]
' Remove stairs (for digitized images)
' scan all selected polylines and remove one point on two

sub main

        Dim p As Polyline
        Dim p2 As Polyline = New Polyline 'temporary polyline
        Dim toggle As Boolean = False
        Dim pt As Point3F

        If CamBamUI.MainUI.ActiveView.SelectedEntities.Length > 0 Then 'if something selected

            For Each ent As Entity In CamBamUI.MainUI.ActiveView.SelectedEntities 'scan all selected entyties

                If TypeOf ent Is Polyline Then 'reject other than polyline object

                    p = ent

                    For Each p_item As PolylineItem In p.Points 'scan the point item list

                        If toggle = True Then

                            pt.X = p_item.Point.X
                            pt.Y = p_item.Point.Y
                            pt.Z = p_item.Point.Z

                            p2.Add(pt)

                            toggle = False

                        Else 'item ignored
                            toggle = True
                        End If

                    Next
                   
                    If p.Closed = True then
                        p2.Closed = True
                    else
                        p2.Closed = False
                    End If
                   
                    Doc.Add(p2.Clone)'add a clone of the temp polyline to the document
                    p2.Points.Clear()' erase the temp polyline

                End If

            Next ent

            CamBamUI.MainUI.ActiveView.RefreshView()

        End If
   
end sub

edit:
an example



++
David

(PS: VB script does not works on 64bits versions of CamBam)
« Last Edit: May 31, 2023, 19:24:00 pm by dh42 »