Sub RemoveItems_Example()
' This example creates some entities and adds them to a
' selection set, and then removes 2objects from the selection set
' using the .RemoveItems 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
' Remove two of the objects from the selection set
' Note: .RemoveItems removes items from the selection set
' but the entities remain in the drawing.
'(removed items are simply no longer associated to the selection set)
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) '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
Bricscad™ is commercialized by Bricsys NV. Bricsys NV and Vondle NV are fully owned subsidiaries of Menhirs NV. © 2001- Menhirs NV - All rights reserved. |