1 Reply Latest reply on Nov 17, 2014 8:21 PM by Francois Racine

    How to access swApp object from userform

    Lois Claracq

      I'm a bit confused on how to use the swApp object from inside my userform.


      Here is my setup

      • MainClass.VB

          Public Sub main(swApp As SldWorks)  'swApp is passed initially by the swAddin class


              Dim swModel As ModelDoc2

              swModel = swApp.ActiveDoc


      'do things@



          End sub


      The problem is once Dialog2 is shown none of the control inside have access to swApp.


      What would be the proper way to access the swApp object without closing the form ?



        • Re: How to access swApp object from userform
          Francois Racine

          The easiest way is by adding a module file to your code. When a variable is declared as public in a module, it is visible in the whole project. Having very public stuff is not a good habit, but for swApp, which always has the same value, I would say it is not that bad.


          Module Global

               Public swApp as Sldworks.SldWorks

          End Module


          Then, in your addin class, just assign using Global.swApp = TheSWAppVariableYouHaveInYourClass


          Hope this helps!