Cancel
Showing results for 
Search instead for 
Did you mean: 

API - Cannot edit nodal loads in GUI

Creator
Creator

Hi Everyone,

I am looking to automate an analysis process using the FEMAP API compiled for Python.  At this point, I am able to import the NX Nastran file I would like to analyze, programmatically define a nodal load using it's X, Y, and Z components, and have it applied to the model.  While the load seems to be correctly applied based on the model viewer, I would like to verify its properties in the Entity Editor pane.  Unfortunately, none of the force's properties show up when I highlight it in the feature tree.  (See attached image.)

I thought this may have been due to a rendering issue, so I both forced a redraw at the end of my code and tried to right-click on the force to edit the load definition, but neither of these items seems to work.  (Again, please see the attached image.)  As can be seen in the Messages window, FEMAP does output a message showing that it received the command to edit the load definition, but this does not generate a pop-up dialog.

Could I receive advice about what may be going on with my code?  Am I perhaps forgetting to set a property in either the load set or load mesh object that is causing a fault in FEMAP?

My code for this script is copied below.  Pyfemap is the name of the Python API module:

 

import pythoncom
import Pyfemap as pythonFemap
    
existObj = pythoncom.connect(pythonFemap.model.CLSID) #Grabs active model
    
#Connect to Femap
femap = pythonFemap.model(existObj)
femap.feAppBringToTop(True, 0) #Bring FEMAP window to top
femap.feAppMessage(0, 'SUCCESS: Python connected to FEMAP') #Print message in FEMAP Window
    
#Set program options
femap.DialogAutoSkipMsg=1 #Set option to automatically dismiss pop-ups
femap.Pref_MsgWndRepeatedErrors=1
    
#Create new model
femap.feFileNew()
activeModelID=femap.feAppGetModel() #Get active model ID
femap.feAppMessage(0,'Active model ID is '+str(activeModelID))
    
#Import NX NASTRAN file 
femap.feAppMessage(0, 'Importing NX NASTRAN analysis model...')
rc=femap.feFileReadNastran(8,"testCube.dat")
if rc==-1:
    femap.feAppMessage(0, 'SUCCESS: Return code FE_OK')
elif rc==0:
    femap.feAppMessage(0, 'FAILURE: Return code FE_FAIL - No Femap model is open')
elif rc==8:
    femap.feAppMessage(0, 'FAILURE: Return code FE_INVALID - Loaded file is not NX NASTRAN brand')
else:
    femap.feAppMessage(0, 'FAILURE: Unknown return code - Please see pg. 227 of the Femap API')        
       
#Initialize load set
femap.feAppMessage(0, 'Creating load set...')
loadSet = femap.feLoadSet #Create new feLoadSet object
loadSet.setID=1 #Assign feloadSet object ID
loadSet.title='loadSet_Test' #Assign feloadSetObject title
loadSet.Active=1 #Set feloadSetObject status to 'Active'
rc=loadSet.Put(1) #Updates loadSet data
if rc==-1:
    femap.feAppMessage(0, 'SUCCESS: Return code FE_OK - Load set is active')
elif rc==0:
    femap.feAppMessage(0, 'FAILURE: Return code FE_FAIL - Unable to store the entity with the specified ID')
else:
    femap.feAppMessage(0, 'FAILURE: Unknown return code - Please see pg. 1389 of the Femap API')
    
#Initialize load definition
femap.feAppMessage(0, 'Creating load definitions...')
loadDef=femap.feLoadDefinition # Create load definition object
loadDef.title="Force on Node"
loadDef.loadType=pythonFemap.constants.FLT_NFORCE
loadDef.dataType=pythonFemap.constants.FT_SURF_LOAD
loadDef.setID=1#femap.Info_ActiveID(pythonFemap.constants.FT_LOAD_DIR)
rc=loadDef.Put(loadDef.NextEmptyID()) #Apply properties
if rc==-1:
    femap.feAppMessage(0, 'SUCCESS: Return code FE_OK - Created load set')
elif rc==0:
    femap.feAppMessage(0, 'FAILURE: Return code FE_FAIL - Unable to store the entity with the specified ID')
else:
    femap.feAppMessage(0, 'FAILURE: Unknown return code - Please see pg. 1868 of the Femap API')
    
#Initialize load geometry
femap.feAppMessage(0, 'Creating load geometry...')
ptLoad=femap.feLoadMesh #Create load mesh object
ptLoad.CSys=0 #Coordinate system
ptLoad.color=10
ptLoad.meshID=74503 #ID of node
ptLoad.setID=loadDef.setID #ID of associated load definition
ptLoad.type=loadDef.loadType #Load type
ptLoad.LoadDefinitionID=loadDef.ID #Associate load mesh with load definition ptLoad.XOn=True ptLoad.YOn=True ptLoad.ZOn=True ptLoad.x=10 #Fx ptLoad.y=15 #Fy ptLoad.z=20 #Fz rc=ptLoad.Put(ptLoad.NextEmptyID()) #Apply properties if rc==-1: femap.feAppMessage(0, 'SUCCESS: Return code FE_OK - Created load set') elif rc==0: femap.feAppMessage(0, 'FAILURE: Return code FE_FAIL - Unable to store the entity with the specified ID') else: femap.feAppMessage(0, 'FAILURE: Unknown return code - Please see pg. 1868 of the Femap API') #Redraw femap.feAppUpdatePanes(True) femap.feViewRegenerate(0) #Analysis #...Perform analysis and save results

Thank you for your help!

2 REPLIES

Re: API - Cannot edit nodal loads in GUI

Siemens Phenom Siemens Phenom
Siemens Phenom

The only thing you forgot is to associate the actual load (LoadMesh) with the  load definition.  You do that by setting the LoadDefinitionID property on the LoadMesh object to the ID of the definition.

 

I am not familiar with Python, but I assume something like this... 

ptLoad.LoadDefinitionID=loadDef.ID

 

Make sure you do this prior to the call to Put().

Re: API - Cannot edit nodal loads in GUI

Creator
Creator

Thank you grudy!  This is exactly what the issue was.  I have edited the above code snippet to include your correction.  Hopefully this will serve as a reference in case someone runs into a similar issue in the future and is looking for working Python code.