Changing Dimension in Drawing sheet from mm to inch vice versa

Hi all,

I am new to journaling and i have just started to learn.Basically, Im working with large no of drawing.I have to create drawing in both inch and mm units.Firstly Im creating drawing in mm and again using the same drawing for inch version.I'll select all the dimensions and change the units and update the drawing.Is it possible to create a journal that will select all the dimensions in a drawing and change the units to inch?Since i have to do this for nearly 100 files it is taking more time to complete this.

Thanks in advance!

Such a journal would be possible to create; however, the usual method for this would be to use "dual dimensions".

https://docs.plm.automation.siemens.com/tdoc/nx/1899/nx_help#uid:xid1370722

With dual dimensions, both the inch and metric values can be shown on the same drawing. Creating and maintaining a single drawing is much preferred to creating and maintaining 2 separate drawings.

I do have a journal that will convert existing dimensions to use the dual dim format. It was made for someone that used inch units as primary and mm units as secondary; the "MakeDualDim" sub may need to be tweaked for your use case.

If any dimensions are pre-selected when you run the code, they will be converted to dual dim format. If no dimensions are pre-selected, it will prompt you to select dimensions (multiple dims can be selected).

'NXJournaling.com
'March 5, 2019

'convert_dim_dual.sln
'Turns on the "dual dimension" format for selected dimensions.
'This journal will operate on any dimension objects that are pre-selected before the journal is run.
'If there are no dimensions pre-selected, it will prompt the user to select the desired dimensions to convert.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "convert dimension to dual")

lw.Open()

Dim selobj As NXObject
Dim type As Integer
Dim subtype As Integer

Dim theUI As UI = UI.GetUI
Dim numsel As Integer = theUI.SelectionManager.GetNumSelectedObjects()

'process the preselected dimensions
If numsel > 0 Then

For inx As Integer = 0 To numsel - 1
selobj = theUI.SelectionManager.GetSelectedObject(inx)

theUfSession.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)

If type = UFConstants.UF_dimension_type Then

Dim theDim As Annotations.Dimension
theDim = DirectCast(selobj, Annotations.Dimension)

MakeDualDim(theDim)

End If

Next

Else
'prompt to select dimensions

Dim myDims As New List(Of Annotations.Dimension)
If SelectDimensions("Select Dimensions to make dual", myDims) = Selection.Response.Cancel Then
Return
End If

For Each tempDim As Annotations.Dimension In myDims
'lw.WriteLine("dim type: " & tempDim.GetType.ToString)
'Dim isAngular As Boolean
'isAngular = GetType(Annotations.BaseAngularDimension).IsInstanceOfType(tempDim)
'lw.WriteLine("dim is angular: " & isAngular.ToString)
MakeDualDim(tempDim)
Next

End If

lw.Close()

End Sub

Function SelectDimensions(ByVal prompt As String, ByRef someDims As List(Of Annotations.Dimension)) As Selection.Response

Dim selObj() As NXObject
Dim theUI As UI = UI.GetUI
Dim title As String = "Select dimensions"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_dimension_type
.Subtype = UFConstants.UF_all_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array,
selObj)
If resp = Selection.Response.Ok Then
For Each temp As Annotations.Dimension In selObj
someDims.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Sub MakeDualDim(ByVal theDim As Annotations.Dimension)

Dim objects1(0) As DisplayableObject

objects1(0) = theDim
Dim editSettingsBuilder1 As Annotations.EditSettingsBuilder
editSettingsBuilder1 = theSession.Parts.Work.SettingsManager.CreateAnnotationEditSettingsBuilder(objects1)

Dim editsettingsbuilders1(0) As Drafting.BaseEditSettingsBuilder
editsettingsbuilders1(0) = editSettingsBuilder1
theSession.Parts.Work.SettingsManager.ProcessForMutipleObjectsSettings(editsettingsbuilders1)

editSettingsBuilder1.AnnotationStyle.UnitsStyle.DualDimensionFormat = Annotations.DualDimensionPlacement.Below

editSettingsBuilder1.AnnotationStyle.UnitsStyle.ConvertPrimaryTolerance = True
If editSettingsBuilder1.AnnotationStyle.DimensionStyle.ToleranceValuePrecision > 0 Then
editSettingsBuilder1.AnnotationStyle.DimensionStyle.DualToleranceValuePrecision = editSettingsBuilder1.AnnotationStyle.DimensionStyle.ToleranceValuePrecision - 1
Else
editSettingsBuilder1.AnnotationStyle.DimensionStyle.DualToleranceValuePrecision = 0
End If

Dim nXObject1 As NXObject
nXObject1 = editSettingsBuilder1.Commit()

editSettingsBuilder1.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

Many thanks for sharing the code.Instead of switching on the dual dimension,it would be more helpful if the code changes the units of existing selected dimension.

I agree that creating single drawing is much better that creating separate drawings but our customer requirement is to create separate drawings for different units

I quickly put together the journal below to try converting dimension units. It doesn't do much error checking and only works on drafting dimensions (no feature control frames). It might be a good starting point for you.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module Module158
Sub Main(ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Dimension units")

Dim theDimensions As New List(Of Annotations.Dimension)
For Each tempDim As Annotations.Dimension In workPart.Dimensions
If TypeOf (tempDim) Is Annotations.BaseAngularDimension Then
'skip angular dimensions
Continue For
End If

theDimensions.Add(tempDim)
Next

If theDimensions.Count = 0 Then
lw.WriteLine("no dimensions found")
Return
End If

Dim curUnit As Annotations.DimensionUnit = theDimensions.Item(0).GetDimensionPreferences.GetUnitsFormatPreferences.PrimaryDimensionUnit

For Each tempDim As Annotations.Dimension In theDimensions

Dim editSettingsBuilder1 As NXOpen.Annotations.EditSettingsBuilder
editSettingsBuilder1 = workPart.SettingsManager.CreateAnnotationEditSettingsBuilder({tempDim})

Dim editsettingsbuilders1(0) As NXOpen.Drafting.BaseEditSettingsBuilder
editsettingsbuilders1(0) = editSettingsBuilder1
workPart.SettingsManager.ProcessForMultipleObjectsSettings(editsettingsbuilders1)

If curUnit = Annotations.DimensionUnit.Millimeters Then
editSettingsBuilder1.AnnotationStyle.UnitsStyle.DimensionLinearUnits = NXOpen.Annotations.DimensionUnit.Inches
Else
editSettingsBuilder1.AnnotationStyle.UnitsStyle.DimensionLinearUnits = NXOpen.Annotations.DimensionUnit.Millimeters
End If

Dim nXObject1 As NXOpen.NXObject
nXObject1 = editSettingsBuilder1.Commit()

editSettingsBuilder1.Destroy()

Next

End Sub

End Module

Thank you so much for the code.