Hi Guys,

I have a little problem with the equation manager Add2 function.

when I delete all the equation that have instr "TEST" then try to re add thoses equations (exactly the same equation that was delete previously),I get an return value of -1 on the add2 function but the equation is still added.

I debug print 40 equation at the beginning, then after delete the TEST equation I debug.print 27 and after all TEST equation re added I debug print 40 ...But I get a -1 on all add2 function...

Why am I getting a false error? and How can I prevent it?

One again Thank you for your time and Knowledge

Yannick

Here is My code Snippet:

'file is loaded silently

Dim EquatMgr As SldWorks.EquationMgr = swModelDoc.GetEquationMgr

Dim EquaCount As Integer = EquatMgr.GetCount

Debug.Print("Equation Count before delete : " & EquaCount) '<--------------------------------Equation Count before delete : 40

''check if equation already exist and if yes delete it

Dim RetVal As Integer = Nothing

Dim sEquat(EquaCount - 1) As String

'Keep internal equation ,delete TEST equation

For I = 0 To EquaCount - 1

If InStr(EquatMgr.Equation(I), "TEST") > 0 Then

RetVal = EquatMgr.Delete(I)

If RetVal = -1 Then

msgBox("An error occured while suppressing equation : " & EquatMgr.Equation(I))

End If

End If

Next

EquaCount = EquatMgr.GetCount

Debug.Print("Equation Count after delete TEST equation : " & EquaCount) '<--------------------------------Equation Count after delete TEST equation : 27

Debug.Print("TEST Equation to be added : " & EquationDict.Count) '<--------------------------------TEST Equation to be added : 13

For Each equation In EquationDict.Values

RetVal = EquatMgr.Add2(-1, equation, False) '<--------------------------------HERE IS THE RetVal = -1 but the equation is still added

If RetVal = -1 Then

MsgBox("An error occured while addin equation : " & equation )

End If

Next

Debug.Print("Equation Count after all equation added : " & EquatMgr.GetCount) '<--------------------------------Equation Count after all equation added : 40

This is a bug in SolidWorks 2013, though I don't think SolidWorks API support ever created an SPR for it. Anyway, the workaround is to set the last argument in IEquationMgr::Add2 to True rather than False. Or you can start using a newer version of SolidWorks.

Keith

SolidWorks API Training and Services