In my code as shown below I try to cath the SaveComplete event:
public void Request() { try { Database db = HostApplicationServices.WorkingDatabase; Document current_doc = Application.DocumentManager.GetDocument(db); current_doc.Database.BeginSave += OnBeginSave; current_doc.Database.SaveAs(drawing_path, DwgVersion.Current); } catch (System.Exception) { } } void OnSaveComplete(object sender, DatabaseIOEventArgs e) { try { Database db = sender as Database; if (db != null) { db.SaveComplete -= OnSaveComplete; } } catch (System.Exception) { } } void OnBeginSave(object sender, DatabaseIOEventArgs e) { try { Database db = sender as Database; if (db != null) { db.BeginSave -= OnBeginSave; db.SaveComplete += OnSaveComplete; } } catch (System.Exception) { } }
But it looks as it works fine in Civil3D up to version 2013. In later versions the SaveComplete event is not fired or something. Any suggestions?
Solved! Go to Solution.
Solved by aknigin. Go to Solution.
If the code you showed here is the same in your project for Acad (or Civil3d, not different here) 2014/15, and 2013, the code in the OnSaveComplete() would never run, regardless AutoCAD's version: you did not hook the event handler (OnSaveComplete()) to any event that might be fired by Document/Database. That is, whatever event AutoCAD exposed ALWAYS fires, your code only responds to a event when your code hooks an event handler to the event. Just as you did with Database.BeginSave event. You need to add
current_Doc.Database.SaveComplete+=OnSaveComplete;
Isn't it quite obvious?
Norman Yuan
Norman,
I do subscribe to the SaveComplete event - in OnBeginSave handler, which you can see in the code snippet. But whatever - I tried to subscribe to both events in the Request() method and got the same results, of course: it does work in Civil3D up to version 2013, and in the versions 2014 and 2015 only BeginSave event is fired.
Your post gave me some idea, I made investigations and it seems that the Database.SaveAs method should be called from the main thread to the events work properly.