4 Replies Latest reply on Nov 10, 2014 11:35 AM by Lois Claracq

    Debug vb.net add-in without restarting solidworks

    Lois Claracq

      Hello

       

      Is there a way to build a vb.net add-in without restarting solidworks.

       

      Currently if Solidworks is started I get "The process cannot access the file '......dll' because it is being used by another process."

       

      Basically my add-in is a toolbar with multiple separate "macro". I'm trying to find a way to quickly debug each "macro" without having to restart Solidworks each time I make a change.

       

      Any advice or example is welcome

        • Re: Debug vb.net add-in without restarting solidworks
          Stefan Wozniak

          You can try to uncheck add-in on addins list in SWX and then try to rebuild addin and then check it again. But I'm just guessing.

          • Re: Debug vb.net add-in without restarting solidworks
            Seth Ruhan

            Hi,

             

            I find that the easiest way when it comes to the actually code debug, is top do it via a VSTA macro.

            Since the code is .net as well. You can directly add Class\Modules into the vsta project as a link (do this by add existing command, then select the arrow next to the add button) .

            Then in the main sub in the VSTA macro make the required calls to the imported calls.

             

            Any thing to do with the Interface ie add in features, has to be done via the good old restart program\Build

            TempMacro.jpg

            1 person found this helpful
              • Re: Debug vb.net add-in without restarting solidworks
                Lois Claracq

                Thanks Seth, that's interesting.

                 

                In case someone is interested here is the way I found.

                 

                I went with 2 VS solution and shared VS project. Here is the basic setup

                • Solution : swAddin (this one can only be built when Solidworks is not running)
                  • Project : Class swAddin (add reference to each macro , add reference > Solution > Project > Each macro)
                  • Project : Class/module Macro 1
                  • Project : Class/module Macro 2 ...
                • Solution : Debugger (this one can be build anytime)
                  • Project : Class debugger (add reference to each macro , add reference > Solution > Project > Each macro)
                  • Project : Class/module Macro 1 (shared, add > Existing project ...)
                  • Project : Class/module Macro 2 (shared, add > Existing project ...)

                 

                The main advantage is I can debug my macros line by line directly from visual studio. Although I'm not sure if the way I get the Solidworks object is efficient and if I should add some kind of startup/cleanup routine to avoid memory leak. And I'm not sure if it's related but Solidworks often stays in the task manager even after I close it.

                 

                I noticed in VSTA macro there is a SwMacroSetup and SwMacroCleanup from SolidWorks.Proxy.Sldworks.dll but I could not find any information about those commands

                 

                In case someone is interested or can suggest improvement :

                • Here is the code to launch a macro from the Class swAddin

                     Imports MacroClassXXXXXXX

                        Dim MacroClassObj As Object = New MacroClassXXXXXXX()

                        MacroClassObj.main(SwApp)

                 

                • Here is the code in Class debugger :

                Imports SolidWorks.Interop.sldworks

                Imports MacroClassXXXXXXX

                 

                Module Module1

                 

                    Sub Main()

                        'Manually get Solidworks Object  for debugging purpose

                        Dim swApp As SldWorks = CreateObject("Sldworks.Application")

                 

                        If swApp Is Nothing Then

                            Exit Sub

                        Else

                            swApp.Visible = True

                        End If

                 

                        Dim MacroClassObj As Object = New MacroClassXXXXXXX()

                        MacroClassObj.main(swApp)

                    End Sub

                End Module