Author Topic: Need event handler help  (Read 7613 times)

0 Members and 1 Guest are viewing this topic.

Glenn R

  • Guest
Re: Need event handler help
« Reply #15 on: July 07, 2010, 04:09:30 PM »
Attach it to a post.

BillZndl

  • Guest
Re: Need event handler help
« Reply #16 on: July 07, 2010, 04:15:39 PM »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Need event handler help
« Reply #17 on: July 07, 2010, 06:33:08 PM »
BTY this "should" work from  a modeless dialog or palette as well,  load/unload using IExtensionApplication
Thanks. I'm just not sure how to handle this with "command methods".

as I noted in my comment, you would use something like

Code: [Select]

using Autodesk.AutoCAD.Runtime;
//
[assembly: CommandClass(typeof(CsMgdAcad1.Commands))]
[assembly: ExtensionApplication (typeof(CsMgdAcad1.Commands))]

namespace CsMgdAcad1
{

  public class Commands : Autodesk.AutoCAD.Runtime.IExtensionApplication
  {
    static DocEvents loader = new DocEvents();
    public void Initialize()
    {
      try
      {
        loader.Do();
      }
      catch(System.Exception ex)
      {
        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.
          MdiActiveDocument.Editor.WriteMessage(ex.Message);
      }
    }

    public void Terminate()
    {
      loader.Undo();
    }
  }
}
« Last Edit: July 07, 2010, 06:37:19 PM by Daniel »

BillZndl

  • Guest
Re: Need event handler help
« Reply #18 on: July 07, 2010, 09:27:39 PM »
BTY this "should" work from  a modeless dialog or palette as well,  load/unload using IExtensionApplication
Thanks. I'm just not sure how to handle this with "command methods".

as I noted in my comment, you would use something like


Thanks Dan,

Not doing programming full time and actually having a "day job",
I do plan on trying what you posted.
But it sometimes feels like trying to get a drink from a fire hose.  :laugh:

First, I'd like to find out why the example I tried,
which is basically the way Kean W. posted it here is not working.
Just seems funny that removing the commandxxxx events
would somehow disable the commandWillStart event handler.

And thanks all for the helpfulness and patience shown here.  :wink:












It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Need event handler help
« Reply #19 on: July 07, 2010, 09:44:42 PM »
The example the Kean posted is for a single document,  I assume that you need to create an instance of your command reactor class for each document, and you also need to manage these instances when documents are created and destroyed.  If you look at the sample I posted you will see two sets of reactor classes DocEvents and CmdEvents.  In DocEvents there is a dictionary Dictionary<Document, CmdEvents> where I track the CmdEvents instance with the Document instance I.e. when a new document is created, I can create a new instance of CmdEvents for that document and when its destroyed I can remove the instance.  :-)

BillZndl

  • Guest
Re: Need event handler help
« Reply #20 on: July 07, 2010, 10:13:31 PM »
The example the Kean posted is for a single document,  I assume that you need to create an instance of your command reactor class for each document, and you also need to manage these instances when documents are created and destroyed.  If you look at the sample I posted you will see two sets of reactor classes DocEvents and CmdEvents.  In DocEvents there is a dictionary Dictionary<Document, CmdEvents> where I track the CmdEvents instance with the Document instance I.e. when a new document is created, I can create a new instance of CmdEvents for that document and when its destroyed I can remove the instance.  :-)

I'm with ya.
And I think that's what I'm doing by first iterating any documents already open,
and second, through my "documentCreated" and "documentToBeDestroyed" handler.
Again, as a newbie, what I think isn't always the way it works.
But all this works perfectly until I remove the commandEnded events.
To me, the commandWillStart should still be there, notifying when a command is issued.   :pissed:


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Need event handler help
« Reply #21 on: July 08, 2010, 12:14:33 AM »
Just keep a reference to each of the event classes you create, so you can go back and turn items on/off.
I have updated my sample a bit to give finer control  :-)

Glenn R

  • Guest
Re: Need event handler help
« Reply #22 on: July 08, 2010, 04:44:59 AM »
Post a cut down project that exhibits the behaviour - the last one has too much other 'noise' to zero in on the issue.

BillZndl

  • Guest
Re: Need event handler help
« Reply #23 on: July 08, 2010, 07:16:29 AM »
Post a cut down project that exhibits the behaviour - the last one has too much other 'noise' to zero in on the issue.

Pruned it some more but there isn't too much more I can cut out without removing the form itself.  :?

Be sure to use the .dll in the bin/release folder,  then type "partmon" to invoke the form after netload.


BillZndl

  • Guest
Re: Need event handler help
« Reply #24 on: July 08, 2010, 10:16:23 AM »
FWIW:
If I remove the commandWillStart and add it again during the removeEventHandlers() call,
everything works as expected.
Just seems kinda Kludgy that I have to do that.

Code: [Select]
void removeEventHandlers()
        {
            try
            {
                AcadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nRemove command reactors.");

                AcadApp.DocumentManager.MdiActiveDocument.CommandCancelled -= new CommandEventHandler(MdiActiveDocument_CommandEnded);
                AcadApp.DocumentManager.MdiActiveDocument.CommandEnded -= new CommandEventHandler(MdiActiveDocument_CommandEnded);
                AcadApp.DocumentManager.MdiActiveDocument.CommandFailed -= new CommandEventHandler(MdiActiveDocument_CommandEnded);
                AcadApp.DocumentManager.MdiActiveDocument.Database.ObjectAppended -= new ObjectEventHandler(Database_ObjectAppended);
                [color=red]AcadApp.DocumentManager.MdiActiveDocument.CommandWillStart -= new CommandEventHandler(Document_CommandWillStart);
                AcadApp.DocumentManager.MdiActiveDocument.CommandWillStart += new CommandEventHandler(Document_CommandWillStart);[/color]            }
            catch (System.Exception ex)
            {
                AcadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.StackTrace.ToString());
            }
        }

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Need event handler help
« Reply #25 on: July 08, 2010, 10:19:59 AM »

BillZndl

  • Guest
Re: Need event handler help
« Reply #26 on: July 08, 2010, 10:31:54 AM »
... Kludgy ....

My middle name  :laugh:

That's good enough for me, I can move on now. :)


Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Need event handler help
« Reply #27 on: July 08, 2010, 10:40:19 AM »
Hi Bill,
As usual I'm a bit late....just wanted to add a note to what Glenn was referring to 'trimming' the project. All of the stuff in there for the Caddzone sample is not needed for your example and is a huge part of the 'fluff'. I just deleted all of that here and it builds fine without it.

Second, I wonder if this is a 2006 issue.... I built the project using 2010 references and it works as I think you expect it to (all groups get the date in the description). Even when starting a new drawing.

I now leave you back in the hands of those far more qualified than I, Daniel & Glenn.

BillZndl

  • Guest
Re: Need event handler help
« Reply #28 on: July 08, 2010, 11:05:19 AM »
Hi Jeff!

Caddzone sample?
I guess I wasn't aware that was in there.
I just copied my project over to another folder and butchered it in VS,
so that folder must've got dragged over accidentally.  :oops:

Oh,well.
Anyway, good to hear from you again,
hope all is well on your side of the world.  :-D