Hi @brianA32ZM. That's a tough one. If you were dealing directly with a real Inventor API Parameter type object, and accessing its Parameter.Expression property, you always get a String, and the contents of that String will be exactly what you see in the Parameters dialog, in the Equation column, for that parameter. So, even if it is just a simple numerical value, with no equation, there will still be a numerical value, then a single space, then the abbreviated 'units' specifier text. In those cases, we can use the Conversion.Val(System.String) method to get just the leading numerical value, without the text that follows it. However, if it contains an equation, and that equation contains the names of other parameters, and you are wanting to replace the parameter names in it with numerical values, then end up with a Double type value, that's definitely a more complex situation. You would need a system that would be able to recognize the parameter names within the equation, and then get the numerical values of those parameters, and substitute those into the equation. At that point you are still working with an equation within a String though, and would then need to 'evaluate' that equation, to get a true numerical value from it. There are several tools for that type of task.
From the Inventor API Parameters object, we can use the following two methods:
Parameters.IsExpressionValid followed by Parameters.GetValueFromExpression, which would result in 'database units' value, instead of document or parameter units value, if they are different units.
We also have the same tools available from the Inventor API UnitsOfMeasure object.
UnitsOfMeasure.IsExpressionValid
UnitsOfMeasure.GetValueFromExpression
Edit: Actually, I just remembered that I recently created an iLogic rule for someone else on the forum recently, which goes through all parameters, looks within their Expression, and replaces any parameter names with the values of those parameters. I will post just the custom Function I created for that case below, in case it gives you some ideas for this case. It works with the entire Parameters collection though, because in order to recognize the parameter names, it starts by getting the names of all the parameters to a single collection. Then as it reviews individual Expression Strings, it checks if it 'Contains' any of those parameter names, and if so, gets the value of that parameter, and replaces its name with its numerical value. You would need to modify it to only effect one parameter at a time, instead of all parameters though.
Function ReplaceParamNamesInParamExpressions(oParams As Inventor.Parameters) As Boolean
'Design Intent: should return True only when changes have been made, and False otherwise
If oParams Is Nothing OrElse oParams.Count = 0 Then Return False
Dim bChanged As Boolean = False
Dim oAllParamNames As IEnumerable(Of String) = oParams.Cast(Of Inventor.Parameter).Select(Function(p) p.Name)
For Each oParam As Inventor.Parameter In oParams
Dim sExp As String = oParam.Expression
For Each sParamName As String In oAllParamNames
If Not sExp.Contains(sParamName) Then Continue For
Try
oParam.Expression.Replace(sParamName, oParams.Item(sParamName).Expression)
bChanged = True
Catch ex As Exception
Logger.Error(ex.Message)
End Try
Next 'sParamName
Next 'oParam
Return bChanged
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)