How can I delete a block in a block?

How can I delete a block in a block?

Anonymous
Not applicable
309 Views
2 Replies
Message 1 of 3

How can I delete a block in a block?

Anonymous
Not applicable
Hello,
I have a block (A1) in a other block (A2) - (A2(A1)) or I have
three or more blocks - (CF(G3(A1))).
The name from the blocks are always different. Only the block A1
have always the same name!
Now I must delete with VBA (AutoCAD 2005) the block A1.
The blocks A2, CF, G3, ... I can also delete, but I don´t know the name!

Dim objBlock As AcadBlock
For i = 0 To ThisDrawing.Blocks.Count - 1
Set objBlock = ThisDrawing.Blocks(i)
If objBlock.Name = "A1" Then obkBlock.Delete '<<< error, because
in the drawing is a blockreference
Next i
0 Likes
310 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Dim objBlockA1 As AcadBlock
Dim objBlock As AcadBlock
Dim objEntity As AcadEntity
Dim objRef As AcadBlockReference

''First verify the block is in the drawing
On Error Resume Next
Set objBlockA1 = ThisDrawing.Blocks("A1")
If Error.Number = 0 Then
On Error GoTo ErrHandler
For Each objBlock In ThisDrawing.Blocks
For Each objEntity in objBlock
If TypeOf objEntity Is AcadBlockReference Then
Set objRef = objEntity
If objRef.Name = "A1" Then objRef.Delete
End If
Next
Next
objBlockA1.Delete
Else
Exit Sub
End If

"Hartmut Callies" wrote in message
news:5450792@discussion.autodesk.com...
Hello,
I have a block (A1) in a other block (A2) - (A2(A1)) or I have
three or more blocks - (CF(G3(A1))).
The name from the blocks are always different. Only the block A1
have always the same name!
Now I must delete with VBA (AutoCAD 2005) the block A1.
The blocks A2, CF, G3, ... I can also delete, but I don´t know the name!

Dim objBlock As AcadBlock
For i = 0 To ThisDrawing.Blocks.Count - 1
Set objBlock = ThisDrawing.Blocks(i)
If objBlock.Name = "A1" Then obkBlock.Delete '<<< error, because
in the drawing is a blockreference
Next i
0 Likes
Message 3 of 3

Anonymous
Not applicable
Many thanks!

Hartmut Callies

___________________________________________________________________


"Jeff Mishler" schrieb im Newsbeitrag
news:5450817@discussion.autodesk.com...
Dim objBlockA1 As AcadBlock
Dim objBlock As AcadBlock
Dim objEntity As AcadEntity
Dim objRef As AcadBlockReference

''First verify the block is in the drawing
On Error Resume Next
Set objBlockA1 = ThisDrawing.Blocks("A1")
If Error.Number = 0 Then
On Error GoTo ErrHandler
For Each objBlock In ThisDrawing.Blocks
For Each objEntity in objBlock
If TypeOf objEntity Is AcadBlockReference Then
Set objRef = objEntity
If objRef.Name = "A1" Then objRef.Delete
End If
Next
Next
objBlockA1.Delete
Else
Exit Sub
End If

"Hartmut Callies" wrote in message
news:5450792@discussion.autodesk.com...
Hello,
I have a block (A1) in a other block (A2) - (A2(A1)) or I have
three or more blocks - (CF(G3(A1))).
The name from the blocks are always different. Only the block A1
have always the same name!
Now I must delete with VBA (AutoCAD 2005) the block A1.
The blocks A2, CF, G3, ... I can also delete, but I don´t know the name!

Dim objBlock As AcadBlock
For i = 0 To ThisDrawing.Blocks.Count - 1
Set objBlock = ThisDrawing.Blocks(i)
If objBlock.Name = "A1" Then obkBlock.Delete '<<< error, because
in the drawing is a blockreference
Next i
0 Likes