change fractional precision of a linear dimension
I would like to be able, on an individual basis, to be able to override the fractional precision of a linear dimension. (From 1/16" to 1/32").
the code "dim.Obj.PrimaryUnitsPrecision = acDimPrecisionFive" doesn't seem to make any difference. Is there a different object I should be using?
Thanks
Re: change fractional precision of a linear dimension
"dim.Obj" Is that a typo? Can you show your code. Go to the Advanced editor and use the # code tags.
Re: change fractional precision of a linear dimension
Yes the dim.Obj was a typo. This is the code I am trying to use. The "If" statement was what I added to attempt to change the fractional precision.
Code:
Public Sub DimAligned(DimX1, DimY1, DimX2, DimY2, DimLX, DimLY, DimText, TRot, Lsf, DimPrec)
Dim Pnt1(0 To 2) As Double
Dim Pnt2(0 To 2) As Double
Dim TextLoc(0 To 2) As Double
Dim dimObj As AcadDimAligned
Dim DimStyle As AcadDimStyle
Pnt1(0) = DimX1
Pnt1(1) = DimY1
Pnt1(2) = 0
Pnt2(0) = DimX2
Pnt2(1) = DimY2
Pnt2(2) = 0
TextLoc(0) = DimLX
TextLoc(1) = DimLY
TextLoc(2) = 0
Set DimStyle = ThisDrawing.DimStyles("cti standard$0")
ThisDrawing.ActiveDimStyle = DimStyle
Set dimObj = ThisDrawing.ModelSpace.AddDimAligned(Pnt1, Pnt2, TextLoc)
dimObj.TextOverride = DimText
dimObj.TextRotation = TRot
dimObj.LinearScaleFactor = Lsf
dimObj.VerticalTextPosition = acAbove
If DimPrec <> "" Then
dimObj.PrimaryUnitsPrecision = acDimPrecisionSix
End If
ThisDrawing.Regen acAllViewports
dimObj.Update
End Sub
Re: change fractional precision of a linear dimension
Your DimPrec comparison is wrong. Here is a cleaned up version.
However, it's not recommended to be adding a bunch of dim style overrides. It would be better to create a dim style with the precision you want and then use the dim's StyleName property to set the style.
Code:
Public Sub dimTest()
MyDimAligned 1, 1, 0, 0, 0, 0, 0
End Sub
Public Sub MyDimAligned(DimX1 As Double, DimY1 As Double, DimX2 As Double, _
DimY2 As Double, DimLX As Double, DimLY As Double, _
TRot As Double, Optional DimText As String, _
Optional Lsf As Double, Optional DimPrec As Integer)
' If you don't specify the data type, Variant is assumed.
' Use the Optional keyword when applicable. They must be at the end.
' Don't name variables the same as other library names,
' e.g. DimAligned and DimStyle are AutoCAD library names.
Dim Pnt1(0 To 2) As Double
Dim Pnt2(0 To 2) As Double
Dim TextLoc(0 To 2) As Double
Dim dimObj As AcadDimAligned
Dim oDimStyle As AcadDimStyle
Dim DimStyleLSF As Double
Pnt1(0) = DimX1
Pnt1(1) = DimY1
Pnt1(2) = 0
Pnt2(0) = DimX2
Pnt2(1) = DimY2
Pnt2(2) = 0
TextLoc(0) = DimLX
TextLoc(1) = DimLY
TextLoc(2) = 0
Set oDimStyle = ThisDrawing.DimStyles("standard")
ThisDrawing.ActiveDimStyle = oDimStyle
DimStyleLSF = ThisDrawing.GetVariable("DIMLFAC")
Set dimObj = ThisDrawing.ModelSpace.AddDimAligned(Pnt1, Pnt2, TextLoc)
With dimObj
If DimText <> "" Then .TextOverride = DimText
.TextRotation = TRot
If Lsf <> DimStyleLSF And Lsf <> 0 Then .LinearScaleFactor = Lsf
.VerticalTextPosition = acAbove
If DimPrec <> acDimPrecisionSix Then .PrimaryUnitsPrecision = acDimPrecisionSix
.Update
End With
ThisDrawing.Regen acAllViewports
End Sub
Re: change fractional precision of a linear dimension
Thanks, It is doing exactly what I wanted it to do.