Item Method (ActiveX)

Gets the member object at a given index in a collection, group, or selection set.

Supported platforms: Windows only

Signature

VBA:

RetVal = object.Item(Index)
object

Type: All collections, Group, SelectionSet

The objects this method applies to.

Index

Access: Input-only

Type: Variant

The index location in the collection for the member item to query.

The index must be either an integer or a string. If an integer, the index must be between 0 and N-1, where N is the number of objects in the collection or selection set.

Return Value (RetVal)

Type: Object

The object at the given index location in the collection or selection set.

Remarks

This method supports string-based iteration. For example, if a block named BLOCK1 was created with the following statement:

Set block1 = Blocks.Add("BLOCK1")

you could reference the object through the following statement:

Set whichblock = Blocks.Item("BLOCK1")
Note: The Item method is case-sensitive when used with the SelectionSets collection; it is not case-sensitive for other collections.

Dictionaries: The return value type for this method is IAcadObject. This allows you to retrieve named objects from the dictionaries collection that are not of the type Dictionary.

Examples

VBA:

Sub Example_Item()
    ' This example shows two uses of the Item method.
    ' The first uses Item with an index counter to return an item in a collection.
    ' The second uses Item with a string to return an item in a collection.
    
    ' Iterate thru the model space collection,
    ' get all the items in the collection
    ' and store them in an array called newObjs
    Dim count As Integer
    count = ThisDrawing.ModelSpace.count
    
    ReDim newObjs(count) As AcadEntity
    Dim index As Integer
    For index = 0 To count - 1
        Set newObjs(index) = ThisDrawing.ModelSpace.Item(index)
    Next
    
    ' Get a particular item, in this case a layer, based on name "0"
    Dim layerObj As AcadLayer
    Set layerObj = ThisDrawing.Layers.Item("0")
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_Item()
    ;; This example shows two uses of the Item method.
    ;; The first uses Item with an index counter to return an item in a collection.
    ;; The second uses Item with a string to return an item in a collection.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    ;; Iterate thru the model space collection,
    ;; get all the items in the collection
    ;; and store them in an array called newObjs
    (setq count (vla-get-Count (vla-get-ModelSpace doc))
          index 0)
    
    (setq newObjs (vlax-make-safearray vlax-vbObject (cons 0 count)))

    (while (>= (1- count) index)
        (vlax-safearray-put-element newObjs index (vla-Item (vla-get-ModelSpace doc) index))
        (setq index (1+ index))
    )
    
    ;; Get a particular item, in this case a layer, based on name "0"
    (setq layerObj (vla-Item (vla-get-Layers doc) "0"))
)