4 Replies Latest reply on Mar 9, 2017 8:29 PM by Bin Huang

    how to run code by start addin

    Bin Huang

      Hi all

       

           I want to write a code to  auto run when i startup a specified add-in ,such as inspection add in . do you how to use sw API event.

        • Re: how to run code by start addin
          Peter Brinkhuis

          Are you using the Addin template from Solidworks? There is a ConnectedToSolidWorks method that gets called after the add-in is connected.

            • Re: how to run code by start addin
              Bin Huang

              yes, i am using Addin template from solidworks. Now ,i want to write a addin to catch the state of other addin by solidworks events.

              for example

                  

                       I want to write a code to  implement when i load the solidworks simulation addin ,solidworks can notify me "it is load" or other action.

               

              can you know how to do it .

               

              I know that the  DSldWorksEvents_DocumentLoadNotify2EventHandler Delegate (SolidWorks.Interop.sldworks)  can  implement the code autorun when I load a document, but I do not know the code can be auto run when i load a addin(such as SOLIDWORKS Simulation or SOLIDWORKS Flow Simulation).

                • Re: how to run code by start addin
                  Jim Sculley

                  The SOLIDWORKS API does not have any events associated with add-in loading.  What you want to do can be done using other tools such as the Microsoft Trace Event library to detect when DLL files are loaded and then compare them to a list of paths of known add-in DLL files, possibly extracted programmatically from information in the registry.

                   

                  Can this be done?  Absolutely.


                  Should it be done?  Probably not.

                   

                  Why do you want to do this?  Perhaps there is a better approach.

                    • Re: how to run code by start addin
                      Bin Huang

                      Why to do this ?

                      Because my customer use the sw inspection addin to automatic balloon in the drawing.  and they want to prevent the addin start again  when the drawing has been ballooned.

                      then

                           

                      I know that to use the  DSldWorksEvents_DocumentLoadNotify2EventHandler Delegate (SolidWorks.Interop.sldworks) to check the drawings when the drawing loading.

                       

                      but if the drawing has been load, i do not how to prevent the customer to start the addin when the drawings has been balloon.

                        

                         do you have any idea?

                      or can you give me a example of microsoft trace event , I haven't written like this before