Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting data from Abaqus OBD file using python, only reads one file

Status
Not open for further replies.

PeterHughes

Materials
Feb 22, 2009
2
Good Afternoon

I'm new to scripting, or any sort of programming and am trying to write a script to extract the displacements and load from a set of nodes in an Abaqus OBD file, as I have about 1000 files to extract data from. I have searched Google/these forums but haven't yet found a solution.

I have managed through adapting the .rpy file and guess work/Google/books to get to the stage where I can open my files, and read them however rather than print the data from 1.odb, 2.odb, 3.odb etc, it just prints the data from one of the files three times. I have included a line that prints the name of the file, and it appears to open all the files in the directory but just not output the correct data.

I would be very grateful if someone with Python/Abaqus experience could have a look and tell me where I have gone wrong and how to remedy this. I have tried changing the indentation to see if that helps, but to no avail.

The file is attached, and runs fine (excluding above error) though File>Run Script in 6.7 however doesn't like being run in command line.

Any input greatly appreciated.

Code:
### import required modules  
import sys, os
from abaqus import *
from abaqusConstants import *
from caeModules import *
from driverUtils import executeOnCaeStartup
#
### point it at the files:
#
FOLDER = '/home/myfolder'
#
os.chdir(FOLDER)
for filename in os.listdir('.'):
	#
	#
	    	#f = open('/home/files.txt','a')
	    	#print >>f, filename
	### open abaqus module
	#
	    	executeOnCaeStartup()
	   	Mdb()
	### open file, set view 
	  	o1 = session.openOdb(
	 	       name=filename)
	 	session.viewports['Viewport: 1'].setValues(displayedObject=o1)
		session.viewports['Viewport: 1'].view.setValues(nearPlane=43.3078, 
			farPlane=76.6444, width=38.4285, height=19.2364, cameraPosition=(-22.5167, 
	     	   5.17008, 48.8967), cameraUpVector=(-0.602818, -0.140808, -0.785356))
	  	odb = session.odbs[filename]
	### extract reaction force 
		session.xyDataListFromField(odb=odb, outputPosition=NODAL, variable=(('RF', 
	 	       NODAL, ((COMPONENT, 'RF2'), )), ), nodeSets=('LOADY', ))
	### extract displacements
	 	odb = session.odbs[filename]
	 	session.xyDataListFromField(odb=odb, outputPosition=NODAL, variable=(('U', 
	  	      NODAL, ((COMPONENT, 'U1'), )), ), nodeSets=('XEXPPOS-VERT', ))
	 	odb = session.odbs[filename]
	 	session.xyDataListFromField(odb=odb, outputPosition=NODAL, variable=(('U', 
	  	      NODAL, ((COMPONENT, 'U3'), )), ), nodeSets=('Z-EXPPOS-TRANS', ))
	### assign data to variable
	 	x0 = session.xyDataObjects['RF:RF2 PI: BCC_FCC-1 N: 8']
	  	x1 = session.xyDataObjects['U:U1 PI: BCC_FCC-1 N: 14']
	  	x2 = session.xyDataObjects['U:U1 PI: BCC_FCC-1 N: 17']
	  	x3 = session.xyDataObjects['U:U1 PI: BCC_FCC-1 N: 23']
	   	x4 = session.xyDataObjects['U:U1 PI: BCC_FCC-1 N: 25']
	   	x5 = session.xyDataObjects['U:U3 PI: BCC_FCC-1 N: 16']
	### report data 
		session.xyReportOptions.setValues(minMax=ON)
		session.writeXYReport(
			fileName='/home/data.rpt', 
			xyData=(x0, x1, x2, x3, x4, x5))
 
Replies continue below

Recommended for you

Hi,

Getting hints from the .rpy file could help, but this is not the way to learn Abaqus Scripting Interface.

I suggest reading Abaqus Scripting User's Manual, in particular: "Using the ABAQUS Scripting Interface to access an output database"

Some remarks on your code:

Mdb() - creates a new model database, not necessary for opening .odb files.

executeOnCaeStartup() - this a function typically defined in the abaqus_v6.env environment file for customizing CAE. You should not execute it in your script.

Your code assumes that there are only .odb files in the folder.

You should close the .odb file once you are done with it.

And most important:

Make sure that your code is indented correctly.

You can always can include "print" statements to see what is going on in the code, for example you can include a print at the beginning of the loop and one at the end.

odb = session.odbs[filename] is repeated. Actually, I think you do not even need this, because:
o1 = session.openOdb(name=filename) should make o1 a reference to the odb object you open.

Best,


 
Thanks; have had a further attempt but it's still misbehaving. I think the problem is caused by the command session Odb and session.odbs being used, and I don't think session.odbs is taking the updated file.

Does anyone have any ideas on how to adapt the code to re-assign this value?

Many Thanks

PH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor