Hello, I have a problem . Hope somebody could correct me. I am going to collect objectid's of the moved items in drawing after they moved to destination. So I wrote an event to monitor move command , by using object modified event handler. when I run below code for every entity it collects 2 object id. One before move and one after move. Is there any way to just collect object ids after they moved?
Thanks for any help.
Janet.
Class EVENTS Dim MyDwg As Document = Application.DocumentManager.MdiActiveDocument Dim Myed As Editor = MyDwg.Editor Dim Mydb As Database = MyDwg.Database Dim Myobjidcoll As ObjectIdCollection Sub On_Command_Will_Start(ByVal sender As Object, ByVal e As CommandEventArgs) Select Case e.GlobalCommandName Case "MOVE" Dim Myobjidcoll As New ObjectIdCollection AddHandler Mydb.ObjectModified, AddressOf Myobj_Moved End Select End Sub Sub Myobj_moved(ByVal sender As Object, ByVal e As ObjectEventArgs) Myobjidcoll.Add(e.DBObject.ObjectId) End Sub End Class
Solved! Go to Solution.
Solved by Artvegas. Go to Solution.
Hi Janet,
I'm not sure why the ObjectId's are being duplicated in your collection. I looked at the Database.ObjectModified event when using the MOVE command, and for me it was only fired once for each moved item. Note: I'm using AutoCAD 2012.
But if this is not what is happening for you, my thoughts would be that you could:
1. Use the Document.CommandWillStart event with the MOVE command to register the Database.ObjectModified event. I believe this is what you have done.
2. In the Database.ObjectModified event handler, first check if the ObjectIdCollection already contains the ObjectId, i.e use the ObjectIdCollection.Contains() function, and if not then add the ObjectId to the collection. This will prevent any duplication.
3. Use the Document.CommandWillEnd event with the MOVE command to un-register the Database.ObjectModified event, and then do whatever you need to do with the ObjectIdCollection.
Hope this helps,
Art
Just had another thought.
Could it be that your code registers the Database.ObjectModified event handler more than once?
Based on your snippet, it might be that each time you start the MOVE command, you are "adding" another event handler. In other words you might end up with the same event handler being fired multiple times.
Have you included code to un-register the Database.ObjectModified event handler when the MOVE command has finished?
Art
Hello Artvegas
well never thought of that. I checked it and yes your are right. object modify fires 2 times.
Thank you very much. Sometimes without help brain doesn't work.
Cheers Artvegas.
Janet.