RemoveItems method example
Sub RemoveItems_Example()
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
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)
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
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)
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)
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
Dim oSS As AcadSelectionSet
Set oSS = ThisDrawing.ActiveSelectionSet
oSS.Clear
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
MsgBox getContent(oSS)
Dim removeObjects(0 To 1) As AcadEntity
Set removeObjects(0) = ellObj
Set removeObjects(1) = lineObj
oSS.RemoveItems removeObjects
MsgBox "The ellipse and line have been removed from the selection set."
MsgBox getContent(oSS)
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. |