This section explains each portion of the example script.
from abaqus import *
This statement makes the basic Abaqus objects accessible to the script. It also provides access to a default model database using the variable named mdb. The statement, from abaqusConstants import *, makes the Symbolic Constants defined by the Abaqus Scripting Interface available to the script.
import sketch
import part
These statements provide access to the objects related to sketches and parts. sketch and part are called Python modules.
The next statement in the script is shown in Figure 1. You can read this statement from right to left as follows:
Create a new model named Model A.
Store the new model in the model database mdb.
Assign the new model to a variable called myModel.
This statement creates a new sketch object named Sketch A in myModel. The variable mySketch is assigned to the new sketch. The sketch will be placed on a sheet 200 units square. Note the following:
A command that creates something (an “object” in object-oriented programming terms) is called a constructor and starts with an uppercase character. You have seen the Model and Sketch commands that create Model objects and Sketch objects, respectively.
The command uses the variable myModel that we created in the previous statement. Using variables with meaningful names in a script makes the script easier to read and understand.
These two statements define the X- and Y-coordinates of the vertices that form the inner and outer profile of the letter A. The variable xyCoordsInner refers to the vertices of the inner profile, and the variable xyCoordsOuter refers to the vertices of the outer profile.
for i in range(len(xyCoordsInner)-1):
mySketch.Line(point1=xyCoordsInner[i],
point2=xyCoordsInner[i+1])
This loop creates the inner profile of the letter A in mySketch. Four lines are created using the X- and Y-coordinates of the vertices in xyCoordsInner to define the beginning point and the end point of each line. Note the following:
Python uses only indentation to signify the start and the end of a loop. Python does not use the brackets {} of C and C++.
The len() function returns the number of coordinate pairs in xyCoordsInner—five in our example.
The range() function returns a sequence of integers. In Python, as in C and C++, the index of an array starts at zero. In our example range(4) returns 0,1,2,3. For each iteration of the loop in the example the variable i is assigned to the next value in the sequence of integers.
Similarly, a second loop creates the outer profile of the A character.
This statement creates a base solid extrude feature in myPart by extruding mySketch through a depth of 20.0.
myViewport = session.Viewport(name='Viewport for Model A',
origin=(20,20), width=150, height=100)
This statement creates a new viewport named Viewport for Model A in session. The new viewport is assigned to the variable myViewport. The origin of the viewport is at (20, 20), and it has a width of 150 and a height of 100.
myViewport.setValues(displayedObject=myPart)
This statement tells Abaqus to display the new part, myPart, in the new viewport, myViewport.