Extracting data from Abaqus OBD file using python, only reads one file
Extracting data from Abaqus OBD file using python, only reads one file
(OP)
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.
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))
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))





RE: Extracting data from Abaqus OBD file using python, only reads one file
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,
RE: Extracting data from Abaqus OBD file using python, only reads one file
Does anyone have any ideas on how to adapt the code to re-assign this value?
Many Thanks
PH