Active Contributor
Posts: 43
Registered: ‎05-14-2004
Message 1 of 3 (100 Views)

Catch inserted block and explode

100 Views, 2 Replies
09-15-2006 01:30 AM
Good morning,

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


End If
End Sub

Regards, Jan
Distinguished Contributor
Posts: 125
Registered: ‎08-02-2005
Message 2 of 3 (100 Views)

Re: Catch inserted block and explode

09-15-2006 08:49 AM in reply to: Jan1

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.

Active Contributor
Posts: 43
Registered: ‎05-14-2004
Message 3 of 3 (100 Views)

Re: Catch inserted block and explode

09-18-2006 11:11 PM in reply to: Jan1
It works!
Thanks, Jan
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.