TheSwamp
Code Red => VB(A) => Topic started by: Bob Wahr on October 10, 2005, 05:54:57 PM
-
Here's what I need
- When a specific block is inserted, block reference is exploded
- Elements that make up block are added to a public array so that they can be deleted later
- block reference is deleted (explode method leaves it)
- block definition is deleted
I was trying to do this using the ObjectAdded event but when I try to delete the block reference, I get an error because it is still open for read. I tried to do the block reference deletion in a sub that was called by the event sub. Same result. Can someone kick me in the head and make me think?
-
Above might not be clear or someone might be able to point me in a slightly different direction here's some more rundown
- One of two blocks will be inserted into drawing manually
- The block will ALWAYS be exploded
- The drawing will be saved with the elements from the block in it
- the drawing will NOT be closed with the elements from the block in it
- The block definition and all elements from the block must be gone from the drawing database when the drawing is closed
-
By the time the EndCommand event fires, all the objects should be closed, so in the ObjectAdded Event, just store the ObjectId of the block reference in a global variable. Then, in the EndCommand event, check to see if the global variable for the ObjectId is non-null, and if it is do your processing there. Then nullify the global variable.
Clear as mud?
-
just exactly the kick I needed. Thanks Chuck.
-
You may want to investigate GROUPS for containing the 'exploded' objects .. may make your management a little easier.
-
That's a thought. I was thinking since the explode method writes to a variant array anyway and the objects would never last longer than the current session, I should be fine. I'll keep the groups in mind if I run into any trouble though.
-
Back in the ancient days days of r10 before dialog boxes were, we were inserting exploded blocks at the command line that would not leave a block definition to purge.
All that is necessary is to place an asterisk "*" at the start of your response when the insert command asks for a file name
example - *c:\<path>\<block name.dwg>
It will then prompt for the scale factor (must be uniform in x,y,z), an insert point and lastly the rotation. I have confirmed that this procedure has indeed survived and still works (with Civil 3D 2006).
Perhaps there is a way to incorporate this into your code?
-
808,
This is what I had to use in AutosXeduLe to delete the block ref. Notice the error handling.
Public Function ExplodeEX(oBlkRef As AcadBlockReference)
Dim objEnt As AcadEntity
Dim anEnt As AcadEntity
Dim aBRef As AcadBlockReference
Dim objBlk As AcadBlock
Dim objDoc As AcadDocument
Dim objArray() As AcadEntity
Dim objSpace As AcadBlock
Dim intCnt As Integer
Dim varTemp As Variant
Dim varPnt As Variant
Dim dblScale As Double
Dim dblRot As Double
Dim strBName As String
On Error GoTo Err_Handler
strBName = oBlkRef.Name
'What document is the reference in?
Set objDoc = oBlkRef.Document
'Model space or layout?
Set objSpace = objDoc.ObjectIdToObject(oBlkRef.OwnerID)
Set objBlk = objDoc.Blocks(strBName)
objBlk.Delete
DeleteRefs:
For Each anEnt In ThisDrawing1.ModelSpace
If TypeOf anEnt Is AcadBlockReference Then
Set aBRef = anEnt
If aBRef.Name = strBName Then
aBRef.Delete
End If
End If
Next
For Each anEnt In ThisDrawing1.PaperSpace
If TypeOf anEnt Is AcadBlockReference Then
Set aBRef = anEnt
If aBRef.Name = strBName Then
aBRef.Delete
End If
End If
Next
oBlkRef.Delete
'Release memory
objDoc.PurgeAll
objDoc.PurgeAll
Set objDoc = Nothing
Set objBlk = Nothing
Set objSpace = Nothing
Exit_Here:
Exit Function
Err_Handler:
Select Case Err.Number
Case -2145386476 ' key not found
Resume Exit_Here
Case -2145386420 ' automation error
Resume Exit_Here
Case -2145386239 ' object is referenced
Resume DeleteRefs
Case Else
MsgBox Err.Number & Err.Description, vbOKOnly, "Uh Oh!"
Resume Exit_Here
End Select
End Function
-
Bob,
keep in mind that you can't use the explode method with NUS blocks since A2k4... :realmad:
-
That is indeed a pain Jürg.
-
I will definitely keep that in mind. although the app I was writing was for a very specific case and it worked fine.