AnsweredAssumed Answered

Disable/Enable Equations - swEqnMgr.Disabled(i) incorrect returns

Question asked by B. Van Tetrode on May 3, 2017
Latest reply on Feb 28, 2018 by B. Van Tetrode

I'm trying to disable and enable multiple equations using a Macro and I'm running into 3 problems.

 

I'm using a modified version of the following example program to clarify the problems:

http://help.solidworks.com/2017/english/api/sldworksapi/Disable_Equation_Example_VB.htm

Disabled Property (IEquationMgr)

http://help.solidworks.com/2017/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IEquationMgr~Disabled.html

    Function:              Gets or sets whether to disable the specified equation in the model.
     Property Value:     True to disable the specified equation, false to not

 

 

Problem 1 - incorrect swEqnMgr.Disabled(i) get values:

swEqnMgr.Disabled(i) should get the disabled state of an equation, but it gets incorrect values of equations greater than i=0.

 

---------------------------------------------

When running the macro with a part (see attachment) with all equations enabled:

Macro:

 

Sub status()
     Dim swApp As SldWorks.SldWorks
     Dim swModel As SldWorks.ModelDoc2
     Dim swEqnMgr  As SldWorks.EquationMgr
     Dim i As Long
     Dim count As Long
     Dim disabledCount As Long
     Dim totalCount As Long

     Set swApp = Application.SldWorks
     Set swModel = swApp.ActiveDoc
     Set swEqnMgr = swModel.GetEquationMgr

     count = swEqnMgr.GetCount
     disabledCount = swEqnMgr.GetDisabledEquationCount
     totalCount = count + disabledCount

     Debug.Print "Number of equations in part = " & count
     For i = 0 To totalCount - 1
         Debug.Print "  Eqn(" & i & ")  " & swEqnMgr.Disabled(i) & " = " & swEqnMgr.Equation(i)
     Next i
End Sub

Returns:

 

Number of equations in part = 5
  Eqn(0)  False = "1"= 100
  Eqn(1)  True = "2"= 200     < incorrect value True     must be   False
  Eqn(2)  True = "3"= 20       < incorrect value True     must be   False
  Eqn(3)  True = "4"= 10       < incorrect value True     must be   False
  Eqn(4)  True = "5"= 4         < incorrect value True     must be   False

---------------------------------------------

 

 

 

 

Problem 2 - enabling correct equation:

After disabling equations (by API or manual) swEqnMgr.Equation(i) returns nothing for disabled equations.

So when there're multiple equations disabled, there's no way to determine the correct equation number for re-enabling a specific equation.

 

---------------------------------------------

Running the above Macro again when equations Eqn(3) and Eqn(4) disabled:

 

Returns:

 

Number of equations in part = 3
   Eqn(0)  False = "1"= 100
   Eqn(1)  True = "2"= 200     
< incorrect value True     must be   False
  Eqn(2)  True = "5"= 40       
< incorrect value True     must be   False
  Eqn(3)  True = 
                  < unknown equation
   Eqn(4)  True = 
                  < unknown equation

---------------------------------------------

 

 

 

Problem 3 - enabling equation:

Enabling equations is only possible using equation numbers 0 to swEqnMgr.GetDisabledEquationCount

Hereby equation numbers are mixed up with equation numbers of enabled equations.

Attachments

Outcomes