Journal to set/ change dimensions tolerance
Journal to set/ change dimensions tolerance
(OP)
Hello,
I want create journal to automatically set (or change already setted) dimensions tolerance. The macro must have:
1) possibility to select more than one dimension
2) possibility to reset previously setted value
3) possibility to select different kinds of dimension (radius, diameter, horizontal, vertical, parallel etc.)
I already wrote some of code, by the main problem is that, I don't know how fix selection of more than one dimension, and I can't set values.
Below is my code:
This journal must set dimension tolerance to "g6", but after selecting do nothing.
Could someone can help me improve this code?
with best regards
Michael
I want create journal to automatically set (or change already setted) dimensions tolerance. The macro must have:
1) possibility to select more than one dimension
2) possibility to reset previously setted value
3) possibility to select different kinds of dimension (radius, diameter, horizontal, vertical, parallel etc.)
I already wrote some of code, by the main problem is that, I don't know how fix selection of more than one dimension, and I can't set values.
Below is my code:
CODE
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Annotations
Module journal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim theAnnotationManager as NXOpen.Annotations.AnnotationManager = workPart.Annotations
'Dim theAnnotationManager as AnnotationManager = workPart.Annotations
Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager
Dim noteDim As Annotation
Dim Dimension1 As Annotations.Dimension
Dim response1 As Selection.Response = Selection.Response.Cancel
response1 = select_Dim("Select a Curve", noteDim)
If response1 = Selection.Response.Cancel Then
Return
End if
'----------------------------------------------
' this code is coped from recorded journal
'----------------------------------------------
Dim linearTolerance1 As Annotations.LinearTolerance
linearTolerance1.LimitFitDeviation = "g"
linearTolerance1.LimitFitGrade = 6
Dimension1.SetTolerance(linearTolerance1)
'-------------------------------------------------
End Sub
Function Select_dim(ByVal prompt As String, ByRef obj As annotation)
Dim message As String = "Select dimensions"
Dim title As String = "Selection"
Dim ui As UI = NXOpen.UI.GetUI
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
' Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
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 = Nothing
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject(prompt, message, _
scope, _
SelAction, _
includeFeatures, keepHighlighted, selectionMask_array, obj, cursor)
If resp = Selection.Response.Ok Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module This journal must set dimension tolerance to "g6", but after selecting do nothing.
Could someone can help me improve this code?
with best regards
Michael





