CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

项方法 (ActiveX)

2023-1-4 05:40| 发布者: admin| 查看: 611| 评论: 0|来自: AutoCAD

摘要: 获取集合、组或选择集中给定索引处的成员对象。

获取集合、组或选择集中给定索引处的成员对象。

支持的平台:仅窗口

签名

工 务 局:

RetVal = object.Item(Index)
对象

类型:所有集合选择集

此方法适用的对象。

指数

访问:仅输入

类型:变体

要查询的成员项在集合中的索引位置。

索引必须是整数或字符串。如果是整数,则索引必须介于 0 和N-1 之间,其中N是集合或选择集中的对象数。

返回值(RetVal)

类型:对象

集合或选择集中给定索引位置的对象。

言论

此方法支持基于字符串的迭代。例如,如果使用以下语句创建了名为 BLOCK1 的块:

Set block1 = Blocks.Add("BLOCK1")

您可以通过以下语句引用对象:

Set whichblock = Blocks.Item("BLOCK1")
注意:Item 方法在与集合一起使用时区分大小写;对于其他集合,它不区分大小写。SelectionSets

字典:此方法的返回值类型为。这允许您从字典集合中检索不属于该类型的命名对象。IAcadObjectDictionary

例子

工 务 局:

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"))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-12 03:17

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部