Erase method example


Sub Erase_Example()
    ' This example creates some entities and adds them to a
    ' selection set, and then erases the objects from the selection set
    ' using the .Erase method
    Dim pt1(0 To 2) As Double
    Dim pt2(0 To 2) As Double
    ' Create a Ray object in model space
    pt1(0) = 3: pt1(1) = 3: pt1(2) = 0
    pt2(0) = 1: pt2(1) = 3: pt2(2) = 0
    Dim rayObj As AcadRay
    Set rayObj = ThisDrawing.ModelSpace.AddRay(pt1, pt2)
    ' Create a polyline object in model space
    Dim points(0 To 5) As Double
    points(0) = 3: points(1) = 7
    points(2) = 9: points(3) = 2
    points(4) = 3: points(5) = 5
    Dim plineObj As AcadLWPolyline
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    plineObj.Closed = True
    ' Create a line object in model space
    pt1(0) = 0: pt1(1) = 0: pt1(2) = 0
    pt2(0) = 2: pt2(1) = 2: pt2(2) = 0
    Dim lineObj As AcadLine
    Set lineObj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
    ' Create a circle object in model space
    pt1(0) = 20: pt1(1) = 30: pt1(2) = 0
    Dim radius As Double: radius = 3
    Dim circObj As AcadCircle
    Set circObj = ThisDrawing.ModelSpace.AddCircle(pt1, radius)
    ' Create an ellipse object in model space
    Dim majAxis(0 To 2) As Double
    Dim center(0 To 2) As Double
    Dim radRatio As Double
    center(0) = 5#: center(1) = 5#: center(2) = 0#
    majAxis(0) = 10: majAxis(1) = 20#: majAxis(2) = 0#
    radRatio = 0.3
    Dim ellObj As AcadEllipse
    Set ellObj = ThisDrawing.ModelSpace.AddEllipse(center, majAxis, radRatio)
    ZoomAll
    ' Create the new selection set
    Dim oSS As AcadSelectionSet
    Set oSS = ThisDrawing.ActiveSelectionSet 'reference the built-in or default (unnamed) selection set
    oSS.Clear 'clear the SS content since it could contain entities from previous selection
    ' Collect all the entities in the drawing into an array
    ReDim arrayOfObjects(0 To ThisDrawing.ModelSpace.Count - 1) As AcadEntity
    Dim i As Integer
    For i = 0 To ThisDrawing.ModelSpace.Count - 1
        Set arrayOfObjects(i) = ThisDrawing.ModelSpace.Item(i)
    Next
    oSS.AddItems arrayOfObjects 'Add the array of objects to the selection set
    MsgBox getContent(oSS) 'Display info on the selection set content
    oSS.Erase 'Erase the objects in the selection set
    MsgBox getContent(oSS) 'Display info on the selection set content
    Set oSS = Nothing
    ThisDrawing.Application.ZoomExtents
End Sub
Private Function getContent(inSelectionSet As AcadSelectionSet) As String
    Dim sBuf As String:    sBuf = vbNullString
    Dim i As Integer
    If inSelectionSet.Count = 0 Then
            sBuf = "The selection set is empty"
        Else
            sBuf = "The selection set contains:"
            For i = 0 To inSelectionSet.Count - 1
                sBuf = sBuf & vbCrLf & inSelectionSet.Item(i).ObjectName
            Next
    End If
    getContent = sBuf
End Function

© Bricsys NV. All rights reserved.