RE: Journal to set/ change dimensions tolerance
Your code doesn't do anything after the selection step because the selection function is working with the noteDim variable; but the code to change the tolerance is working with the Dimension1 variable, which appears to be a null reference (no value has been assigned to it).
www.nxjournaling.com
RE: Journal to set/ change dimensions tolerance
So I should change
response1 = select_Dim("Select a Curve", noteDim)
to
response1 = select_Dim("Select a Curve", dimension1)
or something else?
with best regards
Michael
RE: Journal to set/ change dimensions tolerance
CODE
Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager Dim noteDim As Annotation Dim Dimension1 As annotations.dimension Dim response1 As Selection.Response = Selection.Response.Cancel response1 = select_Dim("Select a Curve", dimension1) If response1 = Selection.Response.Cancel Then Return End if With dimension1 .LimitFitDeviation = "g" .LimitFitGrade = 6 end withbut it also doesn't do anything.
RE: Journal to set/ change dimensions tolerance
As an example let us assume you have a linear dimension with a limit & fit included.
What is required is something like the following:
1) Create a builder
Dim linearDimensionBuilder1 As Annotations.LinearDimensionBuilder
2) Use the selected dimension in the builder (called say dimension1)
linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(dimension1)
3) Set the required parameters
linearDimensionBuilder1.Style.DimensionStyle.LimitFitDeviation = "g"
linearDimensionBuilder1.Style.DimensionStyle.LimitFitGrade = 6
4) Commit the changes
Dim nXObject1 As NXObject
nXObject1 = linearDimensionBuilder1.Commit()
Hope this helps
Frank Swinkels
RE: Journal to set/ change dimensions tolerance
CODE
www.nxjournaling.com
RE: Journal to set/ change dimensions tolerance
cowski I have some questions:
What is it for markId, it appears in every journal I record.
The Annotation.Dimension class has no .SetTolerance method, but has:
.LimitFitGrade
.LimitFitDeviation
and also has
.SetAttribute(String, String)
.ToleranceType
Which could be used to change tolerance. But I don't know how.
FrankSwinks I will also check Your solution with linearDimensionBuilde. Do You have any examples with this function?
Below is my changed code, but I receive error "System.NullReferenceException reference to object wasn't set to occur in object in journal.main() line 29" (I translated it from my language so there will be some difference in English version). Line 29 is: linearTolerance1 = Dimension1.GetTolerance()
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Annotations Module journal Sub Main () Dim theSession As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim workPart As Part = theSession.Parts.Work Dim displayPart As Part = theSession.Parts.Display Dim theAnnotationManager as AnnotationManager = workPart.Annotations Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager Dim Dimension1 As annotations.horizontaldimension = select_dim () Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "change tolerance") theSession.SetUndoMarkVisibility(markId1, Nothing, Session.MarkVisibility.Invisible) theSession.SetUndoMarkName(markId1, "Dimensions Dialog") Dim linearTolerance1 As Annotations.LinearTolerance linearTolerance1 = Dimension1.GetTolerance() linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits linearTolerance1.LimitFitDeviation = "g" linearTolerance1.LimitFitGrade = 6 Dimension1.SetTolerance(linearTolerance1) Dim nErrs1 As Integer nErrs1 = theSession.UpdateManager.DoUpdate(markId1) End Sub ' ---------------------------------------------- ' sub to select dimensions ' ---------------------------------------------- Function Select_dim() As Annotations.HorizontalDimension Dim prompt As String = "Select dimensions" Dim message As String = "Select dimensions" Dim title As String = "Selection" Dim ui As UI = NXOpen.UI.GetUI Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart ' Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly 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 Dim obj As Annotation With selectionMask_array(0) .Type = UFConstants.UF_dimension_type .Subtype = 0 .SolidBodySubtype = 0 End With Dim selectedObject As NXObject = Nothing Dim cursor As Point3d = Nothing 'Dim resp As Selection.Response = _ ui.SelectionManager.SelectObject(prompt, message, _ scope, _ SelAction, _ includeFeatures, keepHighlighted, selectionMask_array, obj, cursor) Dim dim_1 As Annotations.HorizontalDimension = CType(selectedObject, Annotations.HorizontalDimension) If dim_1 Is Nothing Then Return Nothing End If End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY End Function End ModuleCODE
Dim horizontalDimension1 As Annotations.HorizontalDimension = CType(workPart.FindObject("ENTITY 26 1 1"), Annotations.HorizontalDimension)I tried change it to set tolerance to selected objects instead first dimension put in drafting ("ENTITY 26 1 1"). I think that the code is almost ready (after eliminate this error), but the main problems still exists:
1) how to select more than one dimension?
2) how to set tolerances to different kinds of dimensions (horizontal, vertical etc.)
RE: Journal to set/ change dimensions tolerance
Hope this helps.
CODE -->
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.LimitsAndFits radialDimensionBuilder1.Style.DimensionStyle.LimitFitDeviation = "H" radialDimensionBuilder1.Style.DimensionStyle.LimitFitGrade = 7 Dim nXObject1 As NXObject nXObject1 = radialDimensionBuilder1.Commit() Else Dim linearDimensionBuilder1 As Annotations.LinearDimensionBuilder linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(selecteddim) linearDimensionBuilder1.Style.DimensionStyle.ToleranceType = Annotations.ToleranceType.LimitsAndFits linearDimensionBuilder1.Style.DimensionStyle.LimitFitDeviation = "H" linearDimensionBuilder1.Style.DimensionStyle.LimitFitGrade = 7 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 ModuleFrank Swinkels
RE: Journal to set/ change dimensions tolerance
Frank I tested Your code, and I get errors that:
- Annotations.RadialDimensionBuilder is not defined
- Annotations.LinearDimensionBuilder is also not defined
- CreateRadialDimensionBuilder is not member of element NXopen.Annotations.DimensionCollection
- and CreateLinearDimensionBuilder is not member of element NXopen.Annotations.DimensionCollection
I think, that they add this function in NX 8.5. I regreat that we don't have NX 9 (because We have few 32-bits systems), so I have no possibility to test it. This sub to check if selected object is radial or not is brilliant, I will use it later, after remove some errors.I also checked in documentation, that RadialDimensionBuilder is in NXopen.Features.
With best regards
Michael
RE: Journal to set/ change dimensions tolerance
RE: Journal to set/ change dimensions tolerance
1) First You have to choose command, instead of dimension. If You choose dimension, then error appears.
2) Macros doesn't work on every computer, even if You have the same version of NX. It seems that there is something not installed on computer, but I couldn't figured out what.
3) Macros are not supported by Siemens.
4) Sometimes after apply tolerance, instead of for example "H7" 3 or 4 square shows, or whole dimension is boldfaced.
That's why I wanna change .macros to .vb. In catia there is a special toolbar where You choose what tolerance You want. It would be a good idea, if NX has it also, but there is a progress, because NX 6 doesn't have possibility to choose "H7", the only option was to click right arrow and write it by Yourself.
Below I attached picture of my toolbar.
http://files.engineering.com/getfile.aspx?folder=d...
Can someone help me with this error: "System.NullReferenceException reference to object wasn't set to occur in object in journal.main() line 29" ?
With best regards
Michael
RE: Journal to set/ change dimensions tolerance
CODE -->
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Annotations Module NX85LimitsFits 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 markId3 As Session.UndoMarkId Dim dimname1 As String = selecteddim.ToString If dimname1.Contains("Radius") = True Then Dim radiusDimension1 As Annotations.RadiusDimension = selecteddim Dim linearTolerance1 As Annotations.LinearTolerance linearTolerance1 = radiusDimension1.GetTolerance() linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits radiusDimension1.SetTolerance(linearTolerance1) Dim dimensionPreferences1 As Annotations.DimensionPreferences dimensionPreferences1 = radiusDimension1.GetDimensionPreferences() dimensionPreferences1.LimitFitDeviation = "G" dimensionPreferences1.LimitFitGrade = 6 radiusDimension1.SetDimensionPreferences(dimensionPreferences1) ElseIf dimname1.Contains("Horizontal") = True Then Dim horizontalDimension1 As Annotations.HorizontalDimension = selecteddim Dim linearTolerance1 As Annotations.LinearTolerance linearTolerance1 = horizontalDimension1.GetTolerance() linearTolerance1.ToleranceType = Annotations.ToleranceType.LimitsAndFits horizontalDimension1.SetTolerance(linearTolerance1) Dim dimensionPreferences1 As Annotations.DimensionPreferences dimensionPreferences1 = horizontalDimension1.GetDimensionPreferences() dimensionPreferences1.LimitFitDeviation = "G" dimensionPreferences1.LimitFitGrade = 6 horizontalDimension1.SetDimensionPreferences(dimensionPreferences1) End If Dim nErrs1 As Integer nErrs1 = s.UpdateManager.DoUpdate(markId3) 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 ModuleFrank Swinkels
RE: Journal to set/ change dimensions tolerance
Below I attached my journals, so maybe for some other people will be useful.
Is there any way to select more than one dimension at time?
Once more Thanks everybody for Yours help.
With best regard
Michael
RE: Journal to set/ change dimensions tolerance
As an alterative can I suggest using a simple dialog. Image 1 shows it for limits and fit entry Image 2 shows it for tolerance values. When the first entry is set to limits and fits it would show the radio buttons for selecting an individual value. If the first entry is set to tolerance I have used a selection list of tolerances. When the desired requirement is set then select Apply and any number of dimension can be selected. After completion the dialog would again be available to set for an other value. If OK is selected it would do any selected dimensions and then exit the program. That is you would only be maintaining and running one program.
Frank Swinkels
RE: Journal to set/ change dimensions tolerance
I changed My code to fits Yours, so now my journals can select more than one dimension at time. I also looked at Your pictures, and decided to create my own version. First I looked on web sites but without success, only I have found was this tread:
http://www.eng-tips.com/viewthread.cfm?qid=328251
I used this thread and some other articles about radio buttons I create my own version. It doesn't work - after I select +-0,01 and hit Ok button, the program go to function select_dims and in this place I can't select anything because form1 is still active, NX stop responding. What I have do is kill process in task manager. I didn't set the rest buttons because if one isn't working it will be a waste of time. What is working is close button :). To create form1 I used Microsoft visual studio 2010 express, because I didn't found sample how to use UIstyler and radio button.
Below I attached my code and modified macros.
With best regards
Michael
RE: Journal to set/ change dimensions tolerance
One is an NX dialog file (DimTolerances.dlx).
This dialog file must be correctly located. Look in the vb source file for some comments about locating the dialog file
The second is the vb source file (DimTolerances.vb).
It can be run as a journal
The third is an NXOpen executable file (NXDialogTolerances.dll).
It has been signed so that you can execute it.
Frank Swinkels
RE: Journal to set/ change dimensions tolerance
With best regards
Michael
RE: Journal to set/ change dimensions tolerance
Frank Swinkels
RE: Journal to set/ change dimensions tolerance
In the meantime I tried change sub to .getDimensionText, and if vale is for example 100 I wanna set dimension text to something. In first part I get error: "Operator "=" is not defined for type 1-dimension table of elements "string" and "integer"." --> line "if x1 = 100 then". When I change it to "if x1 == 100 then", I get error "expression was expected". Second part of code work perfect -> horizontalDimension1.SetDimensionText(text1). I don't know how to solve it.
CODE
Sub EditDimensionTolerance(ByVal selecteddims () As TaggedObject) Dim markId3 As Session.UndoMarkId Dim dimname1 As String = Nothing For Each selecteddim As Dimension In selecteddims dimname1 = selecteddim.ToString() If dimname1.Contains("Horizontal") = True Then Dim horizontalDimension1 As Annotations.HorizontalDimension = selecteddim Dim text1(0) As String Dim text2(0) As String Dim text3(0) As String Dim x1() As string Dim x2() As string text1(0) = "G 1/8''" text2(0) = "G 1/4''" text3(0) = "G 3/8''" Dim Text0 as string horizontalDimension1.getdimensiontext(x1, x2) if x1 = 100 then horizontalDimension1.SetDimensionText(text1) else horizontalDimension1.SetDimensionText(text2) end if End If Next Dim nErrs1 As Integer nErrs1 = s.UpdateManager.DoUpdate(markId3) End SubWith best regards
Michael
RE: Journal to set/ change dimensions tolerance
if x1 = 100 then
horizontalDimension1.SetDimensionText(text1)
else
horizontalDimension1.SetDimensionText(text2)
end if
It should be
If x1(0) = "100" Then
horizontalDimension1.SetDimensionText(text1)
Else
horizontalDimension1.SetDimensionText(text2)
End If
That is the variable x1 is an array of strings and we need to get the first line of the array eg x1(0)
The second error is that since x1 is a string array it cannot be checked against a number eg = "100"
Frank Swinkels
RE: Journal to set/ change dimensions tolerance
Below I attached 2 journals. First adds appended text "M" before dimension, second change specific dimension value to G (from 1/8" - G 1") (British standard pipe parallel). Maybe It will be useful to someone in the future.
with best regards
Michael
RE: Journal to set/ change dimensions tolerance
RE: Journal to set/ change dimensions tolerance
name: UGII_USER_DIR
value x:\user_dir\
And in this dir You have to create dir: application, where You put this file. Everything is written in the vb file. Bellow I quote this comment:
CODE
'------------------------------- DIALOG LAUNCHING --------------------------------- ' ' Before invoking this application one needs to open any part/empty part in NX ' because of the behavior of the blocks. ' ' Make sure the dlx file is in one of the following locations: ' 1.) From where NX session is launched ' 2.) $UGII_USER_DIR/application ' 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly ' recommended. This variable is set to a full directory path to a file ' containing a list of root directories for all custom applications. ' e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_ROOT_DIR\menus\custom_dirs.dat ' ' You can create the dialog using one of the following way: ' ' 1. Journal Replay ' ' 1) Replay this file through Tool->Journal->Play Menu. ' ' 2. USER EXIT ' ' 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide" ' 2) Invoke the Shared Library through File->Execute->NX Open menu. ' '------------------------------------------------------------------------------with best regards
Michael
RE: Journal to set/ change dimensions tolerance