2 Replies Latest reply on Apr 11, 2013 2:38 PM by Ross Doyle

    Alter Equations Using API

    Ross Doyle

      Hello,

       

      I have had some success adding equations to my parts and assemblies using the API but I am trying to now alter some of the equations to a new value for existing parts where the equation already exists as a global variable.  I have been unable to find any documentation on the way to do this.  I am sure it is through the IEquationMgr interface but I am not sure which function.

       

      When I try to rewrite over the existing equation through this line where beltwidth is a predetermined integer:

       

      swEqMgr.Equation(0) = """belt""=" & BeltWidth

       

      Then the result in the model tree is "belt"=???

       

      Does anyone the correct function for changing the global variable or any suggestions on a better way to tackle this problem?

       

      Thanks,

      Ross

        • Re: Alter Equations Using API
          Patrick Rainsberry

          I have done this in the past by simply deleting the existing equation and replacing it.  It is the only way I can figure to do it with IEquationMgr.

           

          As long as you know the index of global variable in EquationMgr it is pretty easy to replace.  In some cases I simply delete all global variable equations set the new values and then re-write the text strings for the equation mgr.

            • Re: Alter Equations Using API
              Ross Doyle

              Thanks Patrick!  So simple, yet effective.  I am sure it gets more complicated if there are multiple global variables but in my case there is only 1 that drives a few equations so it seems to work seamlessly to use your method.

               

              For reference for anyone else needing help with this method here is the code that I used:

               

              Dim swEqMgr As SldWorks.EquationMgr

                      swEqMgr = swDoc.GetEquationMgr

                      swEqMgr.Delete(0)

                      swEqMgr.Add2(0, """belt""=" & beltwidthint, True)

                      swEqMgr.EvaluateAll()

                      swDoc.EditRebuild3()