指定されたオブジェクトを削除します。
サポートされているプラットフォーム: Windows のみ
VBA:
object.Delete
タイプ: すべての図形オブジェクト、AttributeReference、Block、Dictionary、DimStyle、Group、Hyperlink、Layer、LayerStateManager、Layout、Linetype、Material、MLeaderStyle、PlotConfiguration、PopupMenuItem、RegisteredApplication、SelectionSet、TableStyle、TextStyle、Toolbar、ToolbarItem、UCS、View、Viewport、XRecord
このメソッドが適用されるオブジェクト。
戻り値はありません。
コレクション内のオブジェクトを削除すると、コレクション内にある残りのすべての項目には、現在のカウントに基づいて新しいインデックスが再び割り当てられます。そのためコレクション内で繰り返しオブジェクトを削除するループを避けなければなりません。たとえば、次の 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: このオブジェクトは、1 つの引数 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
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))
)