CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

删除方法 (ActiveX)

2023-1-4 11:03| 发布者: admin| 查看: 531| 评论: 0|来自: AutoCAD

摘要: 删除指定的对象或一组已保存的图层设置。

删除指定的对象或一组已保存的图层设置。

支持的平台:仅窗口

签名

工 务 局:

object.Delete
对象

类型:所有图形对象属性参考,块,字典暗淡样式,超链接,图层,图层状态管理器布局线型材料MLeader样式,打印配置弹出菜单项注册应用程序选择集表格样式文本样式工具栏工具栏项UCS视图视口XRecord

此方法适用的对象。

返回值(RetVal)

无返回值。

言论

删除集合中的对象时,将根据当前计数重新分配集合中的所有剩余项的新索引。因此,应避免在循环访问集合时删除对象的循环。例如,以下 VBA 代码将导致运行时错误:

For i = 0 To ThisDrawing.Groups.Count - 1
    ThisDrawing.Groups.Item(i).Delete
Next I

相反,请使用以下 VBA 代码删除集合中的所有成员:

For Each obj In ThisDrawing.Groups
    obj.Delete
Next obj

还可以使用以下 VBA 代码删除集合的单个成员:

ThisDrawing.Groups.Item("group1").Delete

如果尝试删除集合对象,将导致错误。

工具栏项:仅当工具栏可见时,才能添加或删除工具栏项

LayerStateManager:此对象采用参数 Name,这是一个表示要删除的图层状态的字符串。

例子

工 务 局:

Sub Example_Delete()
    ' This example creates a Layer named "TEST".
    ' It then iterates the Layers collection and displays
    ' the names of the available layers.
    ' It then deletes the layer "TEST", and again iterates
    ' the layers collection and displays the names of
    ' available layers.
    
    Dim layerObj As AcadLayer
    
    ' Create the new layer
    Set layerObj = ThisDrawing.Layers.Add("TEST")
    
    ' Display the names of the layers in the drawing
    GoSub DISPLAYLAYERS
    
    ' Delete the layer "TEST"
    layerObj.Delete
    
    ' Display the names of the layers remaining in the drawing
    GoSub DISPLAYLAYERS
    
    Exit Sub
    
DISPLAYLAYERS:
    Dim entry As AcadLayer
    Dim layerNames As String
    layerNames = ""
    For Each entry In ThisDrawing.Layers
       layerNames = layerNames & entry.name & ", "
    Next
    MsgBox "The drawing consists of the following layers:" & vbCr & layerNames, , "Delete Example"
    Return
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_Delete()
    ;; This example creates a Layer named "TEST".
    ;; It then iterates the Layers collection and displays
    ;; the names of the available layers.
    ;; It then deletes the layer "TEST", and again iterates
    ;; the layers collection and displays the names of
    ;; available layers.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Create the new layer
    (setq layerObj (vla-Add (vla-get-Layers doc) "TEST"))
    
    ;; Display the names of the layers in the drawing
    (setq layerNames "")
    (vlax-for entry (vla-get-Layers doc)
       (setq layerNames (strcat layerNames (vla-get-Name entry) ", "))
    )
    (alert (strcat "The drawing consists of the following layers: \n" layerNames))
    
    ;; Delete the layer "TEST"
    (vla-Delete layerObj)
    
    ;; Display the names of the layers remaining in the drawing   
    (setq layerNames "")
    (vlax-for entry (vla-get-Layers doc)
       (setq layerNames (strcat layerNames (vla-get-Name entry) ", "))
    )
    (alert (strcat "The drawing consists of the following layers: \n" layerNames))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 14:59

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部