i looked in the API help and it seems like a loop thru all the equations needed to get a certain equation
is there a function call to get an equation without runn thru a loop
You can end your loop once you got the desired equation OR if you know the equation index(position), then try following. 0 indicates the equation on number 1 from top.
Dim swApp As SldWorks.SldWorksDim swModel As SldWorks.ModelDoc2Dim swEquationMgr As SldWorks.EquationMgr Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swEquationMgr = swModel.GetEquationMgr Debug.Print swEquationMgr.Equation(0)End Sub
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swEquationMgr As SldWorks.EquationMgr
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swEquationMgr = swModel.GetEquationMgr
do you know why equation manager can return value but not the name of the equation
Chris, you should be able to get both name and values. This line swEquationMgr.Equation(0) should give you both name and values.
i know that. My question is i need strip the name out of the string of equation while I can get the value directly
Sorry no idea on that. So the only method I know is to strip out the name from the string.
2018 SOLIDWORKS API Help - ConvertToSystemValue Method (IUserUnit)
is this what you are looking for?
sorry Chris Champions, you are not making much sense.
please explain what you are trying to do.
if you don't want to loop through the equations, then write a function that does it for you, then call that function whenever you need it.
Public Function GetEquationIndex(Byval SomeArgument as string) as integer
Loop here to find your equation
Sorry, it's not clear to you while Deepak answered most of my questions
say I have a global variable
"Length" = 2.50 from equationManager.equation(index)
1) equationMangaer.Value (Index) returns value of 2.50. Is there a function call which can return the name "Length"? What I do is to use split and replace functions to strip the name "Length" from "Length" = 2.50
2) If I know the Variable name is "Legnth", is there a function call I can directly retrieve its value of 2.50 instead of going thru a loop and searching for it
1) Use the Left Method for removing the value.
Dim eqName As StringeqName = Left(equationManager.Equation(index), Len(equationManager.Equation(index)) - Len(equationMangaer.Value (Index)))
Dim eqName As String
eqName = Left(equationManager.Equation(index), Len(equationManager.Equation(index)) - Len(equationMangaer.Value (Index)))
You might need to add - 3 after the last Length to remove the spaces and equal sign, but I don't know exactly what each one outputs.
2) No, there is no function that I have found to do this
Thank you for confirming it, Matt
a SW API function call for this option would be helpful
too bad it’s not available
Yes, it very annoying. The equation manager i very frustrating to work with in general.
We use regular expressions to extract values and names
string eq = eqman
string pattern = @"""([^@]+)""\s*=\s*(.+$)";
Regex regex = new Regex(pattern, RegexOptions.Compiled);
MatchCollection m = regex.Matches(eq);
if (m.Count == 0 || m.Groups.Count < 3)
name = m.Groups.Value;
eqval = m.Groups.Value;
very nice. i love the Regex
great last name chris
Retrieving data ...