Equation Manager Error

Hi guys, I'm getting an error using equation manager.

I've defined a global variable called

"cost"="SW-Mass" * 5

In background I change values of specific quotas (DisplayDimension),

then without saving the model i call on it a

swModel.ForceRebuild(false);

Then, inside a for cycle I wanna read the new "cost" value,

'cause changing quotas results in chaning mass and so on, till cost variable:

for (int i=0; i < swEqnMgr.GetCount(); i++)

{

if (swEqnMgr.get_Equation(i).Contains("cost"))

return swEqnMgr.get_Value(i);

}

Ok, unpredictably this code sometimes works, sometimes crash,

returning 0 for get_Value and -1 for swEqnMgr.Status, a variable

saying that something went terribly wrong while executing the equation.

What am I missing with that? Many thanks.

SolidworksApi macros