10 Replies Latest reply on Jan 8, 2016 7:31 AM by Willem Van Opstal

    Macro change global variable

    Willem Van Opstal

      Hi all,

      I think it's really simple, but can't get it to work. Just stepped into the world of macro's.

      I downloaded and edited a few examples and wish to make them work within my models. I now created a user form to change dimensions successfully.

      What I can't get to work, is changing global variables. What line of codes do I have to insert?


      For changing the dimensions I use a variable from the userform and the following line of code:


      boolstatus=Part.Extension.SelectByID2("name@sketch@location","DIMENSION", xx,xx,xx....)

      Part.Parameter("name@sketch").SystemValue = dblVariable


      In this case, 'Part' is the active document.

      Pretty simple and straightforward to me. Is there any simple line of code to change Global variables within the equations manager?


        • Re: Macro change global variable
          Paul Churm

          Hi Willem,


          You can use an example like this to itterate over all the Global Variables you have.


          Option Explicit


          Sub main()


              Dim swApp                   As SldWorks.SldWorks

              Dim swModel                 As SldWorks.ModelDoc2

              Dim swEqnMgr                As SldWorks.EquationMgr

              Dim i                       As Long

              Dim nCount                  As Long

              Dim bRet                    As Boolean


              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swEqnMgr = swModel.GetEquationMgr


              Debug.Print "File = " & swModel.GetPathName

              Debug.Print "  Status = " & swEqnMgr.Status


              nCount = swEqnMgr.GetCount


              For i = 0 To nCount - 1


                  Debug.Print "  Eqn(" & i & ")  = " & swEqnMgr.Equation(i)

                  Debug.Print "    Value  = " & swEqnMgr.Value(i)

                  Debug.Print "    Supp   = " & swEqnMgr.Suppression(i)


              Next i


          End Sub


          Hope this helps to get you started.



          • Re: Macro change global variable
            Deepak Gupta

            Try these codes


            Option Explicit

            Sub main()

                Dim SwApp           As SldWorks.SldWorks

                Dim Part            As SldWorks.ModelDoc2

                Dim swEquationMgr   As SldWorks.EquationMgr


                Set SwApp = Application.SldWorks

                Set Part = SwApp.ActiveDoc

                Set swEquationMgr = Part.GetEquationMgr

                'swEquationMgr.SetEquationAndConfigurationOption 0, """Global Variable Name here"" = Required value", swAllConfiguration, Empty

                swEquationMgr.SetEquationAndConfigurationOption 0, """A"" = 5", swAllConfiguration, Empty

            End Sub