I wrote this following iLogic code, but its rounding off the value and not changing tolerance type to -limits stacked
Hope someone can help
'
' Prompt the user to select a dimension
Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition
' Use a general selection method to pick a parameter
Dim oParameter As Parameter
Try
' Pick a parameter from the model
oParameter = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select a parameter")
Catch ex As Exception
MsgBox("Selection was canceled or invalid. Please select a valid parameter.")
Exit Sub
End Try
' Prompt user to enter upper and lower limits, with error handling for decimal input
Dim upperLimitStr As String = InputBox("Enter the upper limit for the dimension:", "Upper Limit")
Dim lowerLimitStr As String = InputBox("Enter the lower limit for the dimension:", "Lower Limit")
Dim upperLimit As Double
Dim lowerLimit As Double
' Convert string inputs to double, ensuring proper decimal handling
If Not Double.TryParse(upperLimitStr, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, upperLimit) Then
MsgBox("Invalid input for upper limit. Please enter a valid decimal number.", vbOKOnly + vbExclamation)
Exit Sub
End If
If Not Double.TryParse(lowerLimitStr, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, lowerLimit) Then
MsgBox("Invalid input for lower limit. Please enter a valid decimal number.", vbOKOnly + vbExclamation)
Exit Sub
End If
' Calculate the median value without rounding
Dim medianValue As Double = (upperLimit + lowerLimit) / 2
' Set the parameter to the median value
oParameter.Value = medianValue
' Inform the user of the new dimension value with six decimal places precision
MsgBox("The nominal dimension has been set to the median value: " & Format(medianValue, "0.######"))