Count プロパティ(ActiveX)

オブジェクト内の要素の数を取得します。

サポートされているプラットフォーム: Windows のみ

構文と要素

VBA:

object.Count
object

タイプ: すべてのコレクションBlockDictionaryGroupMaterialsSectionManagerSelectionSet

このプロパティが適用されるオブジェクト。

プロパティの値

読み込み専用: はい

タイプ: 整数型

オブジェクト内の要素の数。

注意

追加の注意はありません。

VBA:

Sub Example_Count()
    ' Use count to retrieve the number of objects in a collection
    ' You might use this value in a loop structure to iterate through the collection
    
    MsgBox "There are " & ThisDrawing.Layers.Count & " layer(s) in the drawing."
    MsgBox "There are " & ThisDrawing.ModelSpace.Count & " object(s) in ModelSpace."

    Dim objCount As Integer
    Dim I As Integer
    objCount = ThisDrawing.ModelSpace.Count
    
    Dim mspaceObj As AcadObject
    For I = 0 To objCount - 1
        Set mspaceObj = ThisDrawing.modelSpace.Item(I)
        MsgBox "The objects in ModelSpace include: " & mspaceObj.ObjectName, vbInformation, "Count Example"
    Next
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_Count()
    ;; Use count to retrieve the number of objects in a collection
    ;; You might use this value in a loop structure to iterate through the collection
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    (alert (strcat "There are " (itoa (vla-get-Count (vla-get-Layers doc))) " layer(s) in the drawing."))
    (alert (strcat "There are " (itoa (vla-get-Count (vla-get-ModelSpace doc))) " object(s) in ModelSpace."))

    (setq I 0
	  objCount (vla-get-Count (vla-get-ModelSpace doc)))
    
    (while (>= (- objCount 1) I)
        (setq mspaceObj (vla-Item (vla-get-ModelSpace doc) I)
	      I (1+ I))
        (alert (strcat "The objects in ModelSpace include: " (vla-get-ObjectName mspaceObj)))
    )
)