Cancel
Showing results for 
Search instead for 
Did you mean: 

run NxOpen Python Linux NX 10

Experimenter
Experimenter

dear forum,

 

i have create a simple code block (see below) by use of Windows and NX10. In case of Windows it run well, with the command run_journal.exe readExpression.py -args old.prt expression.exp new.prt

 

In case of Linux (same command), I get errors regarding the workPart type. Because under Linux the workPart variable is empty with NoneType. But why, has someone any idea?

 

best regards

bluePy

 

import NXOpen
import sys

def readExpression(oldPartFile, expressionFile, newPartFile):

    #start NX Session
    theSession  = NXOpen.Session.GetSession()
    
    # open component
    theSession.Parts.OpenBaseDisplay(oldPartFile)
    workPart = theSession.Parts.Work
    print(type(workPart))
    # read ExpressionFile and manipulate component
    workPart.Expressions.ImportFromFile(expressionFile, NXOpen.ExpressionCollection.ImportMode.Replace)
       
    # save varied component
    try:
        workPart.SaveAs(newPartFile)
    except:
        print ("Die Datei existiert bereits!")
    
    
if __name__ == '__main__':
    oldPartFile = sys.argv[0]
    expressionFile = sys.argv[1]
    newPartFile = sys.argv[2]
    readExpression(oldPartFile, expressionFile, newPartFile)

7 REPLIES 7

Re: run NxOpen Python Linux NX 10

Siemens Phenom Siemens Phenom
Siemens Phenom

Your code is opening the file specified in the first argument as the base display part. My guess is that this is doing nothing in the batch environment since run_journal starts a session with no UI and no display.

 

Try using theSession.Parts.Open() to open your part.

 

 

Highlighted

Re: run NxOpen Python Linux NX 10

Experimenter
Experimenter


Try using theSession.Parts.Open() to open your part.

 

 


import NXOpen
import sys

def readExpression(oldPartFile, expressionFile, newPartFile): 

    #start NX Session
    theSession  = NXOpen.Session.GetSession()
    
    # open component
    theSession.Parts.Open(oldPartFile)
    workPart = theSession.Parts.Work
    print(type(workPart))
    displayPart = theSession.Parts.Display
    print(type(displayPart))
    # read ExpressionFile and manipulate component
    workPart.Expressions.ImportFromFile(expressionFile, NXOpen.ExpressionCollection.ImportMode.Replace)
       
    # save varied component
    try:
        workPart.SaveAs(newPartFile)
    except:
        print ("Die Datei existiert bereits!")
    
    
if __name__ == '__main__':
    print(sys.argv)
    oldPartFile = sys.argv[0]
    expressionFile = sys.argv[1]
    newPartFile = sys.argv[2]
    readExpression(oldPartFile, expressionFile, newPartFile)

The following output ...

['old.prt', 'expression.exp', 'new.prt']
<class 'NoneType'>
<class 'NoneType'>


Journal execution results for readExpression.py...
Syntax errors:
Line 16: Traceback (most recent call last):
  File "readExpression.py", line 30, in <module>
    readExpression(oldPartFile, expressionFile, newPartFile)
  File "readExpression.py", line 16, in readExpression
    workPart.Expressions.ImportFromFile(expressionFile, NXOpen.ExpressionCollection.ImportMode.Replace)
AttributeError: 'NoneType' object has no attribute 'Expressions'

Unfortunately,  the same error! Man Sad

 

 

Re: run NxOpen Python Linux NX 10

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Two more possibilities:

  1. There may have been a problem when loading the part. The .Open method returns a tuple (part, loadstatus), check the load status to see if it loaded without error.
  2. Don't assume that your newly loaded part has been automatically set as the work part. If the part loaded without error, either explicitly set it as the work part or refer to the part object directly (the one returned from the .Open method), instead of referencing the work part.

Re: run NxOpen Python Linux NX 10

Siemens Phenom Siemens Phenom
Siemens Phenom

 

OpenBaseDisplay() was a better choice for this, even though you are running in batch  mode.  Open() does not make the part the current work part, or the current display part, and it is actually valid to have a display part, even when you are running in batch - even though as Jim mentioned, you won't actually see it.

 

Note that any time you change an expression in a program - or replace expressions by importing them - you must have your program perform an update.  What version of NX are you running?  If I can get access to a Linux machine with your version of NX, I will test the Journal.

Re: run NxOpen Python Linux NX 10

Experimenter
Experimenter

PartLoadStatus.GetStatusDescription request, told me  "Library not found". 

log File analysis regarding UG version shows me libaries from /usr/lib64 are used.

 

that result in an adaptation of the enviroment variable:

 

LD_LIBRARY_PATH=/.../ugs100/ugopen:/.../ugs100/ugopenpp:/.../ugs100/ugii:/usr/lib64

 

now it works :-)

 

thanks a lot to JimB, cowski and SteveLabout

 

Re: run NxOpen Python Linux NX 10

Experimenter
Experimenter
LD_LIBRARY_PATH=/.../ugs100/ugii:/usr/lib64
is enough

Re: run NxOpen Python Linux NX 10

Experimenter
Experimenter
LD_LIBRARY_PATH=/usr/lib64:/.../ugs100/ugii
for my case the order of includes is important !!! I hope that was the last post!