PrimaryUnitsPrecision Example

Using Programming Languages other than VBA

Sub Example_PrimaryUnitsPrecision()
   ' This example creates an aligned dimension in model space and
   ' uses PrimaryUnitsPrecision to allow the user to change
   ' the number of decimal places displayed for the primary units and tolerance
   ' units of the dimension.

	Dim dimObj As AcadDimAligned
	Dim point1(0 To 2) As Double, point2(0 To 2) As Double
	Dim location(0 To 2) As Double
	Dim oldPrecision As String, newPrecision As String

	' Define the dimension
	point1(0) = 0: point1(1) = 5: point1(2) = 0
	point2(0) = 5.12345678: point2(1) = 5: point2(2) = 0
	location(0) = 5: location(1) = 7: location(2) = 0

	' Create an aligned dimension object in model space
	Set dimObj = ThisDrawing.ModelSpace.AddDimAligned(point1, point2, location)

	' Enable and setup tolerance display
	dimObj.ToleranceDisplay = acTolSymmetrical
	dimObj.ToleranceLowerLimit = -0.0001
	dimObj.ToleranceUpperLimit = 0.005

	ThisDrawing.Application.ZoomAll

	' Store old precision value as default for input box
	oldPrecision = dimObj.PrimaryUnitsPrecision

	' Allow the user to change the precision for the dimension and dimension tolerance
	newPrecision = InputBox("Enter a new precision for the dimension and tolerances.  The value must range from 0 to 8.", "Change Precision", oldPrecision)

	Select Case newPrecision
		Case 0: newPrecision = acDimPrecisionZero
		Case 1: newPrecision = acDimPrecisionOne
		Case 2: newPrecision = acDimPrecisionTwo
		Case 3: newPrecision = acDimPrecisionThree
		Case 4: newPrecision = acDimPrecisionFour
		Case 5: newPrecision = acDimPrecisionFive
		Case 6: newPrecision = acDimPrecisionSix
		Case 7: newPrecision = acDimPrecisionSeven
		Case 8: newPrecision = acDimPrecisionEight
		Case Else
			MsgBox "The precision has not been changed."
			Exit Sub
	End Select

	' Change the dimension and tolerance precision
	dimObj.TolerancePrecision = newPrecision
	dimObj.PrimaryUnitsPrecision = newPrecision

	ThisDrawing.Regen acAllViewports

	' Read back and display the dimension and dimension tolerance precision
	newPrecision = dimObj.PrimaryUnitsPrecision
	MsgBox "The precision has been set to " & newPrecision & " decimal places"
End Sub

 

   Comments?