Cancel
Showing results for 
Search instead for 
Did you mean: 

Export Parasolid Error

Creator
Creator

Hi all,

 

I am trying to export a parasolid using NxOpen in a python script.

 

I am currently recieving the following error in my error handler:

UF_initialize must be called by main routine

 

I'm currently running this outside of NX (i.e. from the command line)

 

Here is (what I think) is the relevant part of my code, but let me know if you think you need more.

 

 

    theUFSession = NXOpen_UF.UFSession.GetUFSession()

for part in partsToExport: partPrefix = path + part[1] print("\nExporting " + part[1] + " ...") bodyList=[] for feature in workPart.Features.GetFeatures(): if feature.Name==part[1]: for body in feature.GetBodies(): if body.IsSheetBody: bodyList.append(body.Tag) print(bodyList) print(partPrefix + ".x_t") try: theUFSession.Ps.ExportData(bodyList, partPrefix + ".x_t") except Exception as ex: print(theUFSession.Uf.GetFailMessage(ex.ErrorCode)) sys.exit()

 

Among other things, I tried:

 

 

    theUFSession = NXOpen_UF.UFSession.GetUFSession()
    errorCode=theUFSession.Uf.Initialize()
    print(errorCode)
    print(theUFSession.Uf.IsInitialized())

 

I get the following:

None
0

 

Which suggests the the Uf.Initialize() command isn't working. Any ideas what to do to initialize this?

 

Thanks for the help

12 REPLIES

Re: Export Parasolid Error

Siemens Phenom Siemens Phenom
Siemens Phenom

Try this:

 

import NXOpen
import NXOpen.UF

theUFSession = NXOpen.UF.UFSession.GetUFSession()

Re: Export Parasolid Error

Creator
Creator

Hi Jim,

 

Thanks for the response, I already had something similar in my code (I just had cut a load out to try to simplify it, let me know if it would be useful to post more)

 

Weirdly, I was doing 

import NXOpen
import NXOpen_UF

theUFSession = NXOpen_UF.UFSession.GetUFSession()

I ran it with NxOpen.UF and it made no difference to the result .

 

I think theUFSession is working as elsewhere in my code I do a call to it, which works:

 

sewTuple = theUFSession.Modeling.CreateSew(0, 1, [faceList[0]], len(faceList)-1, faceList[1:], 0.01, 0)

 

Let me know if you have any other ideas.

Re: Export Parasolid Error

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

UF_initialize() is only needed by C/C++, the modern managed development languages no longer need it.

In addition, why don't you use the body collection of the part, would be much faster than cycling through hundreds of features to find one body.

Below some code I use in one of my projects.

        For Each bod As Body In wPart.Bodies
            If LayerFilter = 0 Or bod.Layer = LayerFilter Then
                If bod.IsSolidBody Then
                    BodyArray.Add(bod)
                End If
            End If
        Next

It is VB.NET, but you should get it.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.2, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 11.4
Development: C (ITK), .NET, Tcl/Tk Testing: NX12.0 | AWC 3.4 Preparing: NX12.0

Employees of the customers, together we are strong Smiley Wink
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide
Highlighted

Re: Export Parasolid Error

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

I don't think this directly relates to the error you are seeing, but the part has a .Bodies collection that you can iterate through. Using the .Bodies collection would be more appropriate (and easier); trying to get the bodies through the individual features may return some that are no longer valid in the part (e.g. those consumed by later features).

 

Edit: seems @Stefan_Pendl was faster on the draw...

Re: Export Parasolid Error

Creator
Creator

So I created a test script:

 

import sys
import NXOpen
import NXOpen.UF

