AnsweredAssumed Answered

Can't programmatically set equation

Question asked by Richard K. on Nov 15, 2017
Latest reply on Nov 15, 2017 by Nilesh Patel

For the life of me I can't figure out how to programmatically modify my equations via VBA. I've tried:

  • Assignment to the EquationManager.Equation property
  • Using the EquationManager.SetEquationAndConfigurationOption() function (with swAllConfiguration, swThisConfiguration and even swSpecifyConfiguration)

 

Here's an example, from the Debug window.  I can't even assign the same value back that currently exists.

 

?eqMgr.Equation(0) = chr(34) & "SegmentLength" & chr(34) & " = ( 1 / 1 ) * 1in"

True

 

?eqMgr.SetEquationAndConfigurationOption(0, chr(34) & "SegmentLength" & chr(34) & " = ( 1 / 1 ) * 1in", swThisConfiguration, Empty)

-1

 

I've also tried many variations of this, like using "(1 / 2) * 1in" and even simpler values like just:

eqMgr.Equation(0) = chr(34) & "SegmentLength" & chr(34) & "= 10"

 

Note chr(34) is the double quotation mark (I find the style above easier to read than double-double quotes) and the ampersand (&) is the string concatenation character (more foolproof than using "+" operator).

 

eqMgr is a reference to my part's equation manager, retrieved like so:

 

Set swApp = Application.SldWorks

Set part = swApp.ActiveDoc

Set eqMgr = part.GetEquationMgr()

 

I figure there must be something up with the model.  I can change the equation just fine by hand using Solidworks' Equation Editor.

Outcomes