Delete 方法 (ActiveX)
删除指定对象或一组已保存的图层设置。 支持的平台:仅限 Windows 签名VBA: object.Delete 返回值 (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
如果尝试删除集合对象,则会导致错误。 ToolbarItem:仅当工具栏可见时,才能添加或删除工具栏项。 LayerStateManager:此对象采用参数 Name,该参数是表示要删除的图层状态的字符串。 例子VBA: 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
可视化 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))
)
|
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-30 00:39
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.