I need a solution for the following szenari:
When the user inserts a block to the modelspace I would like to explode it and attach some xData. Inside the block there is always only one entity.
I tried to find a solution with a ObjetAppended reactor.
Within this eventhandler I can read the objects parent database Handle and compare it to the ModelSpace Handle.
Now I know that this object was added to the modelspace.
Next step would be to explode the new object. I tried it with the following code, but it did not work. What is wrong?
Private Sub ObjectAppended(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs)
If _sModelSpaceHandle = e.DBObject.OwnerId.Handle.ToString Then
Dim trans As Transaction
trans = HostApplicationServices.WorkingDatabase().TransactionManager.StartTransaction()
Dim ent As Entity = trans.GetObject(e.DBObject.ObjectId, OpenMode.ForRead, False)
Dim entset As New Autodesk.AutoCAD.DatabaseServices.DBObjectCollection
I think that exploding did work, it just doesn't work the same way it did in VBA. If you set a breakpoint on "trans.Commit()
" and you then inspect "entset" I believe you will see the exploded contents of your block. I think you then have to :
1.call AppendEntity on the blocktablerecord
2.then call AddNewlyCreatedDBObject on the transaction
3. then commit and close
You may not have to do both 1 and 2, but i'm not sitting at a computer with ACAD, so i can't test it. Anyways here is some UNTESTED code (Attached).
You may also need to remove the original block from the database after you explode it, I'll leave that up to you.