Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Programmatically obtaining the session part units

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 9.0.3.4
' 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? 

 

Thanks,

jgolen

NX 9.0.3.4 MP13
VB.net
Visual Studio 2015
2 REPLIES

Re: Programmatically obtaining the session part units

Hi,

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

 

NX_default_unit.JPG

 

Selvaraj C
CAD Automation Engineer
NX 9 | NX 11 | Teamcenter 10
Solution
Solution
Accepted by topic author Jgolen
‎02-06-2017 10:23 AM

Re: Programmatically obtaining the session part units

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.