def main() : 
  theUFSession = NXOpen.UF.UFSession.GetUFSession()
  theSession = NXOpen.Session.GetSession()

  openfile="ShelfFront.prt"

  theSession.Parts.OpenBaseDisplay(openfile)
  workPart = theSession.Parts.Work

  bodyList=[]
  for feature in workPart.Features.GetFeatures():
    try:
      for body in feature.GetBodies():
        bodyList.append(body.Tag)
    except:
      print("error")

  theUI = NXOpen.UI.GetUI()
  #myMsgBox = theUI.NXMessageBox
  #myMsgBox.Show("Test", NXOpen.NXMessageBox.DialogType.Information,str(bodyList))
  
  filename="test.x_t"  

  try:
    theUFSession.Ps.ExportData(bodyList,filename)
  except Exception as ex:
    print(theUFSession.Uf.GetFailMessage(ex.ErrorCode))
    sys.exit()

if __name__ == '__main__':
    main()

Which runs fine if I fire it from inside NX, but errors as before if I run it from the command line using the following batch file:

SET UGII_BASE_DIR=C:\PLM\NX11
SET UGII_ROOT_DIR=%UGII_BASE_DIR%\UGII
SET UGII_NXBIN_DIR=%UGII_BASE_DIR%\NXBIN

SET INTERPRETER=C:\PLM\NX11\SIMULATION\samcef\Exec\Python;C:\PLM\NX11\SIMULATION\samcef\Exec\Python\DLLs;C:\PLM\NX11\SIMULATION\samcef\Exec\Python\Lib;C:\PLM\NX11\SIMULATION\samcef\Exec\Python\Lib\site-packages
SET PYTHONPATH=%INTERPRETER%;%UGII_BASE_DIR%\nxbin\python
SET PATH=%PATH%;%UGII_NXBIN_DIR%;%UGII_ROOT_DIR%

C:\PLM\NX11\SIMULATION\samcef\Exec\Python\python.exe "K:\Telford Road\Projects\WR\WR-03-Aero\CFD Process\SoftwareReleases\LatestRelease\pySMUT\dev\test.py"

pause

Is there something I'm missing in the setup?

 

Thanks

 

Re: Export Parasolid Error

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

In batch mode you have no UI, so you cannot use OpenBaseDisplay() or any of the UI related methods.

OpenBase should return a part object, so just use that.

There is also theSession.IsBatch to distinguish between UI and non-UI mode.

In addition make sure to have the NX folders placed before any others in the PATH variable.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.2, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 11.4
Development: C (ITK), .NET, Tcl/Tk Testing: NX12.0 | AWC 3.4 Preparing: NX12.0

Employees of the customers, together we are strong Smiley Wink
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide

Re: Export Parasolid Error

Creator
Creator

I updated my smaller test code. Using the OpenBase and outputting the part is much nicer, thanks. However I am still getting the error:

 

UF_initialize must be called by main routine

 

 

import sys
import NXOpen
import NXOpen.UF

def main() : 
  theUFSession = NXOpen.UF.UFSession.GetUFSession()
  theSession = NXOpen.Session.GetSession()

  openfile="ShelfFront.prt"

  (workPart,loadStatus)=theSession.Parts.OpenBase(openfile) 

  bodyList=[]
  for feature in workPart.Features.GetFeatures():
    try:
      for body in feature.GetBodies():
        bodyList.append(body.Tag)
    except:
      print("error")

  filename="test.x_t"  

  try:
    theUFSession.Ps.ExportData(bodyList,filename)
  except Exception as ex:
    print(theUFSession.Uf.GetFailMessage(ex.ErrorCode))
    sys.exit()

if __name__ == '__main__':
    main()

 

 

Re: Export Parasolid Error

Creator
Creator

I also tried to set the NX paths to come first in the path variable, but no dice.

 

Do you know if there is a way to set the batch environment up in the "same way" as it is if I opened up NX?

Re: Export Parasolid Error

Creator
Creator

I managed to sort out the issue, it was with the complicated way that I was calling the journal. Turns out there's a handy executable provided, so the batch script reduced to:

 

C:\PLM\NX11\NXBIN\run_journal.exe "test.py" -args %1

This meant that I had to change the arguments in the python script to start from 0:

 

sys.argv[0]

Thanks everyone for the help