Showing results for 
Search instead for 
Did you mean: 

Programmatically obtaining the session part units

Valued Contributor
Valued Contributor

Obtaining the units of a part file is relatively easy. Simply accessing PartReference.PartUnits will return a BasePart.Units enumeration with a value of Inches or Millimeters. However, as far as I know, aquiring this information for the session is another story. By "the session units" I'm referring to the units that are being returned from the measure analysis tools, or used in the creation of text, etc. Interactively this default can be changed by using the Unit Manager.

My question is how can we find out from the session which default unit is currently active? I've looked though the Session Class in the API reference and have not found anything that corresponds to units. Additonally I have tried a journal recording of setting the default unit in the Units Manager, but the resulting journal was junk.

' NX
' Journal created by jgolenbiewski on Mon Feb 06 08:17:40 2017 Eastern Standard Time
Option Strict Off
Imports System
Imports NXOpen

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

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
'   Menu: Analysis->Units Custom->Units Manager...
' ----------------------------------------------
' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Does anyone have any ideas? 




Visual Studio 2015

Re: Programmatically obtaining the session part units

Valued Contributor
Valued Contributor


Below code will gives you the customer defaults unit.

Is this one you expected?


// Gets the customer defaults unit
int retValue = theSession.OptionsManager.GetIntValue("UG_initialUnits"); // 1 - mm // 2 - Inch




Selvaraj C
CAD Automation Engineer
NX 9 | NX 11 | Teamcenter 10

Re: Programmatically obtaining the session part units

Honored Contributor
Honored Contributor

In menu -> analysis -> units, you can choose the unit system to display when performing measures (it also affects the default units of new sketches); this value can be set to something other than the part units. I think that @Jgolen is looking for these "analysis units" rather than the part units. If that is the case, the .AskInfoUnits method can be used.