Showing results for 
Search instead for 
Do you mean 

NXOpen open file/ read attributes / close file

I'm working a project where I need to process through thousands of files.  For each file I need to open the file in NX, read some attributes, and then close the file.  I'm a little unclear on the API's I need.


The general logic I'm following is:


1)Establish a session

2)Start a for loop

3) Open a part (I am a little fuzzy on what the correct api call is here.  There are a number of open commands)

4) Read the necessary attributes.

5) Close the part


Can I do this strictly from the command line, or do I need the part to load into NX fully with the GUI?  Also what is the correct API call for step 3?


Re: NXOpen open file/ read attributes / close file

You can run with no GUI using %UGII_ROOT_DIR%/run_managed.exe or %UGII_ROOT_DIR%/run_journal.exe


To open the part, use NXOpen.Session.Parts.Open()

Re: NXOpen open file/ read attributes / close file

Ok, pardon my ignorance on this.  This seems like the method I need to "run headless" so to speak.  My only question is how would I execute my custom code in this fashion?  

Re: NXOpen open file/ read attributes / close file

After plugging away on my code for a while I've gotten it to this point.  I'm faulting at my attempt to pull attributes, but I'm sure I've made other mistakes.  Any assistance would be appreciated.


package main;

import java.rmi.RemoteException;
import nxopen.*;

* The purpose of this class is to take in a list of attributes and a file name, then return the requested attributes as another list.
* This should entail opening the file in NX, requesting the attributes, storing them in the list, closing the part in NX, then finally returning the list.

public class NXAttributeScanning {
String[] attlist;
String Filename;
String[] respLists;
public static Session theSession = null;
private static final String[] TESTLIST = {"DB_PART_REV","DB_PART_NAME"};
private static final String TESTFILE = "C:\\temp\\somepart.prt";

public static void main(String args[]) {
new NXAttributeScanning().nxAttributes(TESTLIST, TESTFILE);


public String[] nxAttributes(String[] attlist, String FileName){

try {
theSession = (Session)SessionFactory.get("Session");;
} catch (NXException e1) {
System.err.println("NXException: " + e1.getMessage());
catch (RemoteException e) {
System.err.println("RemoteException: " + e.getMessage());

for(int i = 0; i < attlist.length; i++){
try {
respLists[i] = theSession.getProperty(theSession, attlist[i]);
} catch (RemoteException e) {
System.err.println("RemoteException in Attribute capture: " + e.getMessage());
} catch (NXException e) {
System.err.println("NXException in Attribute capture: " + e.getMessage());

//Close NX parts
try {, null);
} catch (RemoteException e) {
System.err.println("RemoteException in Close: " + e.getMessage());
} catch (NXException e) {
System.err.println("NXException in Close: " + e.getMessage());

return respLists;

Re: NXOpen open file/ read attributes / close file

On first glance it looks like you are trying to get the properties of the session. I guess that is not want you want. Please find enclosed an example to get the attributes of the NX parts with Java:


import nxopen.*;


public class Search



public static void main(String [] args) throws NXException, java.rmi.RemoteException


Session theSession = (Session)SessionFactory.get("Session");


UI theUI = (UI) SessionFactory.get("UI");


ListingWindow lw = null;


//load CAD part in managed mode"@DB/ID/Rev); 

nxopen.PartCollection.OpenBaseData openBaseData1;

openBaseData1 ="@DB/ID/Rev");


Part workPart =;

Part displayPart =;


openBaseData1.loadStatus = null;


int number = workPart.getUserAttributes().length;


//get attributes

NXObject.AttributeInformation[] allAtts = workPart.getUserAttributes();


for (NXObject.AttributeInformation anAtt : allAtts){


//check for certain attribute

if(anAtt.type.equals(NXObject.AttributeType.STRING) && (anAtt.title.equalsIgnoreCase("db_part_rev"))){




"Properties: " + anAtt.title + " " + anAtt.stringValue);







public static final int getUnloadOption() { return BaseSession.LibraryUnloadOption.IMMEDIATELY; }




Re: NXOpen open file/ read attributes / close file

Hi! I realize this is an old post, but did you ever succeed in getting this work? I am actually trying to do something nearly identical:

Given an excel list of part numbers: 

1. Open first part number drawing

2. Run NX Journal code to capture data (which I have already written) and export to another excel list 

3. Close part file 

4. Repeat for all of the part numbers on the list 


If you have the code that might do something similar, that would be really appreciated! Also, could you point me in the direction of where to write this program? I am new to NXOpen and not sure where I should be writing these files to execute them properly. 


Thanks in advance! 


Re: NXOpen open file/ read attributes / close file

dwang2 et al, 


Sorry for the delayed response however you can also find more programming related answers on the NX Programming & Customization forum






Simcenter 3D Community Manager
Simulation and Test Solutions