Discussion:
Using VBA to insert a block
(too old to reply)
MarkW
2004-06-19 15:19:04 UTC
Permalink
Can anyone tell me why this code inserts the block twice and explodes only once?
All the code should do is insert a one block, explode the block and zoom Extents.
I can insert and explode this block manually and it works like it should.

CODE --------------

Option Explicit

'This code inserts the Title/Border block "DMR-OFRAME".
Public Sub InsertOframe()

Dim BlockReference As AcadBlockReference 'Declares a variable named "BlockReference".
Dim ExplodedObjects As Variant 'Declares a variable named "ExplodedObjects".

'Declares an array for insert point coordinates for title block.
Dim InputPoint(0 To 2) As Double 'Declares a variable named "InputPoint"
InputPoint(0) = 0 'X
InputPoint(1) = 0 'Y
InputPoint(2) = 0 'Z

'The [NAME] of the block should include the path with the ".dwg" extension on the end.
Set BlockReference = ThisDrawing.ModelSpace.InsertBlock(InputPoint, "C:\DRAWINGS\Designer DMR-UPU\Rev 6\DMR-OFRAME.dwg", 1#, 1#, 1#, 0#)

'Calls the "Update" method of the "BlockReference" to ensure that the block was drawn in Model Space.
BlockReference.Update

'Explodes the title block -
ExplodedObjects = BlockReference.Explode

'Zooms to extents of drawing
ZoomExtents

End Sub
greg hoyt
2004-06-19 17:05:02 UTC
Permalink
i haven't used the explode method before, but perhaps it doesn't delete
the block reference, just creates the new exploded entities, and leaves
it to the programmer to delete the original block reference.
Post by MarkW
Can anyone tell me why this code inserts the block twice and explodes only once?
All the code should do is insert a one block, explode the block and zoom Extents.
I can insert and explode this block manually and it works like it should.
CODE --------------
Option Explicit
'This code inserts the Title/Border block "DMR-OFRAME".
Public Sub InsertOframe()
Dim BlockReference As AcadBlockReference 'Declares a variable named "BlockReference".
Dim ExplodedObjects As Variant 'Declares a variable named "ExplodedObjects".
'Declares an array for insert point coordinates for title block.
Dim InputPoint(0 To 2) As Double 'Declares a variable named "InputPoint"
InputPoint(0) = 0 'X
InputPoint(1) = 0 'Y
InputPoint(2) = 0 'Z
'The [NAME] of the block should include the path with the ".dwg" extension on the end.
Set BlockReference = ThisDrawing.ModelSpace.InsertBlock(InputPoint, "C:\DRAWINGS\Designer DMR-UPU\Rev 6\DMR-OFRAME.dwg", 1#, 1#, 1#, 0#)
'Calls the "Update" method of the "BlockReference" to ensure that the block was drawn in Model Space.
BlockReference.Update
'Explodes the title block -
ExplodedObjects = BlockReference.Explode
'Zooms to extents of drawing
ZoomExtents
End Sub
Jeff Mishler
2004-06-19 19:32:31 UTC
Permalink
This is exactly how the explode function works......

Jeff
Post by greg hoyt
i haven't used the explode method before, but perhaps it doesn't delete
the block reference, just creates the new exploded entities, and leaves
it to the programmer to delete the original block reference.
Loading...