1 Reply Latest reply on Sep 21, 2015 2:33 PM by Nick Sinno

    Listen for Filedropnotify event in C# addin

    Nick Sinno

      Hello all,

       

      Recently I have begun working on an addin for my company, to more easily distribute, and run a set of macros myself and a co-worker have been developing. One of these macros uses the Filedropnotify event. Using some of the stock event handlers from the SWaddin template, I set it into the "Ondocload" event, and it works great except for the fact that he has a pair of sendkeys("Esc") lines in his code. What end up happening is that the sendkeys is sent multiple times, causing the numlock key to turn off https://support.microsoft.com/en-us/kb/179987  I tried the "doevents" to no avail.

       

      My ideal solution, would be to really handle what his macro does, in the addin, using the filedropnotify event, or atleast fire a similar macro using that event in my addin, but I cannoot figure out how to listen for the filedropnotify event in my C# code!

       

      I do want to keep the sendkeys("Esc"), or replace it with something which will still close dialog boxes, but wont cause the bug, if I cant get the filedropnotify to work.

        • Re: Listen for Filedropnotify event in C# addin
          Nick Sinno

          It seems Ive finally figured it out! Im going to outline this some below, to hopefully help anyone else who has problems with this.

          2015 SOLIDWORKS API Help - SolidWorks.Interop.sldworks Namespace under DAssemblyDocEvents is where all your assembly events are listed.

           

          I took the EventHandling.cs from the SWAddin template, added a method:

           

                  public int FileDrop(string filename)

                  {

                         Method stuff here!!!

                      return 0;

                  }

           

          Then added this line into the "override public bool AttachEventHandlers()" method in that same file.

          doc.FileDropNotify += new DAssemblyDocEvents_FileDropNotifyEventHandler(FileDrop);

           

          doc is an assembly doc variable, defined earlier in the class.

           

                  AssemblyDoc doc;

                  doc = (AssemblyDoc)document;

           

          Bingo! It works.