Author Topic: strange problem with events  (Read 7247 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: strange problem with events
« Reply #15 on: March 04, 2013, 03:14:35 PM »
In the BeginSave event have you tried checking DatabaseIOEventArgs.FileName and dropping out if file extension is 'sv$'?

TheMaster

  • Guest
Re: strange problem with events
« Reply #16 on: March 04, 2013, 03:19:33 PM »
after some day's of testing. I've came to a couple of things.

autocad 2009, no problems all works like it should.
autocad 2010, 2011, 2012 no problems all works like it should.


2013 works, until 1 document hits an autosave and the savehandlers are gone.

i know events have limitations, but it has been working for the last 5 years, why did it break in 2013.
the code hasn't changed much between the autocad versions.

Remember that this is not a full database app, i'm only doing a insert or update query to a sql database with 8 block attribute values.
there is no timing issue, or network delay.

i hope a fix is available, otherwise we will stay on 2012.

Most I know who are using customization have passed on AutoCAD 2013, because of many issues. That's what appens when new releases create more problems than they solve.

sybold

  • Newt
  • Posts: 62
Re: strange problem with events
« Reply #17 on: March 04, 2013, 03:31:08 PM »
In the BeginSave event have you tried checking DatabaseIOEventArgs.FileName and dropping out if file extension is 'sv$'?

just tried it, same result. it magically gone

sybold

  • Newt
  • Posts: 62
Re: strange problem with events
« Reply #18 on: March 04, 2013, 03:33:21 PM »
i've got a slim version running now with only printing savebegin and savecomplete in the commandline, not doing any other stuff. same problem.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: strange problem with events
« Reply #19 on: March 04, 2013, 03:58:39 PM »
In first example where does _Document variable come from, which Document is it pointing to?
How about posting a simple project that you can produce the problem with.

trembre

  • Guest
Re: strange problem with events
« Reply #20 on: March 04, 2013, 04:43:10 PM »
 I had the same issue - http://www.theswamp.org/index.php?topic=42961.msg481822#msg481822 - with AutoCAD 2011.

 The problem always arose using BeginSave when multiple drawings were open and an Autosave was fired off - for some reason the event handlers "disappear".  Despite targetting the apparently correct database for my handler as per the above thread, the problem persisted.  To get around this, I started intercepting saves by global command name, which does work well except for one issue - if the user tries to close a drawing without saving, AutoCAD offers them the option, and they click Yes, the code is bypassed. Will be trying the OnCommandWillStart option to see if that fixes it.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: strange problem with events
« Reply #21 on: March 04, 2013, 06:00:59 PM »
I had the same issue - http://www.theswamp.org/index.php?topic=42961.msg481822#msg481822 - with AutoCAD 2011.

 The problem always arose using BeginSave when multiple drawings were open and an Autosave was fired off - for some reason the event handlers "disappear".  Despite targetting the apparently correct database for my handler as per the above thread, the problem persisted.  To get around this, I started intercepting saves by global command name, which does work well except for one issue - if the user tries to close a drawing without saving, AutoCAD offers them the option, and they click Yes, the code is bypassed. Will be trying the OnCommandWillStart option to see if that fixes it.


If you read link posted by trembe Tony mentions problems adding handler multiple times and take a look at your DocumentedCreated and DocumentedActivated handlers.


Using 2013 with AutoSave and no problems.
Fires for each save and still fires after AutoSave has saved for multiple documents.


Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.Runtime;
  3. using Autodesk.AutoCAD.ApplicationServices;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using System.IO;
  8.  
  9.  
  10. // This line is not mandatory, but improves loading performances
  11. [assembly: ExtensionApplication(typeof(AutoCAD_CSharp_plug_in1.MyPlugin))]
  12.  
  13.  
  14. namespace AutoCAD_CSharp_plug_in1
  15. {
  16.  
  17.  
  18.     // This class is instantiated by AutoCAD once and kept alive for the
  19.     // duration of the session. If you don't do any one time initialization
  20.     // then you should remove this class.
  21.     public class MyPlugin : IExtensionApplication
  22.     {
  23.  
  24.  
  25.         void IExtensionApplication.Initialize()
  26.         {
  27.             DocumentCollection docs = Application.DocumentManager;
  28.             foreach (Document doc in docs)
  29.             {
  30.                 doc.Database.BeginSave += new DatabaseIOEventHandler(Database_BeginSave);
  31.             }
  32.  
  33.  
  34.             docs.DocumentCreated += new DocumentCollectionEventHandler(docs_DocumentCreated); ;
  35.         }
  36.  
  37.  
  38.         void docs_DocumentCreated(object sender, DocumentCollectionEventArgs e)
  39.         {
  40.            
  41.             e.Document.Database.BeginSave += new DatabaseIOEventHandler(Database_BeginSave);
  42.         }
  43.  
  44.  
  45.         void Database_BeginSave(object sender, DatabaseIOEventArgs e)
  46.         {
  47.             if (Path.GetExtension(e.FileName) != ".sv$")
  48.             {
  49.                 Application.ShowAlertDialog(e.FileName);
  50.             }
  51.            
  52.         }
  53.  
  54.  
  55.         void IExtensionApplication.Terminate()
  56.         {
  57.             // Do plug-in application clean up here
  58.         }
  59.  
  60.  
  61.     }
  62.  
  63.  
  64. }

trembre

  • Guest
Re: strange problem with events
« Reply #22 on: March 04, 2013, 07:36:30 PM »
Thanks Jeff - your code solves the problems I was having - my event only fires once, survives autosaves and works on close-save.  Now to figure out why - when I changed my code as per Tony and n.yuan's input, I wasn't too far off what you've written yet still had that issue...

Jeff H

  • Needs a day job
  • Posts: 6150
Re: strange problem with events
« Reply #23 on: March 04, 2013, 08:37:00 PM »
Thanks Jeff - your code solves the problems I was having - my event only fires once, survives autosaves and works on close-save.  Now to figure out why - when I changed my code as per Tony and n.yuan's input, I wasn't too far off what you've written yet still had that issue...
I thought the code posted was following Tony and Norman's(n.yuan) advice.

trembre

  • Guest
Re: strange problem with events
« Reply #24 on: March 04, 2013, 11:03:52 PM »
It is, hence my confusion!  I'll have to dig out that code from my repository and compare it to yours.  While I got the point Tony and Norman were making at the time, I must have botched something else in the code... 

EDIT: After resurrecting that code turns out it does follow the same logic and does work.  :ugly:  Must've mixed up my dlls when I was testing - I'll get my coat.
« Last Edit: March 05, 2013, 07:39:27 PM by trembre »

sybold

  • Newt
  • Posts: 62
Re: strange problem with events
« Reply #25 on: March 28, 2013, 08:16:00 AM »
it has been a while, been very busy.

this is great, i now realize what i was doing wrong.

all is working again