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

Database.SaveComplete event is not fired in Civil3D 2014 and 2015

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
aknigin
466 Views, 4 Replies

Database.SaveComplete event is not fired in Civil3D 2014 and 2015

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?

4 REPLIES 4
Message 2 of 5
norman.yuan
in reply to: aknigin

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

Drive CAD With Code

EESignature

Message 3 of 5
aknigin
in reply to: 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.

Message 4 of 5
mcicognani
in reply to: aknigin

I'm not sure you can add the SaveComplete handler inside the OnBeginSave event... isn't too close a call?
I cannot debug your code, but I can say you what I normally do and works well:
- in the plugin init I attach an event handler to the Application.DocumentManager.DocumentCreated event;
- in the DocumentCreated handler I add alla the handler needed, in my case both BeginSave and SaveComplete

Only drawback, the plugin may start after the first document load, so you also need to cycle through the DocumentManager and attach the handlers to the already loaded documents.
I assure you this works.
Message 5 of 5
aknigin
in reply to: mcicognani

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.

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