abaqus.rpy
file¶The file abaqus.rpy
is located in the work directory and contains the commands from the recording of every CAE event for the current session. The code can be copied, modified or otherwise used in your script.
Note: Best practice is usually to first set the parameter replayGeometry
to the option COORDINATE
rather than the default value INDEX
since the latter will produce totally cryptic reference to enteties.
>>>session.journalOptions.setValues(replayGeometry = COORDINATE)
For the session in the video above, the relevant part of the recorded code is
from abaqus import *
from abaqusConstants import *
session.Viewport(name='Viewport: 1', origin=(0.0, 0.0), width=98.5416641235352,
height=53.2150001525879)
session.viewports['Viewport: 1'].makeCurrent()
session.viewports['Viewport: 1'].maximize()
from caeModules import *
from driverUtils import executeOnCaeStartup
executeOnCaeStartup()
session.viewports['Viewport: 1'].partDisplay.geometryOptions.setValues(
referenceRepresentation=ON)
Mdb()
#: A new model database has been created.
#: The model "Model-1" has been created.
session.viewports['Viewport: 1'].setValues(displayedObject=None)
mdb.Model(name='M1', modelType=STANDARD_EXPLICIT)
#: The model "M1" has been created.
session.viewports['Viewport: 1'].setValues(displayedObject=None)
s = mdb.models['M1'].ConstrainedSketch(name='__profile__', sheetSize=200.0)
g, v, d, c = s.geometry, s.vertices, s.dimensions, s.constraints
s.setPrimaryObject(option=STANDALONE)
s.rectangle(point1=(0.0, 0.0), point2=(38.75, 28.75))
p = mdb.models['M1'].Part(name='P1', dimensionality=THREE_D,
type=DEFORMABLE_BODY)
p = mdb.models['M1'].parts['P1']
p.BaseSolidExtrude(sketch=s, depth=3.0)
s.unsetPrimaryObject()
p = mdb.models['M1'].parts['P1']
session.viewports['Viewport: 1'].setValues(displayedObject=p)
del mdb.models['M1'].sketches['__profile__']
session.viewports['Viewport: 1'].partDisplay.setValues(mesh=ON)
session.viewports['Viewport: 1'].partDisplay.meshOptions.setValues(
meshTechnique=ON)
session.viewports['Viewport: 1'].partDisplay.geometryOptions.setValues(
referenceRepresentation=OFF)
p = mdb.models['M1'].parts['P1']
p.seedPart(size=1.0, deviationFactor=0.1, minSizeFactor=0.1)
p = mdb.models['M1'].parts['P1']
p.generateMesh()
a = mdb.models['M1'].rootAssembly
session.viewports['Viewport: 1'].setValues(displayedObject=a)
session.viewports['Viewport: 1'].assemblyDisplay.setValues(
optimizationTasks=OFF, geometricRestrictions=OFF, stopConditions=OFF)
a = mdb.models['M1'].rootAssembly
a.DatumCsysByDefault(CARTESIAN)
p = mdb.models['M1'].parts['P1']
a.Instance(name='P1-1', part=p, dependent=ON)
Several lines are not essential, including all lines starting with session...
, which just gives commands on what should be displayed. That is also the case for setPrimaryObject
and unsetPrimaryObject
.
Furthermore, variables instanciated but not used can be removed, as well as redundant or repeating assignments. Removing everything being non-essential and removing line-breakes to arrive to the following stripped code:
from abaqus import *
from abaqusConstants import *
from caeModules import *
from driverUtils import executeOnCaeStartup
mdb.Model(name='M1', modelType=STANDARD_EXPLICIT)
s = mdb.models['M1'].ConstrainedSketch(name='__profile__', sheetSize=200.0)
s.rectangle(point1=(0.0, 0.0), point2=(38.75, 28.75))
p = mdb.models['M1'].Part(name='P1', dimensionality=THREE_D,
type=DEFORMABLE_BODY)
p.BaseSolidExtrude(sketch=s, depth=3.0)
del mdb.models['M1'].sketches['__profile__']
p.seedPart(size=1.0, deviationFactor=0.1, minSizeFactor=0.1)
p.generateMesh()
a = mdb.models['M1'].rootAssembly
a.DatumCsysByDefault(CARTESIAN)
a.Instance(name='P1-1', part=p, dependent=ON)
The code above is ready to be run in Abaqus CAE, either as a script file or by copying the lines and paste them in the command line interface. However, there are some considerations to be made related to imports:
from abaqus import *
will not be required when for example running the code through the command line interface. However, it may be required by other ways of execution, so it will be left as is. The import will not cause conflicts anyways, so it will be included as a best practice.
from abaqusConstants import *
is required since there are several abaqus constants being used (those with capital letters only)
from caeModules import *
and from driverUtils import executeOnCaeStartup
can be removed.
A final touch on the code may include variables and not hard-coded names and numbers:
from abaqus import *
from abaqusConstants import *
modelname = 'Model-X'
xdim = 50
ydim = 30
zdim = 10
esize = 5
mod = mdb.Model(name=modelname, modelType=STANDARD_EXPLICIT)
s = mod.ConstrainedSketch(name='__profile__', sheetSize=200.0)
s.rectangle(point1=(0.0, 0.0), point2=(xdim, ydim))
p = mod.Part(name='P1', dimensionality=THREE_D, type=DEFORMABLE_BODY)
p.BaseSolidExtrude(sketch=s, depth=zdim)
del s
p.seedPart(size=1.0, deviationFactor=0.1, minSizeFactor=esize)
p.generateMesh()
a = mod.rootAssembly
a.DatumCsysByDefault(CARTESIAN)
a.Instance(name='P1-1', part=p, dependent=ON)