View Full Version : Can you insert an exploded block autocad vba
muck
2nd Sep 2010, 03:16 pm
Can you insert an exploded block from a dwg file with autocad vba?
What would be the code for that in Autocad 2010 vba?
dbroada
2nd Sep 2010, 03:21 pm
from the cammand line it is -INSERT *BlockName
have you tried prefixing your block name with a *?
muck
2nd Sep 2010, 04:14 pm
Adding at * in the following code stop the code
ThisDrawing.ModelSpace.InsertBlock startPnt, "*C:\BlockInsert.Dwg", 1#, 1#, 1#, 0
So should adding a star allow this code to work?
Thank you,
muck
2nd Sep 2010, 05:15 pm
Maybe used vba command send to insert the block or maybe try
"C:*\BlockInsert.Dwg" in the code.
dbroada
3rd Sep 2010, 11:08 am
it looks like I was wrong with the *
the best I can find is to explode the block imediately after insertion although the block definition then remains in the drawing
Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(TriPos, "Tri", CScale, CScale, CScale, 0)
BlockRefObj.Explode
Tyke
6th Sep 2010, 06:58 am
after you've exploded can't you delete the block from the blocks collection with the
BlockObject.Delete method?
It is also normal after deleting a member from a collection to do a purge method on the drawing database to clean it all up.
Deleting a block whose name begins with an * can cause AutoCAD to crash.
frenkas
10th Aug 2011, 07:24 am
I coded what you wanted, because I also needed that, maybe I'll save somebody time:
Dim insertionPnt(0 To 2) As Double, BlockRefObj As AcadBlockReference, bname As String, bl As AcadBlock
bname = "e:\block.dwg"
insertionPnt(0) = 0: insertionPnt(1) = 0: insertionPnt(2) = 0
Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, bname, 1#, 1#, 1#, 0)
BlockRefObj.Explode
Set bl = GetBlock(BlockRefObj.Name)
BlockRefObj.Delete
bl.Delete
frenkas
10th Aug 2011, 07:27 am
I used this function:
Public Function GetBlock(pavadinimas As String) As AcadBlock
Dim B1 As AcadBlock
On Error Resume Next 'Error Free Flow
Set B1 = ThisDrawing.Blocks.Item(pavadinimas)
If err.Number <> 0 Then
Set GetBlock = Nothing
Else
Set GetBlock = B1
End If
On Error GoTo 0 'Normal Flow
End Function
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.