.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Catch inserted block and explode

2 REPLIES 2
Reply
Message 1 of 3
Jan1
241 Views, 2 Replies

Catch inserted block and explode

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
ent.Explode(entset)

trans.Commit()
trans.Dispose()

End If
End Sub
=============================================

Regards, Jan
2 REPLIES 2
Message 2 of 3
cgay
in reply to: Jan1

Jan,

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.

Regards,
C
Message 3 of 3
Jan1
in reply to: Jan1

It works!
Thanks, Jan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost