This is how you do it:
Code: Select all
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
Dim swDim As Dimension
Dim swTol As SldWorks.DimensionTolerance
Set swDim = swApp.ActiveDoc.Parameter("D1@LimitDistance1") 'You gotta figure out how to get the pointer to your dimension
Set swTol = swDim.Tolerance
Dim DesiredMaxValue As Double
Dim DesiredMinValue As Double
DesiredMaxValue = 0.05 'Meters
DesiredMinValue = 0
Debug.Print swTol.Type
Dim theVal As Double
swTol.GetMaxValue2 theVal
Debug.Print "Current max: " & theVal + swDim.SystemValue
swTol.GetMinValue2 theVal
Debug.Print "Current min: " & swDim.SystemValue + theVal
Debug.Print swTol.SetValues2(DesiredMinValue - swDim.SystemValue, DesiredMaxValue - swDim.SystemValue, swSetValue_InThisConfiguration, "")
End Sub
You should be able to set this per configuration using swSetValue_InSpecifiedConfigurations in the SetValues2 line. However, I was unable to get this to work at all. So you'll have to actually activate each config you want to change it in.
Also, the values you have to set are plus and minus from the current value of the dimension, wherever it's sitting in its range. So, for example, if you're currently sitting at 32mm, and you want a range of 30 to 40, you need to use -2 for the lower value and 8 for the upper. That's what the calculations using swDim.SystemValue are for.
Another caveat: if you are changing the range such that the current value now lies outside the new range (like you're at 32 and you want a range from 40 to 50), you will also need to set the dimension value to a number inside that range. Otherwise, you'll get a rebuild error.