Note: This is not a complete nor comprehensive recipe for all possibilities and options but rather what is needed for the scope of this site. Hence, the focus is on the interaction required and helpful for creating and running scripts in an educational context for the relevant courses.
The most versatile method is simply to
abaqus cae
Several optional parameters to the command are available. Relevant examples include
abaqus cae script=myScript.py # (running a script at startup)
abaqus cae noGUI=myScript.py # (running a script without the GUI)
The latter method is very useful when running many tasks like parameter studies where running a display has no added value but drains resources.
An Abaqus session tends to create a lot of files. Most of theese can be considered temporary data, i.e. files not worth keeping. The files will be generated in the work directory which is by default equal to the directory where abaqus cae was started.
For instance, works
will be the work directory following the command C:\temp\works>abaqus cae
Long paths containing non-standard symbols can easilly be a source of problems. For instance, a work directory at
C:\Users\ærlændå\OneDrive\Documents\skole\gløs\Abaqus\Brygging av øl\models\co2 ventil\versjon 10%\
has potentials for great fun on many levels.
Best practice:
A script is simply a file containing Abaqus Scripting Interface commands. It can be a significant work of brilliance containing some thousand lines of codes, or just a few lines of commands like this one:
from abaqus import *
from abaqusConstants import *
mdb.Model(name = 'Model-A') # Creates a new model
If the file path is C:\temp\works\scripts\scriptA.py
while the work directory is C:\temp\works\
, the script can be run using the following procedures:
C:\temp\works>abaqus cae script=scripts\scriptA.py
execfile()
, either by relative path or complete path:>>> execfile('scripts\scriptA.py')
The model "Model-A" has been created.
>>> execfile('C:\temp\works\scripts\scriptA.py')
The model "Model-A" has been created.
Some standard packages and modules are available, and there are nothing particular to consider when importing these. For instance
import numpy
import math
or alternatively more specific and/or convenient as
from numpy import cos, sin, radians
Writing custom modules for common tasks can be very useful, see for instance Custom tools for selecting entities
The modules must be located in one of the search path that can be listed by sys.path
(just a few shown in the result):
>>> sys.path
['C:\\SIMULIA\\CAE\\2019', 'C:\\SIMULIA\\CAE\\2019\\win_b64',...
'C:\\temp\\works',...
'C:\\SIMULIA\\CAE\\2019\\win_b64\\tools\\SMApy\\python2.7',...
'C:\\SIMULIA\\CAE\\2019\\win_b64\\tools\\SMApy\\python2.7\\lib\\site-packages\\win32\\lib',...
'C:\\SIMULIA\\CAE\\2019\\win_b64\\code\\bin', '.']
For example, 'C:\\temp\\works'
is one of the search paths as it is the work directory for the session when sys.path
was called. Hence, a module will be found when being in the work directory.
You may however want to organize your custom modules somewhere else, for example on a network drive like
C:\\Users\\einstein\\OneDrive\\Abaqus\\customlib
The directory is not on the search path and must be added before it can be imported:
>>> sys.path.append('C:\\Users\\einstein\\OneDrive\\Abaqus\\customlib')
>>> import customtools
To automate further, create a file, for example startup.py
, with the following lines:
import sys
sys.path.append('C:\\Users\\einstein\\OneDrive\\Abaqus\\customlib')
and start Abaqus CAE by
C:\temp\works>abaqus cae script=startup.py