RemoveItems Method (ActiveX)

Removes specified items from the group or selection set.

Supported platforms: Windows only

Signature

VBA:

object.RemoveItems Objects
object

Type: Group, SelectionSet

The objects this method applies to.

Objects

Access: Input-only

Type: Variant (array of objects)

An array of objects to be removed.

Return Value (RetVal)

No return value.

Remarks

Items removed from a group or selection set remain in the drawing; they are simply no longer associated to the group or selection set. This functionality mimics the functionality found in the Clear method, except that RemoveItems allows you to specify individual items to be removed instead of the entire selection set.

This method differs from the Delete and Erase methods in that it does not remove objects from the drawing.

Examples

VBA:

Sub Example_RemoveItems()
    ' This example creates a selection set and several objects.
    ' It adds the objects to the selection set, and then
    ' removes two of the objects from the selection set.
    
    ' Create the new selection set
    Dim ssetObj As AcadSelectionSet
    Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SELECTIONSET")
    
    ' Create a Ray object in model space
    Dim rayObj As AcadRay
    Dim basePoint(0 To 2) As Double
    Dim SecondPoint(0 To 2) As Double
    basePoint(0) = 3#: basePoint(1) = 3#: basePoint(2) = 0#
    SecondPoint(0) = 1#: SecondPoint(1) = 3#: SecondPoint(2) = 0#
    Set rayObj = ThisDrawing.ModelSpace.AddRay(basePoint, SecondPoint)
    
    ' Create a polyline object in model space
    Dim plineObj As AcadLWPolyline
    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
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    plineObj.Closed = True

    ' Create a line object in model space
    Dim lineObj As AcadLine
    Dim startPoint(0 To 2) As Double
    Dim endPoint(0 To 2) As Double
    startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0
    endPoint(0) = 2: endPoint(1) = 2: endPoint(2) = 0
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
    
    ' Create a circle object in model space
    Dim circObj As AcadCircle
    Dim centerPt(0 To 2) As Double
    Dim radius As Double
    centerPt(0) = 20: centerPt(1) = 30: centerPt(2) = 0
    radius = 3
    Set circObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)

    ' Create an ellipse object in model space
    Dim ellObj As AcadEllipse
    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
    Set ellObj = ThisDrawing.ModelSpace.AddEllipse(center, majAxis, radRatio)

    ZoomAll
    
    ' Iterate through the model space collection.
    ' Collect the objects found into an array of objects
    ' to be added to the selection set.
    ReDim ssobjs(0 To ThisDrawing.ModelSpace.Count - 1) As AcadEntity
    Dim I As Integer
    For I = 0 To ThisDrawing.ModelSpace.Count - 1
        Set ssobjs(I) = ThisDrawing.ModelSpace.Item(I)
    Next
    
    ' Add the array of objects to the selection set
    ssetObj.AddItems ssobjs
    GoSub LISTOBJS
    
    ' Remove two of the objects from the selection set
    Dim removeObjects(0 To 1) As AcadEntity
    Set removeObjects(0) = ellObj
    Set removeObjects(1) = circObj
    ssetObj.RemoveItems removeObjects
    MsgBox "The ellipse and circle have been removed from the selection set."
    GoSub LISTOBJS

    Exit Sub

LISTOBJS:
    
    ' List all the objects in the selection set
    If ssetObj.Count = 0 Then
        MsgBox "The selection set is empty"
    Else
        For I = 0 To ssetObj.Count - 1
            MsgBox "The selection set contains: " & ssetObj.Item(I).ObjectName
        Next
    End If
    Return
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_RemoveItems()
    ;; This example creates a selection set and several objects.
    ;; It adds the objects to the selection set, and then
    ;; removes two of the objects from the selection set.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    (setq modelSpace (vla-get-ModelSpace doc))

    ;; Create the new selection set
    (setq ssetObj (vla-Add (vla-get-SelectionSets doc) "TEST_SELECTIONSET"))
    
    ;; Create a Ray object in model space
    (setq basePoint (vlax-3d-point 3 3 0)
          secondPoint (vlax-3d-point 1 3 0))
    (setq rayObj (vla-AddRay modelSpace basePoint SecondPoint))
    
    ;; Create a polyline object in model space
    (setq points (vlax-make-safearray vlax-vbDouble '(0 . 5)))
    (vlax-safearray-fill points '(3 7
                                  9 2
				  3 5
				 )
    )
    (setq plineObj (vla-AddLightWeightPolyline modelSpace points))
    (vla-put-Closed plineObj :vlax-true)

    ;; Create a line object in model space
    (setq startPoint (vlax-3d-point 0 0 0)
          endPoint (vlax-3d-point 2 2 0))
    (setq lineObj (vla-AddLine modelSpace startPoint endPoint))
    
    ;; Create a circle object in model space
    (setq centerPt (vlax-3d-point 20 30 0)
          radius 3)
    (setq circObj (vla-AddCircle modelSpace centerPt radius))

    ;; Create an ellipse object in model space
    (setq center (vlax-3d-point 5 5 0)
          majAxis (vlax-3d-point 10 20 0)
          radRatio 0.3)
    (setq ellObj (vla-AddEllipse modelSpace center majAxis radRatio))

    (vla-ZoomAll acadObj)
    
    ;; Iterate through the model space collection.
    ;; Collect the objects found into an array of objects
    ;; to be added to the selection set.
    (setq ssobjs (vlax-make-safearray vlax-vbObject (cons 0 (- (vla-get-Count modelSpace) 1))))

    (setq cnt 0)
    (vlax-for each-item modelSpace
        (vlax-safearray-put-element ssobjs cnt each-item)
        (setq cnt (1+ cnt))
    )
    
    ;; Add the array of objects to the selection set
    (vla-AddItems ssetObj ssobjs)
  
    ;; List all the objects in the selection set
    (setq I 0)
    (if (= (vla-get-Count ssetObj) 0)
        (alert "The selection set is empty")
        (while (>= (1- (vla-get-Count ssetObj)) I)
            (alert (strcat "The selection set contains: " (vla-get-ObjectName (vla-Item ssetObj I))))

            (setq I (1+ I))
        )
    )
    
    ;; Remove two of the objects from the selection set
    (setq removeObjects (vlax-make-safearray vlax-vbObject '(0 . 1)))
    (vlax-safearray-put-element removeObjects 0 ellObj)
    (vlax-safearray-put-element removeObjects 1 circObj)

    (vla-RemoveItems ssetObj removeObjects)
    (alert "The ellipse and circle have been removed from the selection set.")

    ;; List all the objects in the selection set
    (setq I 0)
    (if (= (vla-get-Count ssetObj) 0)
        (alert "The selection set is empty")
        (while (>= (1- (vla-get-Count ssetObj)) I)
            (alert (strcat "The selection set contains: " (vla-get-ObjectName (vla-Item ssetObj I))))

            (setq I (1+ I))
        )
    )

    (vla-Delete ssetObj)
)