Adding/Editting tolerances and precision

I was able to find and modify a journal for changing the tolerance of a dimension and was able to modify it for my needs. The problem is it only works for dimensions that have already been placed. If I try to use the journal while in the rapid dimension command I get the following error.

"NXOpen.NXException: Cannot lock the UI in it's current state
at NXOpen.Selection.SelectTaggedObject(String message, String title, SelectionScope scope, SelectionAxtion action, Boolean includeFeatures, Boolean keepHighlighted, MaskTripple[]maskArray, TaggedObject, Point3d_Cursor)
at EditTolerance.Select_dim(NXObject_obj) in C:\(file location)\journal.vb:line 82
at EditTolerance.Main() in C:\(file location)\journal.vb:line 19

Below is the journal I am using, this is in NX9. I am new to journaling and any help would be appreciated!

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

Module EditTolerance
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
Sub Main()
Dim selecteddim As NXObject = Nothing
Dim response1 As Selection.Response = Selection.Response.Cancel
start1:
response1 = Select_dim(selecteddim)
If response1 = Selection.Response.Cancel Then GoTo end1
EditDimensionTolerance(selecteddim)
GoTo start1
end1:
End Sub
' ----------------------------------------------
' sub to edit tolerance
' ----------------------------------------------
Sub EditDimensionTolerance(ByVal selecteddim As NXObject)
Dim dimname1 As String = selecteddim.ToString
If dimname1.Contains("Radius") = True Then
Dim radialDimensionBuilder1 As Annotations.RadialDimensionBuilder
radialDimensionBuilder1 = workPart.Dimensions.CreateRadialDimensionBuilder(selecteddim)
radialDimensionBuilder1.Style.DimensionStyle.ToleranceType = Annotations.ToleranceType.BilateralOneLine
radialDimensionBuilder1.Style.DimensionStyle.UpperToleranceEnglish = 0.001
radialDimensionBuilder1.Style.DimensionStyle.ToleranceValuePrecision = 3
Dim nXObject1 As NXObject
nXObject1 = radialDimensionBuilder1.Commit()
Elseif dimname1.Contains("Diameter") = True Then
Dim radialDimensionBuilder1 As Annotations.RadialDimensionBuilder
radialDimensionBuilder1 = workPart.Dimensions.CreateRadialDimensionBuilder(selecteddim)
radialDimensionBuilder1.Style.DimensionStyle.ToleranceType = Annotations.ToleranceType.BilateralOneLine
radialDimensionBuilder1.Style.DimensionStyle.UpperToleranceEnglish = 0.001
radialDimensionBuilder1.Style.DimensionStyle.ToleranceValuePrecision = 3
Dim nXObject1 As NXObject
nXObject1 = radialDimensionBuilder1.Commit()
Else
Dim linearDimensionBuilder1 As Annotations.LinearDimensionBuilder
linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(selecteddim)
linearDimensionBuilder1.Style.DimensionStyle.ToleranceType = Annotations.ToleranceType.BilateralOneLine
linearDimensionBuilder1.Style.DimensionStyle.UpperToleranceEnglish = 0.001
linearDimensionBuilder1.Style.DimensionStyle.ToleranceValuePrecision = 3
Dim nXObject1 As NXObject
nXObject1 = linearDimensionBuilder1.Commit()
End If

End Sub
' ----------------------------------------------
' function to select dimensions
' ----------------------------------------------
Function Select_dim(ByRef obj As NXObject) As Selection.Response
Dim resp As Selection.Response = Selection.Response.Cancel
Dim prompt As String = "Select dimensions"
Dim message As String = "Select dimensions"
Dim title As String = "Selection"
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim selectionMask_array(0) As Selection.MaskTriple
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
With selectionMask_array(0)
.Type = UFConstants.UF_dimension_type
.Subtype = 0
.SolidBodySubtype = 0
End With
Dim cursor As Point3d = New Point3d
resp = ui.SelectionManager.SelectTaggedObject(prompt, message, _
scope, selAction, includeFeatures, keepHighlighted, selectionMask_array, obj, cursor)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function

End Module

You do not need a journal to change the tolerance if you are currently in the rapid dimension command. While in the rapid dimension command (either before or after you select the dimension references), expand the "settings" section of the dialog and press the "settings" button. From here you will be able to specify what tolerance style and value you want to use.

If you want to set the default tolerance style and value that will be used on all new dimensions in the part, go to the drafting preferences and set the desired values before adding dimensions. All new dimensions created in this part will follow the style you set. This can be done with a journal; simply record a journal while making the desired changes.

If you have a certain dimension style that you want to use in all new parts in the future, open your template part that your drawings are based on and change the preferences there. This will update the dimension style for any new parts created from the template.

What I am trying to accomplish is being able to bypass having to expand the settings of a dimension and type in the tolerance. I use many different tolerances and it would save a lot of time to be able to simply click a button for the desired tolerance. I had this set up in NX8.5 with macros that were linked to buttons I made, obviously these broke in NX9.

The reason that your current journal is failing in your intended use case is because there is an interactive selection function presented to the user; NX cannot process this interactive selection function while you are in the middle of another command (rapid dimension). Perhaps if you remove the interactive selection and keep only the part that sets the dimension preferences it would work.

Alternatively, you might consider re-creating your macros in NX 9. Macros are still viable in NX 9, but as you have found, they are very dependent on the version. You can likely get them to work again if you re-record them in NX 9.

I tried that, unfortunately "select_dim" becomes undeclared (at line 19). I was hoping there was a way to tell NX to use the current selection. I'm still digging thru the net_ref file to see if I can find anything.

I did try making new macros in 9 without much success, which I think is mostly due to how you now have to input tolerances and fix text.

Try running the following journal before creating a new dimension.

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

Module EditTolerance

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

Sub Main()

Dim markId1 As Session.UndoMarkId
markId1 = s.SetUndoMark(Session.MarkVisibility.Visible, "Drafting Preferences")

Dim preferencesBuilder1 As Drafting.PreferencesBuilder
preferencesBuilder1 = workPart.SettingsManager.CreatePreferencesBuilder()

preferencesBuilder1.AnnotationStyle.DimensionStyle.ToleranceType = Annotations.ToleranceType.BilateralOneLine
preferencesBuilder1.AnnotationStyle.DimensionStyle.ToleranceValuePrecision = 3
preferencesBuilder1.AnnotationStyle.DimensionStyle.UpperToleranceEnglish = 0.001

Dim nXObject1 As NXObject
nXObject1 = preferencesBuilder1.Commit()

preferencesBuilder1.Destroy()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function

End Module

That kind of works, but, I don't really want to change my preferences, and I would like to be able to do it in a dimension command. The majority of my dimensions are 3 or 4 place with no tolerances so I would like to leave my default to 4 place no tolerance. But I also use tolerances ranging from .010 to .0001 plus, minus, and plus minus. I have a journal for each of those situations linked to a button so all I need to do is click the button for the tolerance and precision I want. Currently that only works for dimensions that are already placed, which is better than nothing, but I would really like some way to do that while in a dimension command.

You cannot run a journal while another command is running; i.e. a journal cannot change the values in a dialog box for you while the command is running. A journal can change your dimension preferences before creating a dimension, or change the dimension style of an existing dimension.

Alternately, you could write a journal that would create the dimension then immediately set the style; but you would have to create your own UI for the command, you would not be able to use the rapid dimension dialog.

Well that is unfortunate, thank you for your help!