Hi Team,
I am looking for code to set the tolerance precision -1 while converting units from Inch to metric?
- If inch has 03 level of precision then while converting the precision set to -1 i.e. 02 Level.
Thanks for the support in advance! 🙂
Hi Team,
I am looking for code to set the tolerance precision -1 while converting units from Inch to metric?
Thanks for the support in advance! 🙂
In the document properties set the appropriate decimal places for primary and dual for dimensions.
That would depend on if you changed the decimal precision manually or kept it at "Use Document Property" setting when adding the tolerance. If you manually changed it then the precision would stay between unit conversion
Thanks for the response but can we do this through VBA?
'by John R. Sitek
'04-JUL-2025
'This macro sets primary units to metric if currently imperial
Option Explicit
Sub Main()
Dim swApplication As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim vbPrimaryUnits As String
Set swApplication = Application.SldWorks
Set swModel = swApplication.ActiveDoc
'Change units to metric if currently imperial
If swModel.GetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swUnitsLinear) = swINCHES Then
swModel.SetUserPreferenceIntegerValue swUnitSystem, swUnitSystem_Custom
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swUnitSystem, 4
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swUnitsLinear, swLengthUnit_e.swMM
vbPrimaryUnits = swModel.GetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces)
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, vbPrimaryUnits - 1
End If
End Sub
I think you are referring to Document Primary Dimension Precision and Document Primary Dimension Tolerance Precision. I added those below.
'by John R. Sitek
'04-JUL-2025
'This macro sets primary units to metric if currently imperial
Option Explicit
Sub Main()
Dim swApplication As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim vbPrimaryUnits As String
Dim vbSecondaryUnits As String
Set swApplication = Application.SldWorks
Set swModel = swApplication.ActiveDoc
'Change units to metric if currently imperial
If swModel.GetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swUnitsLinear) = swINCHES Then
'Set primary to metric
swModel.SetUserPreferenceIntegerValue swUnitSystem, swUnitSystem_Custom
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swUnitSystem, 4
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swUnitsLinear, swLengthUnit_e.swMM
vbPrimaryUnits = swModel.GetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces)
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces, vbPrimaryUnits - 1
'Set Dimension Precision and Tolerance
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swDetailingLinearDimPrecision, vbPrimaryUnits - 1
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swDetailingAltLinearTolPrecision, vbPrimaryUnits - 1
'Set secondary to imperial
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swUnitsDualLinear, swLengthUnit_e.swINCHES
vbSecondaryUnits = swModel.GetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swUnitsDualLinearDecimalPlaces)
swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swUnitsDualLinearDecimalPlaces, vbSecondaryUnits + 1
End If
End Sub