Dimensions. Load settings from customer defaults.

Hello

Here’s the code that applies customer defaults settings to the angular dimensions. The code acts weirdly. The dimension tolerance disappears, but when I open dimension settings the tolerance is still there. The other thing is that the tolerance text settings (color, font and height) is not inherited form customer defaults but from part drafting preferences.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Annotations

Module NX_cd

Dim s As Session = Session.GetSession()
Dim ui As UI = UI.GetUI()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = s.Parts.Work
Dim myDim As Annotations.Dimension
Dim lw As ListingWindow = s.ListingWindow

Sub Main()

For Each myDim As Annotations.Dimension In workPart.Dimensions

Dim dimname1 As String = Nothing

dimname1 = myDim.ToString()
lw.Open()
If dimname1.Contains("Angular") = True Then

Dim AngularDimension1 As Annotations.AngularDimension = myDim
Dim angularTolerance1 As Annotations.AngularTolerance
Dim upperToleranceDEG As Annotations.Value
Dim lowerToleranceDEG As Annotations.Value
Dim upItemValue As Double
Dim lowItemValue As Double
Dim toltype As Annotations.ToleranceType

angularTolerance1 = AngularDimension1.GetTolerance()

toltype = angularTolerance1.ToleranceType

upItemValue = angularTolerance1.GetUpperToleranceDegrees.ItemValue
lowItemValue = angularTolerance1.GetLowerToleranceDegrees.ItemValue

Dim objects1(0) As NXOpen.DisplayableObject
objects1(0) = myDim
Dim linearDimensionBuilder1 As Annotations.AngularDimensionBuilder
linearDimensionBuilder1 = workPart.Dimensions.CreateAngularDimensionBuilder(objects1(0))
linearDimensionBuilder1.Style.InheritSettingsFromPreferences()
linearDimensionBuilder1.Style.InheritSettingsFromCustomerDefault()
linearDimensionBuilder1.Style.InheritSettingsFromPreferences()
linearDimensionBuilder1.Style.InheritSettingsFromCustomerDefault()
Dim nXObject1 As NXObject
nXObject1 = linearDimensionBuilder1.Commit()
linearDimensionBuilder1.Destroy()

angularTolerance1.ToleranceType = Annotations.ToleranceType.None
angularTolerance1.ToleranceType = toltype

upperToleranceDEG.ItemValue = upItemValue
upperToleranceDEG.ValuePrecision = 2
angularTolerance1.SetUpperToleranceDegrees(upperToleranceDEG)

lowerToleranceDEG.ItemValue = lowItemValue
lowerToleranceDEG.ValuePrecision = 2
angularTolerance1.SetLowerToleranceDegrees(lowerToleranceDEG)

AngularDimension1.SetTolerance(angularTolerance1)
End If
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module

If you call the .RedisplayObject method of the dimension after setting the preferences, the tolerance value should display onscreen and when editing the dimension.

However, the font may still be incorrect; I think it may be a bug in NX. When I run the code, I have the opposite problem: the font for the tolerance is correct, but the dimension font changes to blockfont (I have Arial unicode set for dimension and tolerance font in both the part preferences and customer defaults). I would suggest submitting the issue to GTAC to see if this is a bug or if some other method needs to be called to have the desired effect.