Hauptseite Python Scripts for ABAQUS: Learn by Example

Python Scripts for ABAQUS: Learn by Example

0 / 0
How much do you like this book?
What’s the quality of the file?
Download the book for quality assessment
What’s the quality of the downloaded files?
2011, Gautam Puri, 1 ed.Python scripts let you accomplish tasks in Abaqus that would be time consuming or practically impossible in the GUI (Abaqus/CAE). Using a script you can automate a repetitive task, vary parameters of a simulation as part of an optimization study, extract information from large output databases, and can even create user interfaces that customize the look and feel of Abaqus, hiding parts of the interface from FEA illiterate team members.
However the learning curve for Python scripting is steep, and although the Abaqus documentation is comprehensive, it tends to overwhelm beginners. This is where this book fits in.
If you've never written a working script for Abaqus (and haven't used the Python programming language either), this book will take you from a beginner to an intermediate level.
If you have some previous scripting experience, but are not very confident in your abilities, this book will give you the stable foundation you need.
Sprache:
english
Seiten:
747
Datei:
PDF, 182,31 MB
Herunterladen (pdf, 182,31 MB)

Es kann für Sie interessant sein Powered by Rec2Me

 

Am meisten angefragte Begriffe

 
0 comments
 

Sie können die Buchrezension schreiben oder über Ihre Erfahrung berichten. Ihre Meinung über das gelesene Buch ist interessant für andere Leser. Unabhängig davon, ob Sie das Buch mögen oder nicht, kann Ihre ehrliche und ausführliche Beschreibung anderen Leuten beim Suchen von Büchern helfen.
PYTH ON SCRI PTS FOR
ABA QUS
LEARN BY EXAMP LE

~:· ·

""~'

t

Gautam Puri
'

'

Dedicated to Mom

f-irst Edition 2011
Copyright ID 2011 , Gautam Puri. All rights reserved.
The contents of this publication are the sole intellectual property of the author Gautam Puri. No part of this
publication may be reproduced, altered or distributed in any form or by any means, electronic, mechanical,
photocopying, reco rding, scanning, or otherwise, without the prior written consent of the author. This
document may NOT be posted anywhere on the internet, including but not limited to personal or commercial
websites, forums, private intranets, online storage locations (Rapidshare, Megaupload, etc.) and file sharing
(P2P I torrent I IRC etc.) portals or applications, nor may it be stored in a data base or retrieval system.
This book is neither owned (in part or full) nor endorsed by Dassault Systemes SIMUUA Corporation.

Disclaimer: The author does not offer any warranties for the quality or validity of the information contained
in this book or the included example Python scripts. This book has been written for entertainment purposes
only and should be treated as such. The reader is responsible for the accuracy and usefulness of any analyses
performed with the Abaqus Software, with or without the use of Python scripts. The reader is also responsible
for the accuracy and usefulness of any non-Abaqus related Python programs or software developed. The
information contained in the book is not intended to be exhaustive or apply to any particular situation and
must there fore be viewed with skepticism and implemented with extreme caution. The Python scripts
available with this book have been included for their instructional value. They have been tested with care but
are not guaranteed for any particular purpose. In no event shall the author be liable for any incidental, indirect
or consequential damages arising from use of this book or the example scripts provided with it.
In plain English, by reading this document y; ou acknowledge that the author is not responsible for your finite
element studies, nor is he responsible for the validity of their results or their interpretation.

Printed in the United States of America
Book website: www.abaquspython.com

Contents
1.

A Taste of Scripting

1.1
1.2
1.3
1.4
1.5

2.

Introduction
Using a script to define materials
To script or not to script..
Running a complete analysis through a script
Conclusion

2.4

2.5
2.6

Introduction
How Python fits in
Running a script within Abaqus/CAE
2.3.1 Running a script in GUl to execute a single or multiple tasks
2.3.2 Running a script in GUI to execute an entire simulation
Running a script from the command line
2.4.1 Run the script from the command line without the GUI
2.4.2 Run the script from the command line with the GU1
Running a script from the command line interface (CLI)
Conclusion

Python 101

3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8

8
8
32

33

Running a Script
2.1
2.2
2.3

3.

1

33
33

34
35
35
35
37
38
39
40

41

Introduction
Statements · ··:· ' ..
Variables and"'assign.ment stat~~ents
Lists
Dictionaries
Tu pies
Classes, Objects and Instances
What's next?
''

I

I

•

41
41
41
44

46
49
51
59

11

4.

Contents
The Basics of Scripting- Cantilever Beam Example

60

4.1
4.2
4.3

60
60
64
65
67
68
71
72
74
75
76

4.4

5.

Python 102

5.1

5.2
6.

Introduction
A basic script
Breaking down the script
4.3.1 Initialization (import required modules)
4.3.2 Create the model
4.3.3 Create the part
4.3.4 Define the materials
4.3.5 Create solid sections and make section assignments
4.3.6 Create an assembly
4.3.7 Create steps
4.3.8 Create and define field output requests
4.3.9 Create and define history output requests
4.3.10 Apply loads
4.3. 1I Apply constraints/boundary conditions
4.3.12 Mesh
4.3.13 Create and run the job
4.3.14 Post processing
What's Next?

Introduction
5.1.1 If... elif ... else statements
5.1 .2 For loops
5.1.3 range() function
5.1.4 While-loops
5.1.5 break and continue statements
What's Next?

77

78
81
83

88
89
90
92

92
92
94
95
97
97
99

Replay files, Macros and IDEs

100

6.1
6.2
6.3
6.4

100
100
101
106

Introduction
Replay Files
Example - Compare replay with a we11 written script
Macros

Contents
6.5

6.6
7.

Static Analysis of a Loaded Truss
7.1
7.2
7.3
7.4

7.5

8.

IDEs and Text Editors
6.5. 1 IDLE
6.5.2 · Notepad ++
6.5.3 Abaqus PDE
6.5.4 Other options
What's Next?

1ntroduction
Procedure in GUl
Python Script
Examining the Script
7.4.1 Initialization (import required modules)
7.4.2 Create the model
7.4.3 Create the part
7.4.4 Define the materials
7.4.5 Create sections and make section assignments
7.4.6 Create an assembly
7.4.7 Create steps
7.4.8 Create and define field output requests
7.4.9 Create and define history output requests
7.4.10 Apply loads
7.4.11 Apply boundary conditions
7.4.12 Mesh
7.4.13 Create and run the job
7.4.14 Post processing - setting the viewport
7.4.15 Plot the defonned state and modify common options
7.4.16 Plot the field outputs
Summary

Explicit Analysis of a Dynamically Loaded Truss
8.1
8.2
8.3

Introduction
Procedure in GUl
Python Script

Ill

109
109
109
110
113
114
117

117
118
124
129
129
130
130
131
132
134
135
135
135
136
137
139
141
141
142
143
145

146
146
147
154

1v

Contents

8.4

9.

8.3 .1 Part, material, section and assembly blocks
8.3 .2 Creating sets
8.3.3 Creating steps
8.3.4 Create and define history output requests
8.3.5 Apply loads
8.3.6 Boundary conditions, mesh, running the job and initial post
processing
8.3.7 XY plots of displacement
Summary

Analysis of a Frame of 1-Beams
9.1
9.2
9.3
9.4

Introduction
Procedure in GUT
Python Script
Examining the Script
9.4.1 Initialization (import required modules)
9.4.2 Create the model
9.4.3 Create the part
9.4.4 Define the materials
9.4.5 Create profiles
9.4.6 Create sections and make section assignments
9.4.7 Assign section orientations
9.4.8 Create an assembly
9.4.9 Create connectors using wire features
9.4.10 Use constraint equations for two nodes
9.4.11 Create steps
9.4.12 Create and define field output requests
9.4.13 Create and define history output requests
9.4.14 Apply loads
9.4.15 Apply boundary conditions
9.4.16 Mesh
9.4.17 Create and run the job

9.5

Summary

160
161
162
163
164
164
165
170
171
171
174
188
199
199
199
199
206
206
207
210
210
211
216
218
218
218
218
220
222
222
223

Contents v

10.

Bending of a Planar Shell (Plate)
10.1
10.2
10.3
10.4

10.5

11.

Introduction
Procedure in GUI
Python Script
Examining the Script
10.4.1 Initialization (import required modules)
10.4.2 Create the model
I 0.4.3 Create the part
I 0.4.4 Define the materials
10.4.5 Create solid sections and make section assignments
10.4.6 Create an assembly
10.4.7 Create steps
10.4.8 Create and define field output requests
10.4.9 Create and define history output requests
10.4.10 Apply boundary conditions
10.4.11 Partition part to create vertices
10.4.12 Apply loads
10.4.13 Mesh
10.4.14 Create and run the job
10.4.15 Display deformed state with contours
I 0.4.16 Write Field Output Report
Summary

Heat Transfer Analysis
11.1
11 .2
1 1.3
1 1.4

224

224
226
233
239
239
239
239
240
240
242
242
243
243
244
245
248
248
250
250
251
252
253

Introduction
253
Procedure in GUI
255
Python Script
261
Examining the Script
266
11.4.1 Initialization, creation of the model, part, materials, sections and
assembly
266
I 1.4.2 Create a datum plane and partition the part
266
11.4.3 Create steps
268
11.4.4 Apply constraints/boundary conditions
268
11.4.5 Apply loads
269

VI

Contents

11.5

1 I.4.6 Create interactions
11.4.7 Mesh
1 I .4.8 Create and run the job
1 I .4.9 Post Processing
Summary

12. Contact Analysis (Contact Pairs Method)
12.1
12.2
12.3
12.4

12.5
12.6

13.

Introduction
Procedure in GUI
Python Script
Examining the Script
I 2.4.1 Initialization (import required modules)
12.4.2 Create the model
12.4.3 Create the part
12.4.4 Define the materials
12.4.5 Create solid sections and make section assignments
12.4.6 Create an assembly
12.4.7 Create steps
12.4.8 Create and define field output requests
12.4.9 Create and define history output requests
12.4.10 Apply boundary conditions
12.4.11 Apply loads
12.4.12 Create Surfaces
12.4.13 Create Interaction Properties
12.4.14 Create Interactions
12.4.15 Mesh
12.4.16 Create and run the job
12.4.17 Post Processing- Display deformed state
Summary
What' s Next?

Optimization - Determine the Maximum Plate Bending Loads
13.1
13.2

Introduction
Methodology

270
273
275
275
278

279
279
281
291
300
300
300
301
302
303
304
309
310
310
310
312
312
313
314
316
317
318
318
318

319
319
3 19

Contents vii
13.3
13.4

13.5

14.

Python Script
321
Examining the Script
329
13.4.1 Model, Part, Material, Section, Assembly, Step, Field Output
Request, Boundary Condition, Partition and Mesh creation.
329
13.4.2 Initialization
329
13.4.3 Modify and run the analysis at each iteration
330
13.4.4 Print a table of the results
338
13.4.5 Read the report file to determine where the maximum stress was
exceeded
341
13.4.6 Light up elements in the viewport where max stress is exceeded
345
13.4.7 Print messages to the message area
347
Summary
348

Parameteriz ation, Prompt Boxes and XY Plots
14.1
14.2
14.3
14.4

14.5

Introduction
Methodology
Python Script
Examining the Script
14.4.1 Accept inputs
14.4.2 Create the model
14.4.3 Create part
14.4.4 Create a section
14.4.5 Create sets
14.4.6 Request and use load magnitude
14.4.7 Boundary conditions
14.4.8 Initial post processing
14.4.9 Combined XY plot
14.4.10 Chart Options
14.4.11 Axis Options
14.4.12 Title Options
14.4.13 Chart Legend Options
14.4.14 XY Curve Options
14.4.15 Print the plot to an image
Summary

349
349
350
351
363
363
366
366
367
368
368
369
370
371
371
373
375
376
377
378
379

VIII

Contents

15.

Optimization of a Parameterized Sandwich Structure
15.1
15.2
15.3
15.4

15.5

Introduction
Procedure in GUI
Python Script
Examining the Script
15.4.1 Accept inputs
15.4.2 Variable initialization and preliminary calculations
15.4.3 Create the model
15.4.4 Create the parts, material, section and assembly
15.4.5 IdentifY faces and sets
15.4.6 Assemble parts
15.4.7 Create steps, boundary conditions and loads
15.4.8 Surfaces and Tie constraints
15.4.9 Mesh and Run Job
15.4.1 0 XY Reports
15.4.11 Read from report
15.4.12 Write to output file
Summary

16. Explore an Output Database
16.1
16.2
16.3
16.4
16.5

380

380
382
392
405
405
407
408
408
409
410
411
412
413
413
415
416
417
418

Introduction
418
Methodology
419
Before we begin - Odb Object Model
420
How to run the script
423
Python Script
423
16.5. 1 Initialization
429
16.5.2 Mathematical operations on field data
429
16.5.3 Access infonnation about part, nodes, elements, stresses,
displacements
433
I 6.5.4 Display history output information for static truss analysis 441
I 6.5.5 Display history output information for dynamic explicit truss
analysis 444
16.5.6 Extract material and section definitions
447
16.5.7 Extract material and section definitions
449

Contents tx
16.6
16.7
16.8

17.

Object Model Interrogation
More object model interrogation techniques
Summary

Combine Frames of two Output Data bases and Create an Animation
17.1
17.2
17.3
] 7.4
17.5
17.6
17.7
17.8

17.9

Introduction
Methodology
Procedure in GUI
How to run the script
Python Script to simulate plastic plate bending
Python Script to simulate elastic springback
Python Script to combine the output databases
Examining the Script
] 7.8.1 Class Definition.
17.8.2 Read data from output databases
17.8.3 Create a new output database
17.8.4 Create the animation using the new output database
Summary

18. Monitor an Analysis Job and Send an Email when Complete
18.1
18.2
18.3
18.4

18.5

Introduction
Methodology
Python Script
Examining the Script
18.4.1 Job submission and message callback
18.4.2 Define the callback function
18.4.3 Define a function to handle post processing
18.4.4 Define the email function
Summary

19. A Really Simple GUI (RSG) for the Sandwich Structure Study
19.1
19.2

Introduction
Methodology

450
454
457
459
459
460
460
467
467
475
486
492
492
493
500
507
509
510

510
510
511
516
517
519
520
520
524

527
527
527

-----

x Contents

19.3
19.4
19.5
19.6

19.7

20.

528
535
552

566
566
566
567
568
569
569

Create a Custom GUI Application Template

570

20.1
20.2
20.3
20.4
20.5
20.6

570

20.7
2 1.

Getting Started with RSG
Create an RSG for Sandwich Structure Analysis
Python Script to respond to the GUI dialog inputs
Examining the Script
19.6.1 Function definition
19.6.2 Material variable assignments
19.6.3 Create the materials
19.6.4 Create the sections
19.6.5 To write (or not write) XV report and print displacement
Summary

Introduction
What is the Abaqus GUI Toolkit
Components of a GUI Application
GUI and Kernel Processes
Methodology
Python Script
20.6.1 Application Startup Script
20.6.2 Main Window
20.6.3 Modified Canvas Toolset (modified ' Viewport' menu)
20.6.4 Custom Persistant toolset
20.6.5 Adding some functionality with a ' main' program
20.6.6 Custom Module
20.6.7 Fonn Mode
20.6.8 Modal Dialog box
20.6.9 Modeless Dialog box
Summary

57 1
571
573

575
576
576
579

587
593

602
607
615
619

623
625

Custom GUI Application for Beam Frame Analysis

626

21.1
21.2
21.3
21.4

626
630

Introduction
Layout Managers and Widgets
Transitions and Process Updates
Exploring the scripts

631

631

~ -

Contents
21.4.1
2 1.4.2

Beam Application Kernel Script
Beam Application Startup Script

2 1.4.3
21.4.4
21.4.5
2 1.4.6

21.5

22.

Beam Application Main Window
C ustom Pe rsistant toolset
Custom Beam Module
Step I Dialog Form and Dialog Box
2 1.4.7 Step 2 Dialog Form and Dialog Box
2 1.4.8 Step 3 Procedure and Dialog Box
21.4.9 Step 4 Form and Dialog Box
Summary

Plug-ins

631
655
656
657
666
671
688
70 1
709
716
717

22.1
22.2

Introduction
Methodology

22.3

Learn by Example
22.3 .1 Kernel Plug-in Example

22.4

XI

22.3.2 GUI Plug-in Example
Summary

717
717
718
7 18

720
724

Preface
If you're reading this, you've probably decided to write a Python script to run an FEA
analysis in Abaqus. But you' re not sure where to begin, you've never written a working
script for Abaqus, and you've never worked with the programming language Python
either. The good news is you've found the right book to deal with the situation. Through
the course of this text you 're going to learn the basics of writing scripts for Abaqus and
understand the working of the Abaqus Scripting Interface. At the same time you're going
to learn what you need to know of the Python programming language itself. You're going
to receive the stable foundation you need so that you spend more time focusing on your
research and less time debugging code.
The aim of this book is not to teach you every single built-in scripting method offered by
Abaqus. There are literally hundreds of these, and chances are you will only use a few of
them for your own simulations. We'll focus on these, and put you in a position where you
can branch out on your own. For the record all the keywords and methods of the Abaqus
Scripting Interface are listed in the Abaqus Scripting Reference Manual. The
documentation also consists of a manual called the Abaqus Scripting User' s Manual
which provides helpful advice on different scripting topics. You could potentially learn to
write Abaqus scripts in Python from the documentation itself, as many people (such as
me) have had to do in the past. But as a beginner you will likely find yourself
overwhelmed by the sheer quantity of information provided there. You will spend a Jot of
time making avoidable mistakes and discovering for yourself, after hours (or days or
months) of trial and error, the correct method to accomplish a given task through a script.
This book gives you the guidance you need to start writing complex scripts right off the
bat. Once you've read through all the pages you will have the knowledge and the
confidence to write your own scripts for finite element simulations in Abaqus, and will
then be able to refer to the Abaqus documentation for more information specific to your
research task.

Why write scripts?
If you plan to learn scripting in Abaqus chances are you already know why it is useful
and intend to use it to accomplish some task for your analyses. But for the sake of

xtv Preface
completeness (and for those of you who are reading because your professor/boss forced
you to), a few uses shall be mentioned.
Let's assume you regularly use a few materials in all your simulations. Every time you
start a new simulation in the GUT mode (Abaqus/CAE) you need to open up the materials
editor and enter in material properties such as the Density, Young's Modulus, and
Poisson's Ratio and so on for each of these materials. You could instead put all of these
materials in a script. Then all you would need to do is go to File > Run Script ... and your
material database would be populated with these materials in a couple of seconds.
Basically you would be using the script to perform a repetitive task to save time. That is
the one use of a script, to perform the same task the same way multiple times with
minimal effort. We will in fact look at this example of creating materials with a script in
the first chapter.
A more complex use of a script is if you have a certain part on which you plan to apply
loads and boundary conditions, and you wish to change the loads, constraints, or the
geometry of the part itself and rerun the simulation numerous times to optimize the
design. Let's assume for example you apply a load on a horizontal cantilevered beam and
you want to know how much the beam bends as you increase its length. One way to do
this would be to recreate the beam part 7 or 8 times. If your simulation has complex
parameters you might have to apply sections, loads and constraints to it every time. A
more sophisticated and efficient way to accomplish the same task is to write a script with
the length of the beam assigned to a variable. You could then change the value of this
variable and rerun the script in a loop as many times as you need to. The script would
redraw the beam to the new length and apply the loads and BCs in the correct regions
(accounting for the change in location of loads and BCs with the geometry). While this
may sound like too much work for a simple beam simulation, if you have a more
complex part with multiple dimensions that are all related to each other then remodeling
it several times wiiJ prove to be very time consuming and a script will be the wise choice.
An added advantage of a script is that you have your entire simulation setup saved in the
form of a small readable text file only a few kilobytes in size. You can then email this
text file to your coworker and a11 he would need to do is run this script in Abaqus. It
would redraw the part, apply the materials, loads, boundary conditions, create the steps,
and even create and run the job if programmed to do so. This also has the advantage of
readability. If a coworker takes over your project, he does not need to navigate through

Preface xv
the model tree to figure out how you created the complex geometry of your part file, or
what points and edges you applied each load or boundary condition on. He only needs to
open up the script file and it's aiJ clearly spelled out. And you can put comments all over
the script to explain why you did what you did. It keeps things compact and easy to
follow.

What you need ...
This book assumes that you have some previous experience with running simulations in
Abaqus in the GUI (Abaqus/CAE). This means you know how to set up a basic
simulation, create parts, enter material properties, assign sections, apply forces and
boundary conditions, create interactions, mesh parts and run jobs by using the tool bars or
menus in Abaqus/CAE. When we start learning to write scripts you will essentially be
perfonning all ofthese same procedures, except in the form of Python code.
However you do not need to be an expert at these tasks. For every example we work on,
we first look at the procedure to be carried out in the Abaqus/CAE. This procedure has
been spelled out in the text, and is also demonstrated as silent video screencasts where
you can watch me perform the analysis step by step. This is to ensure that you know how
to perfonn the task in the GUI itself, before trying to write a script. These screencasts
have been posted on the book website www.abaguspython.com (and hosted on YouTube)
where I've found they are also being used by beginners trying to teach themselves
Abaqus. Following the creation of these videos, I was employed by Dassault Systemes
Simulia Corp. to create an Abaqus tutorial series on their new ' SIMULIA Learning
Community'. I have recorded audio narration with detailed explanation over all of these,
and other newer tutorials as well. These are currently displayed (free) at
www.simulia.com/leaming. If you wish to brush up on your Abaqus skills you may
watch these. Refer to the book website for up-to-date information and links.
The book assumes that you have some basic knowledge of programming. This includes
understanding concepts like variables, loops (for, while) and if-then statements. You are
all set if you have experience with languages such as C, C++, Java, VB, BASIC etc. Or
you might have picked up these concepts from programmed engineering software such as
MATLAB or Mathematica.
In order to run the example scripts on your own computer you will need to have Abaqus
installed on it. Abaqus is the flagship product of SIMULIA, a brand of Dassault

xvi Preface
Systemes. If you have Abaqus (research or commercial editions) installed on the
computers at your workplace you can probably learn and practice on those. However not
everyone has access to such facilities, and even if you do you might prefer to have
Abaqus on your personal computer so you can fiddle around with it at home. The good
news is that the folks at SIMULIA have generously agreed to provide readers of this
book with Abaqus Student Edition version 6.10 (or latest available) for free. It can be
downloaded off the book website. This version of Abaqus can be installed on your
personal computer and used for as long as you need to learn the software. There are a few
minor restrictions on the student edition, such as a limitation on the number of nodes
(which means we will not be able to create fine meshes), but for the most part these will
not hinder the learning experience. For our purposes Abaqus SE is identical to the
research and commercial editions. The only difference that will affect us is the lack of
replay files but I'll explain what those are and how to use them so you won't have any
trouble using them on a commercial version. Abaqus SE version 6.9 and version 6.10
were used to develop and test all the examples in this book. The Abaqus Scripting
Interface in future versions of Abaqus should not change significantly so feel free to use
the latest version available to you when you read this.

How this book is arrange d..•
The first one-third of this book is introductory in nature and is meant to whet your
appetite, build up a foundation, and send you in the right direction. You will learn the
basics of Python, and get a feel for scripting. You 'll also learn essential stuff like how to
run a script from the command line and what a replay file is.
The second part of the book helps you ' Learn by Example'. It walks you through a few
scripting examples which accomplish the same task as the silent screencasts on the book
website but using only Python scripts. Effort has been taken to ensure each
example/ script touches on different aspects of using Abaqus. All of these scripts create a
model from start to finish, including geometry creation, material and section assignments,
assembling, assigning loads, boundary conditions and constraints, meshing, running a
job, and post processing. These scripts can later be used by you as a reference when · .
writing your own scripts, and the code is easily reusable for your own projects. Aside
from demonstrating how to set up a model through a script, the later chapters also
demonstrate how to run optimization and parametric studies placing your scripts inside

Preface xvtt
loops and varying parameters. You also get an in-depth look into extracting information
from output databases, and job monitoring.
The last part of the book deals with GUI Customization - modifying the Abaqus/CAE
interface for process automation and creating vertical applications. It is assumed that you
have no previous knowledge of GUI programming in general, and none at all with the
Abaqus GUI Toolkit. GUI Customization is a topic usually of interest only to large
companies looking to create vertical applications that perfonn repetitive tasks while
prompting the user for input and at the same time hiding unnecessary and complex
features of the Abaqus interface. Chances are most readers will not be interested in GUI
Customization but it has been included for the sake of completeness and because there is
no other learning resource available on this topic.

Acknowledgements
I would like to thank my mother for giving me the opportunity to pursue my studies at a
great expense to herself. This book is dedicated to her. I would also like to thank my
father and my grandmother for their love, support and encouragement.
I'd like to thank my high school Physics teacher, Santosh Nimkar, for turning a subject I
hated into one I love. The ability to understand and predict real world phenomena using
mathematics eventually led me toward engineering.
I'd like to extend a special thank you to Rene Sprunger, business development manager
at SIMULIA (Dassault Systemes Simulia Corporation) for his support and
encouragement, without which this book might never have materialized. I'd also like to
thank all the professionals at SIMULIA for developing the powerful realistic simulation
software Abaqus, and for creating the remarkable Abaqus Scripting Interface to enhance
it.

PART 1- GETTING STARTED
The chapters in Part I are introductory in nature. They help you understand how Python
scripting fits into the Abaqus workflow, and explain to you the benefits and limitations of
a script. You will learn the syntax of the Python programming language, which is a
prerequisite for writing Abaqus scripts. You will also learn how to run a script, both from
within Abaqus/CAE and from the command line. We'll introduce you to replay files and
macros, and help you decide on a code editor.
It is strongly recommended that you read all of these chapters, and do so in the order
presented. This will enhance your understanding of the scripting process, and ensure you
are on the right track before moving on to the examples of Part 2.

-1
A Taste of Scripting
-

The aim of this chapter is to give you a feel for scripting in Abaqus. It will show you the
bigger picture and introduce you to idea of how a script can replace actions you would
otherwise perform in graphical user interface (GUl) Abaqus/CAE. It will also
demonstrate to you the ability of Python scripts to perform just about any task you can
perform manually in the GUI.

When running simulations specific to your field of study you may find yourself reusing
the same set of materials on a regular basis. For instance, if you analyze and simulate
mostly products made by your own company, and these contain a number of steel
components, you will need to define the material steel and along with its properties using
the materials editor every time you begin a new simulation. One way to save yourself the
trouble of defining material properties every time is to write a script that will accomplish
this task. The Example 1.1 demonstrates this process.

Example 2.1 -Defining materials and properties
Let's assume you often use Titanium, AISI 1005 Steel and Gold in your product. The
density, Young's Modulus and Poisson's Ratio of each of these materials is listed the
following tables.

2 A Tast e of Scri pting
Properties of Titanium
Prop erty

Metr ic

English

Density

4.50 g/cc

0.163 lb/in

Mod ulus of Elasticity

116 GPa

16800 ksi

Poisson' s Ratio

0.34

0.34

3

Properties of AISI I 005 Steel
Property

Metr ic

English

Density

7.872 g/cc

0.2844 lb/in

Mod ulus of Elasticity
Poisson's Ratio

200GPa

29000 ksi

0.29

0.29

3

Properties of Gold
Prop erty

Metr ic

English

Density

19.32 gjcc

0.69 80 lb/in

Mod ulus of Elasticity

77.2 GPa

1120 0 ksi

Poisson's Ratio

0.42

0.42

Let' s run through how you would usually define these

3

materials in Abaqus CAE.

1. Startup Abaq us/C AE
> New Mod el Data base > With
2. If you aren 't already in a new file click File
Stan dard /Exp licit Model
ult model called Model-1. Ther e is
3. You see the model tree in the left pane with a defa
it is empty.
no '+' sign next to the Materials item indicating that

1.2 Using a script to define materials 3

Contut 111i0.1i%otions

+/
~jj

4. Double click the Materials item. You see the Edit material dialog box.

._.,,.r ,; ...... ,.... '

.. .....

-

4 A Taste of Scripting
5. Name the material Titanium
6. Click General> Density.

Qcnstty
Oepyor

Begularization
!,lser Mat~ri~l
Usec Defined f ield
User Qutput Vari~bf~

7. Let' s use SI units with MKS (m, kg, s). We write the density of 4.50 glee as 4500
kg/m3• Type this in as shown in the figure.

--~-~-~-•_I__M
__«_h_in_i_ca_l__!h
__~_m_•_l__~
__~
_______________ _________~l lo~8el
Density ·-- - - - - - · - - · - - - -

IEJ Use t«npttature·dependent dna
Numbtt of fitld variables:
, Data ·-·

l

0 ~~

- - - - - - - - - - · - - ·- -·

I
8. Then click Mechanical> Elasticity> Elastic

IMechanical

~eneral
- Density -

!!::! Usettt
Numbeto
Data
I - ,i. _ .

(

iJ..
1

!henna!

e.hsstk ity
Damag~ for

! [P~~~

Qther
~

D!,Lctile Metals
..
Oamag,e for Traction Separation laws
..
Damage for Fi,bet-Reinforced Composites ..
Damage for Elastomers
DeformBtion Plasticity
~am ping
~ansion

irittle Cracking
Eos

Pastic
J::typerela_stic
Hypel{oam

,Low Density Foam
HypQelostic

eorous'8astic
~scoelastic

1.2 Using a script to define materials 5
9. Type in the modulus of elasticity and Poisson's ratio. The Young's modulus of 116
GPa needs to be written as 116E9 Pa (or 116E9 N/m2) to keep the units consistent.
The Poisson's ratio of0.34 remains unchanged.

Elostic ... ·•· ·

Typco juottopic
IEJ ll•• temporotur..dep.,.dtnt dou

Number of fitld varitbl"" L~
Moduli timt$Uie (for viscot:lnticity): '
lfing·ttnn
-~

El No compreuion
la No ttn<ion
( D11J ·-·-··- - - - · --·-·-····--·-..·--·--------·- · · - -----

i

Voung"s
Modulll:s
1 )_ -·---- 116£9
I

:

Po!ssoa's
~io

.

--1034·-.--:1

I
1-t o.K.£,1

Lc&nal,j

.........._,__________ · ····- .•. ....... .... ................. _,
-.

10. Click OK. The material is created and the model tree on the left indicates the
presence of I material with the number 1 in parenthesis. Clicking the '+' symbol
next to it reveals the name of the material Titanium, and double clicking it will
reopen the Edit material window.

I€a Model Oataba~

kiJ :

ltJ t\ ·'tJ

l ~ Model$ (1)

i

t
1

ll

El Model·l

HI!• Parts

t~ ~erTals(ij
:

~ Sections

i-. Profiles
$ii Assembly
! $A Steps (1)

!

I

~~

tre

1b

Field Output Requests
History Output Requests
Time Points

l "'

lP

~

~
~

~

~

1

11. Repeat the process for the other 2 materials, AISI 1005 Steel and Gold. Remember
to keep the units consistent with those used for Titanium.

6 A Taste of Scripting
12. When you're done the model tree should appear as it does in the figure with the 3
materials displayed.
Model

I Rtsuttsj Material library J

l€9 Model Database
-l ~ Models (1)

8

Modtl·l

.
j

I· I!, Parts

~ Matetials (3)

1~1 ! rtl ~ ~
~•

'1
,'i
.

lt- ~1005~~1

~

Gold
·· Titanium

"'

~ fl•

I

Sections

t· ~ Profiles
That wasn't too hard. You defined 3 materials and you can now use these for the rest of
your analysis. The problem is that you will need to define these materials in this manner
all over again whenever you open a new file in Abaqus CAE to start a new study on your
products. This is a tedious process, particularly if you have a lot of materials and you
define a large number of their properties. Aside from consuming time there is also the
chance of typing in a. number wrong and introducing an error into your simulations,
which will later be very hard to spot.
One way to fix this situation is to add your materials to the materials library. Then you
could import the materials every time you created a new Abaqus file. Another way to do
this would be in the form of -a script. You type out the script once and place if in a file
with the extension .py and every time you need these materials you go to File > Run
Script...
Let's put a script together. Start by opening up a simple text editor. My personal favorite
is Notepad++. his free and it has got a clean interface. It also displays line numbers next
to your code (making it easier to spot debugging errors) and can color code your script by
auto-d~tecting Python from the file extension. On the other hand you may wish to use one
of the Python editors from Python.org such as Python Win. The idea is to create a simple
text 'file, and then save it with a .py extension.

1.2 Using a script to define materials 7
Open a new document in Notepad. Type in the following statements:

Save the file as 'chlexl.py' . Now open a new file in Abaqus CAE using File> New.
Click on File > Run Script... The script will run, probably so fast you won't notice
anything at first. But if you look closely at the Materials item in the model tree you will
see the number 3 in parenthesis next to it indicating there are 3 defined materials. If you
click the '+' sign you will see our 3 materials.

lia Model Database
9J
I

l

!

l
l

l

I
ll
J

·==

~-odeJJ_g)j

1~1

!

ffJ ~ ~
l _.

8' Model·l
~ IJ. Parts
El C!i Materials (3)
AISI 1005 Steel

f

r Gold

j LTitanium

r- •
r· ~

Sections

Profit~

In fact if you double click on any of the materials, the Edit Material window will open
showing you that the density and elastic material behaviors have been defined.
The script file has perfonned all the actions you usually execute manually in the GUI. lt's
created the 3 materials in turn and defined their densities, moduli of elasticity and
Poisson's ratios. You could open a new Abaqus/CAE model and repeat the process of
running the script and it would take about a second to create all 3 materials again;

8 A Taste of Scripting
If by chance you tried to decipher the script you just typed you may be a little lost. You
see the words 'density' and 'elastic' as well as the names of materials buried within the
code, so you can get a general idea of what the script is doing. But the rest of the syntax
isn't too clear just yet. Don't worry, we'll get into the details in subsequent chapters.

Is writing a script better than simply storing the materials in the materials library? Well
for one, it a1lows you to view all the materials and their properties in a text file rather
than browsing through the materials in the GUI and opening multiple windows to view
each property. Secondly you can make two or three script files, one for each type of
simulation your routinely perform, and importing all the required materials will be as
easy as File > Run Script. On the other hand if you store the materials in a material
library you will need to search through it and pick out the materials you wish to use for
that simulation each time.
At the end of the day it is a judgment call, and for an application as simple as this either
· method works just fine. But the purpose of this Example 1.1 was to demonstrate the
power of scripting, and give you a feel for what is possible. Once you've read through the
rest of the book . and are good at scripting, you can make your own decision about
whether a simulation should be performed with the help of a script or not.

. You've seen how a script can accomplish a simple task such as defining material
properties. A script however is not limited to perfonning single actions, you can in fact
run your entire analysis using a script without having to open up Abaqus/CAE and see
the GUl at all. This means you have the ability to create parts, apply materia] properties,
assign sections, apply loads and constraints, define sets and surfaces, define interactions
and constraints, mesh and run the simulations, and also process the results, all through a
script. In the next example you will write a script that can do all of these things.

Example 2.2 - Loaded cantilever beam
Just as in the previous example, we will once again begin with demonstrating the process
in Abaqus/CAE and .then perform Jhe same tasks with a script. .We're going to create a
simple.:..canti.J.eV.eL·heam· 5. .meters··long ~~~-~~'Cr{}SS' .section ef side 0.2 m made of
-'·- NISI ·JOO'S"Steet/ Being a cantilever this beam ·WiU-.be -clamped at one end. That means
· that"it can neither translate along the X, Y or Z axes, nor can it rotate about them at that

1.4 Running a complete analysis through a script 9
fixed end. This is also known as an encastre condition. A:. pr.essure· load of I 0 Pa will
cause the beam to bend downwards with the maximum deflection experienced the free
end.
Field output and history output data will be collected. Field output data provides
information on the state of the overall system during the load step, such as the stresses
and strains. Instead of using the defaults, we wi.ll instruct Abaqus to track the stress
components and invariants, total stTain components, plastic strain magnitude, translations
and rotations, reaction forces and moments, and concentrated forces and moments.
History output data provides information on the state of a smaller section such as a node
at frequent intervals. For this we will allow Abaqus to track the default variables for
history output.
We will mesh the beam using an 8-node linear brick, reduced --integration element
(C3D8R) with a mesh size of0.2. We"..wi41"e-reate.a.job, submit it, and inspect the results.
Let's start by performing these tasks in the GUI mode using Abaqus CAE.
I. Startup A baqus/CA E
2. If you aren't already in a new file click File> New
3. In the Model Database panel right click Model-1 and choose Rename •...

11·

(l~

eT.u; ._c.m... c...,.."
Models

-l!i t.
)t
.•

S

p

ji.A
A S

Copy Model...

£dlt Attributts-

Edit !Ce:ywords...
Ret~ame...

Delete....

•~ F

Set·AsRoot

·!it 1-

Expand. All Under

bT

•

Od

Arnt'lml'rlll'!"mRn:::mml'llrm:--r'fi

'f1 lntereaions
4. Type in Cantilever Beam. Model-:-1 will change to Cantilever Beam in the tree.

10 A Taste of Scripting

5. Double click on the Parts item. The Create Part dialog is displayed. Name the part
Beam. In the Modeling Space section, choose 3D. For the Type choose
Deformable. For Base Feature choose Solid as the shape and Extrusion as the
type. Set the Approximate Size to 5. Press Continue..

N•m~ IBNm
I Modding Space
~~ ~[)

?

20 Pf1n1r (1) ~m~~ _I

Type -

l

'I

•··

I @ De!ormable

1r Options . .........~,.
!
:

. 'd
v""" o·•scren ng•

If

!

:

l

I~

I

I

None available
I <0
L~-~u~an _ll__ --- -An11ytit1J rigicl

(" Base feature

r Shape ·--

I
i'Ii

@ Solid

(O Shdl

LO Wire

I

· - - - · ---.
Type

··- - .

!l

.
1

!

Revolution

jl ~

!L~~~-----.
.....

'--~·--·~

Approximate.siz.e:

I Continue-.)

rs=

j.,.,YI)~d~j

11

I;
!:;
~~

l

6. You find yourself in the Sketcher window. Select the rectangle tool from the
tooJbar. For the first point click on (0.1 , 0.1 ). For the second point click on (0.3, 0.1). A rectangle is drawn with these two points as the vertices.

1.4 Runnin g a complete analysis through a script 11

~

rvr;

r·n~Hr~,-,_~--~-+--+-~--b--r-TI--,_~--

+--+--r;

. ,.". ~t

·

~~ JJU

l·l p~ H--1---+ --+---+- -+--t--i- -i!---i-- +--+---+ ---+---+ ---H
ri.'· :::
H--JI-,_ -+---+

n

A nev acxlel database has been ereat.od
~ The oaodcl "llodo l - 1 " bo" bee~ cr""Lod .
\-=, A n"v llcxlcl d a tGbolse nas been C%106tod .
~
acxlcl "llodel-1" has been e1-eal ed .

:The

7. Click the red X button at the bottom of the window indicating End proced ure and
then click Done.
8. In the Edit Base Extrusion window set Depth to 5.

r End Condition
1

Type:

Blind

11 Depth: [5"- J

I '·. --···
---- ····-- ----·
If' Options ·······-- ._, · ,. ·

Ij

--

1

Note: Twist and draft cannot be specified together. ;

l1 !El Include twist,. pitch:

I•

···

·

'· (Dist/Rev)

ILIE!_I_n~lucfe~~ft. ~n~le: ......_.......,..~ {Degrees)
I

---'

I
9. Click OK. You will see a 3D rendering of the part Beam you just made. The Parts
item in the model tree now has a sub-item called Beam.

12 A Taste of Scripting

i€11 Modd O•tot..sfl :

GJ ~

~~McxfdsOl

~~ s;:&mm
Motorial•

,,

~:::::

' ejl
!I toe.
I ·!:r

I

· f£

'j

b

l

1

~

l~>

Assembly

Strps (1)
Field Output RoquHistoty Output Rtque>ts

:g

TimePoinb

ll;p AU A<bptive Mod> Con!

•

1

j

I1

V

: 12ii. U!J!
: ~. : .!!,_ 8-q

r~

!

~El

· I ~.ih.

U lnter1ctions
!fl lntttaction Proptrties
tf Contact Contsols

.-. -ia

Conact lniti11iali<H1s

~-

n

A nev •txiol do.t <>bMe ho:s been creo.ted .
The aodel • Hodel-1' hu been c rttated .
, A nev .ooeJ da.tab<t.se ha.s been ONO&ted ,
~ The •odel "llodel - 1' ho.:s been c re4ted .
~

10. Now would be a good time to save your file. Choose File > Save. Select the
directory you save your files · in and name this file 'cantilever beam.cae' (or
something more creative ifyou prefer)

~'d=
lleq=============;;;;~JL. SJK I

file Name:
file Filttr. Modtl Dltlbne r.cn"J

I

Gk

C..nctl '

I

11. Double click the Materials item in the model tree. Name it AISI 1005 Steel. Set
General > Density to 7872 kg/m3• Set Mechanical > Elasticity > Elastic to a
Young's Modulus of200E9 N/m2 and a Poisson's Ratio of0.29.

1.4 Running a complete analysis through a script 13

-j ·i
t
:~~. -------~~.1
.
1~_1 1
.

:~:;l6ch~~·

.

:i

1Nl,

El•>~k -

1

c:J

Type: jlswopic

I• ~ion>!

f

El u~ ltmp.m...r..dtpend..-1 dol•
Nvmt>t<olfotldvarilblts: ~
Modulttimt f.alot (fot viscodasticit)')l Lon
- g-.1.,
---r
t:J
'"'I
.
r-1

0: No comptession
f:J Norension

o.c.

-- -

v.....,·.

ro~uon·.

200E9

·f·

-----·- l.~e·~:L___

GBJ

12. Click OK. The material is added to the model tree.
13. Double clicluluthe·Sectimas item..Tile Create Section window is displayed. Name
it Beam SedMm. '-Set the Category to ·Solid and the Type to Homogeneous ·if this
isn' t already the default.

; Nam~ ~_Se_ct_io_n__________~
~

Typ~

Category

;, @S
I'd
.:,
0 01

I:

Homogeneous
, Generalized plane strJin

~l ~ (!:) Shell
,·j ·, If-."\
v Beam

1·

. Eulerian

Composite

·. ' ,.
.
·'
,. l ..~ f'luld

1

1 i. ~ Other

I: .__________.

I

:i·,

I
14. Click Continue. The Edit Section window is displayed with the Name set to Beam
Section and Type set to Solid, Homogeneous. Under the Material drop down menu
choose AISI 1005 Steel which is the material you created a moment ago.

14 A Taste of Scripting

Name: Beam Section

Type: Solid. Homogeneous

Material; jAIS11005 Steel

[El Plane stress/strain thickness:

15. Click OK. You will notice that the Sections item in the model tree now has a subitem called Beam Section.
16. Next we need to assign this section to the part Beam. Expand the Parts (1) item by
clicking the + symbol next to it to reveal the Beam item. Expand that too to reveal a
number of sub-items such as Features, Sets, Surfaces and so on.
Model LResults !· Material Libral)' ,I

leJ Model Oat~base
~ ~. Models (1) _

! El [Cantilever Beaiij
'i t:llb
. Palts (1)
:,1

ISBeamJ! .
e'3

i
:

.

~ Slcins

1
1

0 Stringers
[ Z· Section Assignments

I

:
!.'

1

I
j
!

Features (1)
Sets

~Surfaces

j

!.;

..b

. . Composite L.ayups
1
Gl ~ Enginwing Features
I
j t. !b. Mesh (Empty)
~ ~ Materiel5 (1)
~ Sections (1)
I L Beam Std:ion
~ • Profiles

$

~

j

I

17. Double click the sub-1t~in Section Assignments: You wi11 see the hint Select tbe
regions to be assigned a section below the viewport. Hover your mouse over the
beam in the viewport and when all its edges light up click to select it.

1.4 Running a complete analysis through a script 15

.

~ ------------------==~------------------===-·~~~

, • [B~ Stlt<tthcregionotobunigntdose<tion @3

!s.ts...l

~uu.o

11 nev •odel datob<ose has beeo crea~ed.
Tbe •odel ·llodel-1· bu been created .

A ncv aodol do.tobo:sc bo~ been croot.ecl.
~ The •odel "llodet-1· has been ~eel.

18. Cl.ick Done. You see the .Edit Section Assignment window. Set the Section to
Beam Section which is the section you created in steps 13-15.

Rtgion
Region: (Picked)
. Section

I;Section: rB_ea_m_ St!_ct_io_n_ _....,@l

li'

Not!!: list conuins only

·

Type

~~~~~..!

~ctions

applicabletothesel~ed

regions.

Solid, Homogentous

l l.Ma_:e"al: _Al~.l005 St~

~

L§!J!!ceiJ

19. Click OK. The Section Assignments item now has 1 ·sub-item Beam Section
(Solid, Homogeneous). The part in the viewport changes color (to green on my
system) indicating it has been assigned a section.
~
20. Let's import the part into an assem,bly. Click the + symbol next,.. to ' the· Assembly
item in the model tree and double-click the Instances sub-item. You see the Create

16 A Taste of Scripting
Instance window. For Parts, Beam is the only option available and it is selected by
default. For the Instance Type choose Dependent (mesh on part).

- Jn!bnaTypo - - - - -·- - @\ Oop011dt111 (l'>esl\010 pori)
el lndes><ndent (met. on insblncd
Not~ Todunge-aGtp~inuance's

21. Click OK. The Instances sub-item of the Assembly item now has a sub-item of its
own called Beam-1. You can right-click on it and choose Rename•... Change the
name to Beam Instance.
22. Next we create a step in which to apply the load. Notice that Jhe Steps item in the
model tree already has the Initial step. Double-click the ,Steps
item. The Create
'
Step window is displayed. Name the step Apply Loa~- :F{)r ~.nsert new step after
the only option is Initial and it is selected by detall.k. -s,t the Procedure type to
General from the drop down menu. In the list scroll down till you see Static,
General and select it.
/

/

1.4 Running a complete analysis through a script 17
>1-.....1::!&-

•

il!:J ·~re~te,

Name: [AP;i;'L;;;;d
Insert new step after
Initial

·

I

Procedure type: General

BJ

Dynamic. Explicit
Dynamic, Temp-disp, Explicit
Geostatic
Heat transfer
Mass diffusion

23. Click Continue.... You see the Edit Step window. For the description type in Load
is applied during this step. Leave everything else set to the defaults.
24. Click OK. You'll notice that the Steps item in the Model Database now has 2 steps,
Initial and Apply Load.
25. Let's now create the field output requests. Right click4Re ~Field Output Requests
item in the model tree and choose Manager. You see the Field Output Requests
Manager window with an output request F-Output-1 created in the Apply Load
step.

I

Activ•te

I

~vat•)
Variabl6:

Prestltcted dtfaults

' s,tahl$:
Cruted in this step
, ~------------~----------------------

.

:.:.;,c

L0~.~··Jl

I €opx;··d

l~!l!11.m~l

IQt1~~-~l

L!>jsmiss I

18 A Taste of Scripting

Click the Edit button. You notice a number of output variables selected by default.
On top of the list of available output variables you see a comma separated listing of
the ones selected which by default reads CDISP, CF, CSTRESS, LE, PE, PEEQ,
PEMAG, RF, S, U,.
26. From the Strains remove PE, Plastic strain components, PEEQ, Equivalent
plastic strain and LE, Logarithmic strain components. Add E, Total strain
components. Remove Contact entirely. The variables you are left with are
displayed above as S,E,PEMAG,U,RF,CF

i' Output V1riJ~ ·-- · ·~
(t) Sdt<tftom liv bdcw

· ·-·--·· --- ···--···-· ·· ·---·

e Pt.,dtcttdddauhs e;l All 0 £dhariablt<

lS.EPEMAG.U.Rf,O:

I, ~
-~ .-

____] :.

.Sit.....

·:l .

• .SVfll. E.

~
!:., _,
.,

ins
Tot.tl Jbain components

, /

!

~ Vf. Vis.cou~ .s.t,.in •n the elntit•Yiscou1 nttwotk'
~ Pf. Pf•~tic st111n <ompontnts
1r:J VEEQ.. t.qu~lftmYiKOU!t Jt,.in in tht. tt•'Stic·'lliuout ndwotlr

I!·,[
;

1EJ PE£Q. Equivolcnt plutic stt1io

l!l PEEQT. (qulvilcntpfutic sttfln ~UOI'\: CIJt'iron 1od concJtt.'t)

~ p~~:"m~m~tpladicwaln

_

1

••

, .' ~ 1

: ~ Nd:« Enor JndiUCOIJ art not w•i.l•blt wtltn OomMn i$ \Vhoje Modd otltmildi~n.

Out,>ut at.,..._ t...n\ 1r1d lqatd •«tit>n pGinb:
'

*U.edd.....,

0 Spt<ify. Cc:

•:i. ;)tj

fl)ltttk.d'e-loal cootdinate.dile«ions -..men tv-1ilabt~

27. Click OK. Then click Dismiss... to close the Field Output Request Manager
window. In the model tree right click the F-Output-1 sub-item of Field Output
Requests and rename it Selected Field Outputs.
28. Let' s move on to history output requests. Rig~t cHck History Output Requests in
the model tree and choose Manager. You see the History Output Requests
Manager window. It is very similar to the Field Output Requests Manager
window.

1.4 Running a complete analysis through a script 19

I Edit... I
I Move Left I
!Move. Righrj

I Activat! j
I Oe.activ~te I
Step procedure: Static. General
Variables:
Prese!ected defaults
Status:

/

Created in thi~ step

I Delete.•• I

L~~py... I

I Di_!miss I

;r

29. [fyou click Edit you can see the variables selected by default. We're going to leave
the default variables selected so Cancel out of the Edit History Output Requests
window. In the model tree right click the H-Output-1 sub-item of History Output
Requests and rename it Default History Outputs.
30. lt's time to apply loads to the beam. In the model tree double click-the Loads item.
You see the Create Load window·. Name the load Uniform Applied Pressure. For
the step select Apply Load. Under Category choose Mechanical. And from the
Types for Selected Step 1ist choose Pressure.
f D €rtate LoacJ
Name 'lu-n·,ro-rm
-Ap_p_lied
--P-res-su_r_e ________,

Ell

. Step: [A~~ly load

: Procedure: Static, Gl!neral
. <"
'

Cat~O'Y --..·-·-- (
1

i @ Mechanical
() Thermal
•

1

()

Acoustic

,:;. Fluid

Types for St!ected Stq>

I, r - - -- -- - - -j1 C~ncentrated force

j

Moment

'

1 Shell edge load
l Surface. traction

l Pipe pressure
,: v Mm diffu~ioo !I Body force
0

.

I

Electrital

e Other

I

ll l ine loacl
i

~~

Gravity
Bolt loJd

-,

20 A Taste of Scripting
31 . Click Continue.... The viewport displays a hint at the bottom Select surfaces for
the load. Hover your mouse over the top surface of the beam till its edges light up.
Click to select.
Modd ··Res..lts

!E'1Mode1Dol1bos<@; G;J ~

l!f History Output Request• (l)

1

Module:

' e Default Hl<tory Output•
'
·b Time Points
f ~ ALE Ad1ptiva t.Aeoh Con.U.ints

f,Q'i:l

I{

· Q::

Contact lnitialiutions

t

•

lntetJdio ns

lnteroction Properties
Conlllct Conttols

I1-·

~==~~~==~~~==~--------~----~

'9 ~U!I

~

~ Constraint<

Y

Connedor~ons

Fields
1- ~ Ampliwd..

~· !!:!.lm
J;\;. BCs

tI

1!:.

Ptedefined Fields

~
. Rtmeshin9Rules

•

u.:':__,.~~:~~
--":,;.:;
' ;.;;'"~~!!...___;:._]

~rvl

!EIIf8 Selertsulfacestolthelood ~~~

32. Click Done. You see the Edit Load window. For Distribution choose Uniform
from the drop down list. For Magnitude enter a value of 10 Pa (just type in 10
without units).
1:•- Editl~~ . 1
l Name: Uniform Applied Pressur!
l
! Type: Pressure

! Step:

I

.
Apply Load (Static, Gmeral)

! Region:

(Picked)

I

I
I Magnitude: E

Distribution: Uniform

l

Amplitude:

I(Ramp)

_8 [§f~~.,l

I

liiJ [&r~te...l

I

l

----~====~-ii--~====~
1~&;,.9$\
lt...~,J

33. Click OK. The viewport updates to show the pressure being applied on the top
surface with the arrows representing the direction. Also the Loads item in the Model
Database tree now has a sub-item called Uniform Applied Pressure.

1.4 Running a complete analysis through a script 21

34. The n~t step is to apply the boundary conditions or constraints. Double click on the
.BCs item in the Model Database tree. You see the Create Boundary Condition
window. Name it Encastre one end. Change Step to Initial. Under Category
choose Mechanical. From the available options for Types for Selected Step choose
Symmetry/Antisymmetry/Encastre.
I

I Name: I(ncastre one end

I Step: I
~-

liJl

Initial

I

Procedure:

h Category · · 1. Types for Selected Step ·
i 'l
;
!1! @ Mechankal ·j'
I 0 Fluid
Displacement/Rotation
fl

Symmelty/Antisyrnmdry/Entd~trc

1

j ·l IF~ Other

! iv

l1 j

!l I

!~ '

'1!i
h
111
\-' --

'I

V~ocity/Angular velocity

Accel~tion/An9ular acc~~ation

.I , Connector displacem ent
i

:

Connector velocity
Connector acceh!:ration

!-

I Gontjnue... I

22 A Taste of Scripting
35. Click Continue .... The viewport displays a hint at the bottom Select regions for the
boundary condition. Hover your mouse over the surface at one end of the beam till
its edges light up. Click to select it.

36. Click Done. You see the Edit Boundary Condition window. Choose ENCASTRE
(Ul = U2 = UJ = URl = UR2 = UR3 =0). This will clamp the beam at this end.
~~~~a"ft~""~':'f:!·r~·~~11~~il1
Nam~

Encastre one end

Type:

Symme:tty/Antisymmetry/Encastre

Step:

Initial

Region: (Pidced)
(5) XSYMM (Ul = UR2 = UR3 = 0)

® YSVMM (U2 = URl = UR3 = 0)
0 ZSVMM (U3 = URl :: UR2 :: 0)
(f) XASYMM (Ul = U3 = URl :: 0; Abaqus/Standard only)

® YASYMM (U1 = U3 = UR2 :: 0; Abaqus/Standard only)
® ZASYMM (Ul = U2. :: UR3 = 0; Abaqus/Stand11rd only}
® PINNED (Ul : U2. =U3 : 0)
@ ENCASTRE (Ul = U2 = U3 = URl "' UR2 = UR3 = 0)

37. The viewport will update to show the end of the beam being clamped. Also the BCs
item now has a sub-item called Encastre one end.

1.4 Running a complete analysis through a script 23

38. If you haven't been saving your work all along now would be a good time to do it.
We' re going to mesh the part and then run the simulation.
39. [n the model tree expand the Parts item again, and then the Beam sub-item. You see
..;~·~Mesli" (Empty) sub-item. at-the bottom. Double-click it. You are now in mesh
mode and yq,u .notice;the toolbar next to the viewport changes to provide you with
mesh tools.
40. Using the menu bar go to Me~h > ~lement Typ_e. The Element Type window is
displayed. For Element 'Library choose' Stamtarif!, for- Geometric Order choose
Linear, and for Family choose 3D Stress from the list. Leave everything else at the
defaults. You will notice the description C3D8R: An 8-node linear brick, reduced
integration, hourglass control near the bottom of the window.

24 A Taste of Scripting

Element libwy

- -

@ Standard () Explicit

_. _ _

i, r:Family_ _

~---------------~

i

..J

@

Acoustic

Goomt«ic Order ~~·,
_., o:
a. Q d ~: 1
\~ unNr v
ua roue 1

Cohesive
Continuum Shell
...; -:.-::::;.- --:::::::---R-

'-------"'·----

H~ I•Wedge--1 fttcj

!El Hybrid formulation 0
r-

Reduced integration

IEJ lncompatible mod~

Element Controls --·--· ·----·-·· ..----·-·--· - ···· ........ · ......... ·......- ... - - - -·-·--·--------·----......_..

L:._J

HourgiiSs stiffness:

@ Ust dtfault 0 Specify

Viscosity.

@ Uoe dthult

Kinemotic split

@

Second·otder accuracy.

E5 Veo

Oistoltion control:

@ Use default ID Yes 0 No

0

Av~•9• strain

Specify

r

D

i~

L

E5 Orthogonal (5 Controid

.

@ No

---

....

-·

C308R: An8-nodt ijnear bricl(. reduced integratiol\ hourglus cortrol.

Note: To soled an olement.hapt for mtshing.

soled "Meoh·>Controls"from the main mtnu b11.

41. Click OK.
ruM~-!.
42. Then use the menu bar to navigate to Seed > l!al:i. The Global Seeds window is
displayed. Change the Approximate global size to 0.2, which is the width of our
beam. Set the Maximum deviation factor to 0.1 .

: Sizing Controls

. ;

I

~ Approximate global siz~ Ol

'--------'

l

' ~ Curvature control

_,j •

Maximum deviation factor (0.0 < h/L < l.o): ":lo.,....l_ _ _
(Approximate numb~ of elements pet cird~ 8)
Minimum sizdactor (as a fraction of global sizf):

@ Use default (Ol)

<Cl Sp~ify (0.0 < min < 1.0) ~

43. The beam in the viewport updates to show where the nodes have been applied.

1.4 Running a complete analysis through a script 25

.
~~
44. Then from the menu bar go to Mesh > l!aJ:t. You see the question OK to mesh the
part? at the bottom of the viewport window. Click on Yes. The part is meshed. The
Mesh item in the model tree no longer has the words (Empty) next to it.

45. Now it is time to create the analysis job.
46. All the way at the bottom of the model tree you see Analysis with the sub-item Jobs.
Double-click on it. The Create Job window is displayed. Name it
Cantilever BeamJob. Notice that there are no spaces in the name. Putting a space in
the job name can cause problems because Abaqus uses the job name as part of the
name of some of the output files such as the output database (.odb) file. Source is set
to Mo~el and the only model you can select from the list is Cantileve r Beam.

26 A Taste of Scripting

!;! Create Job

j

Name: CantileverBeamJob

I

li1J

Source: j Model

Cantilever Beam

I Continue... 11 . Cans el

J

47. Click Continue .... You see the Edit Job window. In the Description textbox type
in Job simulates a loaded cantilever beam. Set the Job Type to Full Analysis.
Leave the other settings to default. Notice that in the Memory tab there is an option
for Memory allocation units. On my system the option selected is Percent of
physical memory, and for the Maximum preprocessor and analysis memory my
system defaults to 50°/o. You might wish to play with these numbers if your
computer has insufficient resources.

Name: CantileverlleamJob
Model: Cantilever Beam

Analysis product Abaqus,IStandard
Description: !Job simulates a loaded cantilever beam

.

Job Type

' @ Full analysis

! £C) Recover (&plicit)

:0

I

Restart

----· --- ............---·-'
-...•.-·-----·----.

Run Mode ~--·-·-

B :: ·:

I

:@Background ei Queue:a: • :v,~·:,Y ~Type:
'-

.....

- -

~-- ---·--~·

__ __. . . .

,.. Submit Time · - -

1

- ·-· ........ -

JE)Ho!tnarnt";

... · - - - · - - - . . . . .

.....

....

•·

® Immediately
( ) Wait~hrs.~ min.
0

llr.p,..j

f!·s ;.<Cf~..
__ ,_- .1._~_:_,. .*-

At; L; '

-

.

-- -·

..

-

-~·-·---------

J

1.4 Running a complete analysis through a script 27
48. Notice that the Jobs item in the model tree now has Cantilev erBeamJ ob listed (you
might have to hit the'+' symbol to see it). Right-click on it and choose Submit.
49. The job starts running. You see the words (Submit ted) appear next to its name in
parentheses, then a few seconds later you see (Runnin g) and when the simulation is
complete you see (Comple ted).
50. Right click on Cantilev erBeamJ ob (Comple ted) and choose Results. You see the
undeformed shape.

.~..

......liiiU.4.

~C..•I~'

ooe v,.w....aw..u.DM•
~-.:a...,
t"'N'"M"I

1!

bt•OIII

MtH..Wfw..._.. ~. , I!C~4· t..ID-·l

...... LoH4I ~ .......

, .......

;..,t:... • •.000

S.l J.•

u

lf1••-·

16. ~1&

t..c•• O.,Jt•l ,...,. tDi l

WD ~ ~--------------------------~~~~==~--~.-~
-··
-

- -- - - -- '

{tj[gj OragtMmouse inniowpartt<uototetileviow

Routian<tnlitf: [ Sd«t...

llu..:omubl

ils

SlloflltM

51. Click the Plot Deforme d Shape button in the tool bar to the left of the viewport. You
will see your deformed beam. Of course the deformation has been exaggerated by
Abaqus. You can change that if you wish by going to Options > Commo n••. if you
wish.

28 A Taste of Scripting
You have created and run a complete simulation in Abaqus/CAE. It was a very basic
setup, but it covered all the essentials from creating a part and assigning sections and
material properties to applying loads and constraints and meshing. Now we're going to
watch a script perform all the same actions that we just did.
Open up a Jext editor such as Notepad++ and type in the following script.

1.4 Running a complete analysis through a script 29

30 A Taste of Scripting

1.4 Running a complete analysis through a script 31

32 A Taste of Scripting

Typing out the above code might be a real pain and you'll likely mistype a few variable
names or make other syntax errors creating a lot of bugs. It might be a better idea just to
use the source code provided with the book- cantilever_beam.py.
Open a new Abaqus model. Then go to File > Run Script. The script will recreate
everything you did manually in Abaqus/CAE. It will also create and submit the job so
you will probably notice the analysis running for a few seconds after you run the script.
You can then right click on the 'CantileverBeamJob' item in the model tree and choose
Results to see the output. It will be identical to what you got when performing the
simulation in the GUI.

In the example we did not use the script to accomplish anything that could not be done in
Abaqus/CAE. In fact we first performed the procedure in Abaqus/CAE before writing our
script. But I wanted to drive home an important point: You can do just about anything in
a script that you can do in the GUI. Once you're able to script a basic simulation, you'll
be able to move on to more complex tasks that would really only be feasible with a script
such as making automated decisions when creating the simulation or performing
repetitive actions within the study.
As for the script from this example, we're going to take a closer at it in Chapter 4. Before
we can do this you' re going to have to learn a little Python syntax in Chapter 3. But first
let's take a look at the different ways of running a script in Chapter 2.

-2
Running a Script
This chapter will help you understand how Python scripting fits into Abaqus, and also
point out some of the different ways a script can be run. While you may choose to use
only one of the methods available, it is handy to know your options.

A few years ago Abaqus existed purely as a finite element solver. It had no preprocessor
or postprocessor. You created text based input files (.inp), submitted them to the solver
using the command line, and got text based output files. Today it has a preprocessor
which generates the input file for you - Abaqus/CAE (CAE stands for Complete Abaqus
Environment), and a postprocessor that helps you visualize the results from the output
database - AbaqusNiew er. When you use Abaqus/CAE, the actions you perfonn in the
GUI (graphical user interface) generate commands in Python, and these Python
commands are interpreted by the Python Interpreter and sent to the Abaqus/CAE kernel
which executes them. For example when you create a new material in Abaqus/CAE, you
type in a material name and specify a number of material behaviors in the ' Edit Material'
dialog box using the available menus and options. When you click OK after this,
Abaqus/CAE generates a command or a number of commands based on what you have
entered and sends it to the kernel. They may look something like:
beamMaterial = beamModel.Material(name='AISI 1ees Steel')
beamMaterial .Density(table =((7872, ),
))
beamMaterial . Elastic(table= ((2eeE9, e . 29), ))

In short, the Abaqus/CAE GUI is the easy-to-use interface between you, the user, and the
kernel, and the GUI and kernel communicate using Python commands.

34 Running a Script

Abaqus/CAE
GUI

Python
commands

Python
Interpreter

Abaqus/CAE
Kernel

The Abaqus Scripting Interface is an alternative to using the Abaqus/CAE GUI. It allows
you to write a Python script in a .py file and submit that to the Abaqus/CAE Kernel.

Abaqus Scripting Interlace
(Python Script)

Python
commands

Python
Interpreter

Abaqus/CAE
Kernel

A third option is to type scripts into the kernel command line interface (CLJ) at the
bottom of the Abaqus/CAE window.

Abaqus CLI
(Command Line Interface)

Pvthon
commands

Python
Interpreter

Abaqus/CAE
Kernel

The Abaqus/CAE kernel understands the model and creates an input file that can be
submitted to the solver. The solver accepts this input file, runs the simulation, and writes
its output to an output database (.odb) file.

Abaqus/CAE
Kernel

Input File

Abaqus Solver
(Standard/Explicit/CFD)

~

Output Database
(.odb)

You have_the option of running a script from with in Abaqus/CAE using the File > Run
Script... menu option. You can do this if your script irrespective of whether your script
only performs a single task or runs the entire simulation.

2.4 Running a script from the command line 35

·.

v~.l Qunnin.! .a·scriH't in GUI to ei"ecute a ,single or multiple tasks
-..... .
If you have a script that performs a single independent task or mu1tiple tasks assuming
some amount of model setup has already been completed or will be performed later, you
need to run that script in Abaqus/CAE. For instance, in Example 1.1 of Chapter 1, we
wrote a script which only creates materials. On its own this script cannot run a
simulation, it does not create a part, assembly, steps, loads and boundary conditions and
so on. However it can be run within Abaqus/CA E to accomplish a specific task. When we
ran the script using File > Run Script••• you noticed the model tree get populated with
new materials. You could then continue working on the model after that.
~~=

~~·

~~:..10.~·

•

Such scripts will not run as standalone from the command line, or at least they won' t
accomplish anything.

-.-. simulation
23.2. ··· ·Running a sc~~t in G"UJ":to e;X.ecute an entire
If you have a script that can run the entire simulation, from creating the part and materials
to applying loads and constraints to meshing and running the job, one way to run it is
through the GUI using File > Run ... This was demonstrated in Example 1.2 of Chapter I.
However such a script can also be run directly from the command line.

~

'

~

"~~~

~

~

·

·~

Path
The path is a list of directories which the command interpreter searches for an executable
file that matches the command you have given it. It is one of the environment variables
on a Windows machine.
The directory you need to add to your path is the 44Command s" directory of your Abaqus
installation. · By default Abaqus Student Edition v6.1 0 installs itself to directory
4
' C:\SIMUL IA\Abaqus ,. It likely did the same on
your computer unless you chose to
. install it to a different location during the installation procedure. One of the subdirectories of 44C:\SIMUL IA\Abaqus , is "Commands", so its location is
"C:\SIMULIA\Abaqus\Commands". This location needs to be added to the system path.

36 Running a Script

Check if Abaqus is already in the path
The first thing to do is to check if this location has already been added to your path as
part of the installation. You can do this by opening a command prompt. To access the
command prompt in Windows Vista or Windows 7, click the Start button at the lower left
corner of your screen, and in the ' Start search' bar that appears right above it type ' cmd'
(without the quotes) and hit enter. In Windows XP you click the Start button, click ' Run',
and type in ' cmd' and click OK. You will see your blinking cursor. Type the word 'path'
(without the quotes). You wil'l see a list of directories separated by semicolons that are in
the system path. If Abaqus has been add to the path, you will see
"C:\SIMULIA\Abaqus\Commands" (or wherever your Commands folder is) listed among
the directories. If not, you need to add it manually to the path.
Add Abaqus to the Path
Adding a directory to the path differs slightly for each version of Windows. There are
many resources on the internet that instruct you on how to add a variable to the path and a
quick Google search will reveal these. As an example, this is how you add Abaqus to the
path in Windows Vista and Windows 7.

I. Right click My Computer and choose Properties
2. Click Advanced System Settings in the menu on the left.
3. In the System Properties window that opens, go to the Advanced tab. At the
bottom of the window you see a button labeled Environment Variables... Click
it.
4. The environment variables window opens. In the System variables list, scroll
down till you see the Path variable. Click it, then click the Edit button. You see
the Edit System Variable window.
5. The variable name shall be left at its default of Path. The variable value needs to
be modified. It contains a number of directories, each separated by a semi colon.
It
may
look
something
like
C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem. At the
end
of it,
add
another
semi
colon,
and
then
type . in
C:\SIMULIA\Abaqus\Commands. So it should now look something like
C:\Windows\System32\;C:\Wiodows\;C:\Wiodows \System32\Wbem;C:\SIM
ULIA\Abaqus\Commaods. C lick OK to close the window, and click OK to
close the Environment Variables window.

2.4 Running a script from the command line 37
6. Now if you go back to the command prompt and type path, you see the path has
been updated to include Abaqus

Running the script from the command line
Now that Abaqus is in the system path, you can run your scripts from the command line.
First you navigate to the folder containing your script files using DOS commands such
as cd (change directory) command. For example, when you start the command prompt, if
your cursor looks something like C:\Users\Ga utam>, and your script is located in the
folder C:\Users\Ga utam \Desktop\Ab aqus Book, then type in
cd C:\Users\Gautam \Desktop\Abaqus Book

and press Enter. Your cursor will now change to C:\Users\Ga utam\Deskto p\Abaqus
Book>
You are now in a position to run the script with or without the Abaqus/CAE GUI being
displayed.

2.4~.1 : Run .tlie~ript from the command line without the GUI
Type the command to~----~~run the script-----without the Abaqus/CAE GUI. The exact command
varies depending on the version of Abaqus.
In the commercial version of Abaqus you would type
abaqus cae noGUI= "cantilever_be am.py"

In the student edition (SE) version 6.9-2 you would type
abq692se cae noGUI="cantilever_beam.py"

In the student edition (SE) version 6.10-2 you would type
abq6102se cae noGUI="cantilever_beam.py"

Notice the difference in the first word of all these statements. If you are not using either
of these versions the command you use will be different as well. To figure out exactly
what it is, go to the 'Commands' folder in the installation directory and look for a file
with the extension '.bat'. In the commercial version of Abaqus this file is called
'abaqus.bat', hence in the commercial version you use the command 'abaqus cae

38 Running a Script

noGUI="cantilever beam.py". In Abaqus 6.10-2 student edition, the file is called
'abq6102se.bat'
which
is
why
the
command
'abq6102se
cae
noGUI="cantilever_beam.py" has been used. Depending on the name of your file, change
the first word in the statement.

When you run your scripts in this manner, you will not see the GUI at all. While the
script is running, you will notice that the cursor is busy and you cannot type in any
other commands at the prompt. This is because we have used the built in method
waitForComp]etion() in the script which prevents the user from executing other DOS
commands while the simulation is running. We will take a look at this statement
again a little later, just be aware that if we did not include the waitForCompletion()
command in the script, the prompt would continue to remain active even while the
simulation is being run. And if you find yourself running batch files, or linking your
simulations with optimization software such as !Sight or Mode1Center, this
knowledge will come in handy.

abq6182se cae script="cantilever_beam.py"

2.5 Running a script from the command line interface (CLI) 39

When you run your scripts in this manner, Abaqus/CAE will open up and the script is
run within it. In addition the cursor will remain busy (as seen in the figure), and will
only be released once you close that instance of Abaqus/CAE.
1>.

'#!.

;

"'

.f

':'

'

•

,

',.;

~

I

"c:

...'!-.

:•

t

2~5 Runn~g a scriJ>l!!om tb~ c-ommand Ji:Oe interface (c;LI)
The kernel command line interface is the area below the viewport in Abaqus/CAE.
Chances are the message area is currently displayed here. If you click the box with '>>>'
on it you will be able to type in commands. We will use this to test a few different Python
commands in the next chapter. For now l wish to make you aware that it is possible to
run a script from here using the execfile() command.
·

'\,

Type in
Execfile('cantile ver_beam . py')

The file you've passed as an argument to execfile() needs to be present in the current
work directory for Abaqus, otherwise you need to spell out the full path such as:
Execfile('C;\Users\Gautam\Desktop\ Book\cantilever_b eam.py')

By default the work directory is C:\Temp although you can change it using File > Set

Work Directory ..
If the file is not in the current work directory and you did not specify the full path,
Abaqus will not find the script and will display an IOError.
IOError : (2, 'No such file or dir ectory' , ' cantilever_beam.py))

40 Running a Script

>>> execfile('cantilever_beaa .py')
IOError : (2 . 'No such file or di~tory' . 'cantilever_beaa . py')
I,L.---11 >» I

If the file is present in the work directory, or you specifY the full path, the script executes
successfully.
>»

.

>>> execfile('eantilever_beaa . py')
Global seeds have been assigned .
200 eleaemts have been gemerated on part. : Beaa
Job BeaaDeflectionJob: Analysis Input File Processor ooapleted successfully .
Job BeaaDeflectionJob: Abaqus/Standard COilpleted successfully .
Job BeaaDeflectionJob coapleted successfully .

>»

l

·-------··-----

' "..........._.,~1

This chapter has presented to you some ofthe various ways in which scripts can be run.
You may choose the appropriate method based on the task at hand, or feel free to go with
personal preference.

-3
Python 101
,'·In
· ' t rod' uc. ti. on . ., .
'

.

. .

:i~ •• _....,:,.,..t.air.~""'ffi,..,n,.. ~~ ~

•

. , .

\\ ,

~~~.....,J;~----,......_,_

In the cantilever beam example of Chapter 1, we began by creating the entire model in
Abaqus/CAE. We then opened up a new file and ran a script which accomplished the
exact same task. How exactly did the script work and what did all those code statements
mean? Before we can start to analyze this, it is necessary to le~m some basic Python
syntax.lfyou have any programming experience at all, this chapter should be a breeze.

.

Python is written in the form of code statements as are other languages. However you do
not need to put a semi-colon at the end of each statement. What the Python interpreter
looks for are carriage returns (that's when you press the ENTER key on the keyboard).
As long as you hit ENTER after each statement so that the next one is on a new line, the
Python interpreter can tell where one statement ends and the other begins.

In addition statements within a code block need to be indented, such as statements inside
a FOR loop. In languages such as C++ Y9ll use curly braces to signal the beginning and
end of blocks of code whereas in Python_:you indent the code. Python is very serious
about this, if you don't indent code which is nested inside of somethi~g ·eJse (such as
statements in a function definition or a loop) you will receive a lot of error messages.
Within a statement you can decid~ how ~uch whitespace you wish to leave. So a=b+c
can be written as a = b + c (notice the spaces between each character)

In some programming languages such as C++ and Java, variables are strongly typed. This
means that you don' tjust name a variable; you also declare a type for the variable. So for

42 Python 101

example if you were to create an integer variable 'x' in C++ and assign it a value of 5,
your code would look something like the following:
int x;
X=5;

However Python is n~t strongly typed. This means you don't state what type of data the
variable holds, you simply give it a name. It could be an integer, a float or a String, but
you wouldn't tell Python, it would figure it out on its own. So if you were to create an
integer variable x in Python and assign it a value of 5 you would simply write:
X=5

In addition Python doesn 't mind ifyou try to do things like multiplying a whole number
with a float. Some languages object to this type of mixing and require an explicit cast.
Python is also able to recognize String variables, and concatenates them if you add them.
So a statement like
greeting = 'h' + 'ello'

stores the value 'hello' in the variable 'greeting'.
Let's work through an example to understand some of these concepts.
Example 4.1- Variables

Open up Abaqus CAE. In the lower half of the window below the viewport you see the
message area. If you look to the left of the message area you see two tabs, one for
"Message area" and the other for "Kemal Command Line Interface".

l
1

r·l!::. l'rodefinal Fields
1-'ll Remtsh"'g fWios

Le. Sketch..

~ Annoutions

all An•tysis
[-.!.Jobs

Click the second one. You see the kernel command prompt which is a ">>>" symbol.
Type the following lines, hitting the ENTER key on your keyboard after each.

3.3 Variables and assignmen t statements 43

The number 40 is displayed. Since we set length to I 0 and width to 4, the area being the
product of the two is 40. ~~-:pr.Htt.:sta.tement displays the-value stored in the area
variable. The follo~ing image.d-ispl~ys what you should ·s~e on your own screen.

I
etl

r~ Remeshing Rules

.

l..

'

C. Slcttches

.

'

.

,)'.;l i-.~~.; ~..>: ~c.. ·._...., ... ... . .. . . ..: ~··.-:.,· ~· . . -,: ..,: ...
t!!.~if::i~;~;;@,t~~::: ·:·i~~·, -'ll~P~~·"'i~tE~~i~··f..~

· ~ Annotations
Analysis
·A Job$

fr.'i<f-~.YS~;.$~'S.;~•r.;.,!:·~;. ~,~~..2~~Jf'i:~;~~~.

>» length • 10
>» width • 4
>> > area • length
» > print are"
40

* vidth

So you see the Python interpreter realized that the variables 'length' and 'width' store
integers without you needing to specify what type of variables they are. In addition when
assigning their product to the variable 'area', it decided for itself that 'area' was also an
integer.
What if you had combined integers and floats? Add on the following statements:

The output is 140.0 . Note the ".0" at the end. Since your height variable was a float
(number with decimal point in layman terms), the volume variable is also a float, even
though two of its factors 'length' and ' width' are integers.

r::1 >>> length • 10
vidt:h • 4
>» area • length • vidth
~ >» print o~
t=J 40

~ - 1 >>>
,__....,•...,
:1

........._..... >>>- depth a 3. 5
>>> volu•e • length
>>> print volu•e
140 . 0 .

>»I

*

vidth

*

depth

44 Python 101
Lefs experiment with Strings. Add the following lines

The output is "GautamPuri". Notice that we did not tell Python that ' first_name' and
'last_name' are String variables, it figured it out on its own. Also when we added them
together, Python concatenated them together.

n

»>
>»
>>>
~>~ >>>
'----.I >»
~

first_na•e • "Go-uta••
last naae • •Puri•
na.e-· first_na•e + last_na•e
print naae
GautaaPuri

I >»

As you can tell from this example, not having to·define variable types makes it a lot less
painful to type code in Python than in a language such as C++. This also saves a lot of
heartache when dealing with instances of classes so that you don't have to define each
variable as being an object of a class. If you don't know what classes, instances and
objects are, you will find out in the section on "Classes" a few pages down the line. But
first Jet's talk about lists and dictionaries.

Arrays are a common collection data type in just about every high level programming
language so [expect you've dealt with them before and know why they're useful. You
aren't required to use them to write Abaqus scripts, but chances are you will want to store
information in similar collections in your scripts. Let's explore a collection type in
Python known as a List.
·1.n a, list y.ou..stor.e.multiple .elements or ~a~'.:\ vatues ~nd can refer to them with the name of
· ...~ the list vru:ia,bfe-~followed by an index. in square 'brackets []. T_be lowest index is 0. Note
that you ·can store all kinds of data:types, such as · integers~ float~, Strings, all in the same
list. This is different from languages such as C, C++ and Java where all array members ,
must be of the same data type. Lists have many built-in functions, some of which are:
•
•

Ien() - returns the number of elements in the list
append(x)- adds x to the end of the list making it the last element

3.4 Lists 45

•
•

remove(y) - removes the first occurrence of y in the list
pop(i) - removes the element at index [i] in the list, also returns it as the return
value

Let's work through an example.
.F,:xample 4.2 - Lists

In the ' Kernel Command Line Interface' tab ofthe lower panel of the window, type in the
following statements hitting ENTER after each.

Your output will be as displayed the following figure. Note that the lowest index is 0, not
1, which is why random_stuftiO] refers to the first element 'car'. The Ien() function
returns the number of elements in the list. The append() function adds on whatever is
passed to it as an argument to the end of the list. The remove() function removes the
element that matches the argument you pass it. And the pop() function removes the
element at the index position you pass it as an argument.

46 Python 101
I' '

>>> randoM_stuff • ['car' . 24 . 'bird' . 7S . S. 44,

» > print rando,._stuff ( 0)

'golf ' )

car

>>> print randoa_stuff (l)
24
..._--..~-<> » print rando•_stuf f
['car'. 24 . 'bird' . 78 . 5 , 44 , 'golf')
>>> print len(randoa_s tuff)

6
>>> rando•_stuff . insert(2 . 'ooaputer')

>> >print len(randoa_st uff)

7

>>> print randoa_stuf£

[ ' car' . 24 . 'ooaputer' , 'bird'. 78 . 5 . 44 . 'golf']
>» randoa_stuf .f . append(29)
>» print len(rando!ll_s tuff)

>> > print randoa_stuff
['car ' . 24. 'coaputer' , 'bird '. 78 . 5.

» > print randoJLstuff . inclex( ' qolf'}

u . 'golf'. 29)

6

>>> randoM_stuff .-reaove(24)
>>> print randoJLstuff
['car' . 'coaputer' , 'bird' . 78 . 5. 44 . 'golf • . 29]
>>> reaoveQ_var • randoa_stuff .pop(2)
>>> print reaoved_var
bird
>>> print randoa_stuff
['car' . 'coaputer' . 78 . 5. 44 . 'golf ' . 29)

>» I

.

Dictionaries are a collection type, just as lists are, but with a slightly different feel and
syntax. You do not really need to create your own dictionaries in order to write scripts in
Abaqus, you can accomplish most tasks with a list, but y~u never know when you might
prefer to use a dictionary. More importantly though, Abaqus stores a number of its own
constructs in the form of dictionaries, and you will be accessing these regularly, hence
knowing what dictionaries are will give you a better understanding of scripting.
Dictionaries-are-sets of.key;~alue .pairs. To access a value, you use the key for that value.
This i$ analogous to using an index position to access the data within a list. The
difference is that keeping track of the key to access a value may be easier in a certain
situation than remembering the index 1ocation of a value in a Jist. Since there are no index
positions, dictionaries are lillorder~d.
-:To remove a: key:vatue pair, you '.!Se the del:.~ommciD.<L~rremoye ·a1Hfie key:value pairs,
you use the clear command.

3.5 Dictionaries 4 7
Aside: If you've worked with the programming language PERL, dictionaries are very
similar to the hash collections. If you're coming from a Java environment,
dictionaries are similar to the Hashtable class.
An example should make things clear.

Example 4.3 - Dictionaries
In the 'Kernel Command Line Interface', type in the following statements hitting ENTER
after each. You will see an output after each print statement.

Here names_and_ages is your dictionary variable. l_~)t you .store 3 .keys, ' John', ' Rahul'
and 'Lisa'. You store their ages as the values. This-way if you wish to access Lisa's age,
you would write names_and_ages[' Lisa'].
..
.
The del command removes the key:value pair 'John' :23, leaving only Rahul and Lisa.
The clear command removes all the key value pairs leaving you with an empty dictionary
{}.
Note that since the dictionary is unordered, the first statement could instead have been
written as
>>> names_and_ages = {'Rahul': l5, 'Lisa•:ss, 'John':23}

and it would have made no difference since your values (ages) are still bound to the
correct keys (names).
The following image displays what you should see.

48 Python 101
>»

!!I J >»
» > print

t--__.

I))J 23
~

>»

L-----,115

naaes_~nd_ages • {'Jphn' : 23 .
naaes_and~ages( ' John')

'Rahul ' :15. 'Lisa' : 55}

print naaes_and_ages['Rahu l']

>>> print naaes_and_ages
{ ' Lisa' : 55 , 'John' : 23 , 'Rahul ' : 15}
>» del naaes_and_ages{ •John' )
>>> print naaes_and_ages
{'Lisa' : 55 , 'Rahul ': 15}
>>> naaes_and_ages . clear()
>>> print naaes_and_ages
{}

»>

So bow does Abaqus use dictionaries?
You're probably wondering when you would actually use dictionaries. You will be using
them all the time, and already did so more than once in the cantilever beam example of
Chapter 1 (Example 1.2), except you didn't know it at the time. Here' s a block of code
from the example.

1

···#--::-::-::-===~~~~-~---~ ----

#

-------- ~ --------- ---_·
_-- ----·-···-·-·--··------·-··. .· · ··- ·

Create the model

mdb . models.c~angeKey{fromName='Model-1',

beamModel = mdb . models['Cantilever Beam']

toName='Cantilever Beam')

~::. :-. : . : :. : . :. ----------------------------------------- -- -:_.:::..________
.:::

Look closely at the statement
beamModel = mdb .models('Cantilever Beam']

Here you s~e.the model.database· 'm~b'. h~:a:-propercy-calle~ ' models' . This property is a
diCtionary object contajning:..a,key;:valoe pair for each model you create. The model name
itself is the 'key', and the value is an i{lstance ofthe model object.
You know that the syntax to access a value in a dictionary is dictionary_name['key'}. So
when you want the script to refer to the cantilever beam model you say
models['Cantilever Beam'}.
To be a little more precise, .models in not exactly a dictionary object but a subclass of a
dictionary object. What does that mean? Well, to put it simply, it means that the
programmers at Abaqus created a new class that has the same properties and methods as

3.6 Tuples 49
dictionary, but also has one or more new properties and methods that they defined. For
example the changeKey()_· m.e~hod tha~ changes the name of the key from 'Model- I' to
'Cantilever Beam' is not native to Python dictionaries, it has been created tiy
·programmers at Abaqus. You don't have to worry about how they did it unless you are a
computer science buff, in which case google 'subclassing in Python •. As far as a
user/scripter is concerned, the ' models' object works similar to a dictionary object with a
few enhancements. Also in Abaqus these enhanced dictionaries are referred to as
'repositories'. You will hear me use this word a lot when we start dissecting scripts.
Let's look at another block of code from Example 1.2.

I

# ------------ -------- -------------- - -------- --- ------ ---

# Create the history output request

I

# we try a slightly different method from that used in field output request
#create a new history output request called 'Default History Outputs' and assign
both the step and the variables
beamMod~l.HistoryOutputRequest(name='Default History Outputs', createStepName='Apply
Load .~ , ?variables=PRESELE_
CT)
#now delete the original history output request 'H-Output-1'
del beamModel.historyOutputRe quests('H-Output-1']
# ---- -------------- --------- --- ---- -- ------------ -- -----

Look closely at the statement .
del

beamModel . hi storyOutputRequests['H-Output-1~]

Notice that your model beamModel has a dictionary or ' repository' (subclass of a
dictionary) .c.a_lled. historyQutputRequests. One of the key:value pairs has a key ' HOutput-1 ', and is referred io as historyOutputRequests['H-Output-11. In the Abaqus
Scripting Interface you will often find aspects of your model stored in repositories. For
the record, in this statement the 'H-Output-1' key:value pair in the repository is being
deleted using the del command.

We've covered lists and dictionaries so far. Tuples are a third type of collection tool in
Python. They are similar to lists, except once a tuple is created it cannot be edited. You
cannot add on elements: commands such as append() do not work on it. And you cannot

50 Python 101
delete elements either using the del command. To access the elements of a tuple you use
the same index notation as you do for lists. Let's work an example.
Example 4.4 - Tupies
Jn the 'Kernel Command Li.ne Interface' type in the following statements hitting ENTER
after each. You will see an output after each print statement.

A tuple called random_items is created which contains integers, floats and Strings. Note
that you use arcs for parentheses, whereas if random_ items was a list you would instead
use square brackets as:
random_items

= [

' Mercedes', 'airplane' , 5, 17 .6, 'hi']

The following image displays the outputs of the above statements:
/ /;

>>> rando-_ite•s• ('Keroedes' . 'airplane' . 5. 17 . 6. ' hi ')
,~---...::....~ 1 >>> print randoa_i teas( 0 l
Kercedes
>>> print rando•_ite•s£21
5

>» print randoJa_iteas
('Mercedes' . ' airplane' . 5. 17 . 6 . 'hi')
>»

So how does Abaqus use tuples?
We ll just as in the case of dictionaries, you have actualJy already used tuples in the
cantilever beam example of Chapter 1, you just didn't know it. Let's look at a block of
code from that example.
·-··;---~=-~-~-.:-=-=---~==-=-=-===-==-=-=-===---=-::~-=-=-:~-=---=-=-.:---------------·---·-----,1
# Apply pressure load to top surface

First we need to locate and select the top surface
# We place a point somewhere on the top surface based on our knowledge of the
geometry
1 top_face_pt_x = 8.2
top_face_pt_y = 8.1
I1 top face_pt z = 2. 5
#

I
'!

1

I
I

l1

3.7 Classes, Objects and Instances 51

Here you create 3 variables top_face_pt_x, top_face_pt_y and top_face_pt_z, and then
store them in a tuple called top_face_pt. At this point you do not need to understand why
the above statements were used, we will examine these statements in subsequent
chapters. I only wish to point out what tuples are and the fact that you will be using them
regularly when writing scripts.

classes. You often create an "instance" of a. class and then~aooe&S· the built-in .metheds
which belong to the class or assign properties using'it. So it's important for you to have
an understanding of how this all works.
Python is an object oriented language. If you've programmed in C++ or Java you know
what object oriented programming (OOP) is all about and can breeze through this section.
On the other hand if you're used to procedural languages such as Cor MATLAB you've
probably never worked with objects before and the concept will be a little hard to grasp at
first. (Actually MATLAB v2008 and above supports OOP but it's not a feature known by
the majority of its users).
For the uninitiated, a class is a sort of container. You define properties (variables) and
methods (functions) for this class, and the class itself becomes a sort of data type, just
Jike integer and String are data types. When you create a variable whose data type is the
class you've defined, you end up creating what is called an object or an ins~ce of the
class. The best way to understan~ this.iS:thr.ough.an-examp!e-...

Example 4.5- 'Person~ class
In the following example, assume we have ·a class called .~.Person.': Tiiis class has sorrw
. properties, such as . 'weight', 'heigh(, 'hair'. color and so on. This class also has some
·. methods such· as ·'exercise()' and · 'dyeHair()' which cause the person to lose weight or
change hair color.
Once we have this basic framework of properties and methods (called the class
definition), we can assign./8?_actual-·person to this cJ~~· We can say Gary is a 'Person'.
This mean&·GaJ¥;:has:properties such-as height, weight and hair color.. We can set Gary's

52 Python 101
height by using a ·statement such as Gary.height = 68 inches. We can also make Gary
exercise by saying Gary.exerciseO which would cause Gary.weight to reduce.~ is~
object of type Persol.!)or Gn instance of the Person clasP
Open up notepad and type out the following script

_

,J

---·---··:---·-..--.................. ...,,.............
4

tllass Person:
height = 69
weight =· 160
hair_color =

•

. :...· ·1

.~i
...

i

.j

" black~

def exercise(self):
self.weigHt

=

self.weight - s

·-I

def dyeHair(self.. new_hair_color):
self.hair_color = new_hair_color
, print ·~ake 'Gary' an instance of the class
Gary = Person()
1

: pr.int
pr:l!nt
·pr:l!nt
l print

"Print Gary's height ..
Gary.height .
Gary.weight
Gary.hair_color

J

.,

'Person!~

I

.

print "Change Gary' s height to 66 fnches by· setting the height _e;roperty to 66" ·
Gary.height = 66
·

.I
.I

print "Make Gary exercise so he loses 5 lbs by calling the-. exercise() method"
Gary.exercise()
·
·
·
print "Make Gary dye his .hair blue by calling the dyeaair· method and passing
an vumenr
Gary.dyeHair('blue')

.,

blu~ as

ll

j'
.I
~

Open a new file in Abaqus CAE (File > New Model Database > With
Standard/Explicit Model). In the lower half of the window, make sure you are in the
" Message Area" tab, not the "Kernel Command Line Interface" tab. The print statements
in our script·will display here in the "message area" that' s why you want it to be visible.

I

s: I

3.7 Classes, Objects and Instances 53
Run the script you just typed out (File > Run Script.•. ). Your output will be as displayed
in the following figure.
The Jtodel "·Model-1" has been created .

Define the cl~ss ca.lled 'Person'
M~ke 'Gary' e.n in$t.&nce of the cl~ss 'Person'
Print Gary's height . veight and he.ir eolor
60
160
bl&.ek
Che.nge Gary's height to 66 i nches by settin9 the height property to 66
Make Gary exercise so lle loses S lbs by calling the exercise( ) ~aethod
Make Gary dye h is hair blul{ by calling the dyeHair •ethod and passing blue as an

Once again print Gary ' s hei ght . veight. and hair color
66

argUllent

155

blue

Let's analyze the script in detail. The first statement is

-------------- -

1 print "Define the class called 'Person'"

~---------··-..·····- ----.....--- - ·--··-----·--- - -·----- ·---------

_ _____]

This basically prints "Define the class called 'Person"' in the message window using the
'print' command. Hence that is the first message displayed. The following statements
define the class:
-,

...O
H__,__,,.,. __ H_

----~RMo~O~

I class Persorl': .

I
·I

height = 60
weight = 160
hair_color = '!black"

I

def

1

I
l
L

exercise(s~.!!) :·
self . we~ght

.

.

= _.s elf . we1ght

5

def dyeHair(self, new_hair_color):
-~eif. h~ir:=:~~_!?._r = new hair colo.:.............--....................

A class named 'Person' has been created. lt has been given the•properties (variables)
'height\ 'width' and 'hair col or', which have been assigned initial values of 60 inches,
160 lbs, and the color black.
In addition two methods (functions) have been defmed, 'exercise()' and 'dyeHair()'. The
'exercise()' method causes the weight of the person to decrease by 5 lbs. The ' dyeHairQ'
function causes 'hair_ color' to change to whatever col or is passed to that function as the
argument 'new-hair- color'.

What's with the word ' self'? In Python, every method in a class receives ' self as the first
argument, that's a rule. The word 'se'if' refers to the instance of th~ class which will be

54 Python 101

created later. In our case this will be 'Gary'. When we create 'Gary' as an instance of the
'Person' class, self.weight translates to Gary.weight and self.hair_co/or translates to
Gary.hair_color. In object oriented languages like C++ and Java you do not pass self as
an argument, this is a feature unique to tlre Pythons syntax and might even be a little
annoying at first.
r--:------::--- - : - - - : - - - - - - - - - - -- - -- - - -- - - - - -- --

Print "Make 'Gary • an instance of the class 'Person'"
G~~-~- Person(.:....
) - - - - - - - - -- -

- - -- -.,

1
____________________j!

These statements define Gary as an instance of the Person class, and also print a comment
to the message area indicating this fact.
print
print
print
print

"Print Gary's height, weight and hair color"
Gary.height
Gary.weight
Gary.hair color

We then display Gary's height, weight and hair_color which are currently default values.
Notice how we refer to each variable with the -- in~tance name followed by a dot " ."
symbol followed by the variable name. The form~t is l~sJanceName.PropertyName.
These statements make the following lines appear on the screen:

Print Gary ' s height, weight and hair co lor'~
60
160
black
r print· "Change Gary • s height to 66 inches by setting the height property to 66"

Gary.height

= 6{?

l

We now change Gary's height to 66 inches by using an assignment statement on the
'Gary.height' property. We print a comment regarding this to the message area.
print "Make Gary exercise so he loses 5 lbs by calling the exercise() method"
Gary.exercise()

These lines call the exercise function and display a comment in the message area. Notice
that you use the format JnstanceName.MethodNameO. Although we don't appear to pass
any arguments to the function (there's nothing in the parenthesis), internally the Python ·
interpreter is passing the instance 'Gary' as an argument. This is why in the function

3.7 Classes, Objects and Instances 55

definition we had the word 'self' listed as an argument. Why does the interpreter pass
'Gary' as an argument? Because you could potentially define a number of instances of
the Person class in addition to Gary, such as 'Tom', ' Jill', 'Mr. T', and they will all have
the same 'exercise()' method. So then if you were to call Tom.exerciseO, it would be
Tom's weight that would reduce while Gary' s would remain unaffected.
If you look once again at the definition of the 'exercise()' method in the Person class,
you'll notice that it decreases the weight of the instance by 5 lbs. So Gary's weight
should now be 155 lbs, down 5 lbs from before.

---------·--------- ------- ---,
I print "Make Gary dye his hair blue by calling the dyeHair method and pass ing blue as i

l-~~.t:!!Ye!!~~_:.f_~-~-~~-:.2.-..··---··· -· ···-··-··-·--------------·-·--··-···--·-···---·--·-·
an argument"

I

-·--·-·---------··--·-··-----------·-··-------·-----··--·-----·--·---··

These lines call the 'dyeHair()' function and display a comment in the message area. The
difference you notice between the 'exercise()' and 'dyeHair()' functions is that you pass a
hard argument to 'dieHair()' telling it exactly what color you wish to dye the individuals
hair. Internally an argument of 'self' is also passed.
Take another look at the definition of the 'dyeHair()' method in the ' Person' class. You' ll
notice that the variable being passed as an argument is assigned to the 'hair_color' . So
Gary's hair color should now have changed from black to blue.
print "Once again print Gary' s height, weight and hair color"
I print
print Gary.height
Gary.weight
print Gary.hair_color

We print out Gary's height, weight and hair color again to notice the changes. The
' Gary.height' statement was used to reset his height to 66 inches, the 'exercise()' method
was used to reduce his weight to 155 Jbs, and the 'dyeHair('blue')' method should have
changed his hair color to blue. These print statements display the property values in the
message area. The output is what you expect:

Once again print Gary's height, weight and hair color
66
155

blue

56 Python 101

Hopefully this example has made the concept of classes and instances clear to .you.
There's a lot more to OOP than this, we've only touched the surface, but that's because
you only need a basic understanding of OOP to write Abaqus scripts. In none of our
examples will you actually define a new class of your own.
So why learn about cla'sses, objects and instances?
Now that you've understood classes you're probably wondering why I bothered telling
you about them. Well you won't need to define your own classes, but understanding what
they are will help you understand the Abaqus Scripting Interface. lfyou look back at the
cantilever beam script (Example 1.2) of Chapter 1, you'll notice many spots where
instances of a class are created and properties/methods-of the class are.accessed using the
. dot operator '.'
For instance, look at the following chunk of code of Example I .2
# -------------------------- -- -------- -- ----- ----------

# Create the part
import part

l

;~..../_, ·# .a) Sketch the beam cross sec;;tion us:i.ng·\ rectahgl~ 'tool
· beamProfileSk~t~h = beallt!ledel'. Constr~i,_r)edSk.etch( name= ' Beam CS Profile', sheetSize=S)
, beamProfileSketch.recta~(pointl~(e.~.e . l), .

point2=(0.3,-0.1))

~r4he-:statement
'

·beamPrdfileSketch =

beamModeL~i"aihedSketch( ...some

parameters_.)

lt creates a new instance ~f th-~Jass,:~ ~'beam_ProfileSketch'.
This is similar to our example where w~ created an instance called 'Gary' of the 'Person'
class using the statement Gary = PersonO.
Consider the next statement:
beamProfileSketch.rectang le()

..

It calls the 'rectangle()' method of.th~ 'ConstrainedSketch()' .class. This--is similar to our
example · where we called the 'exercise()' method of our instance· 'Gary' using
'Gary.exercise()'.

3.7 Classes, Objects and Instances 57

So you see a basic understanding of classes and OOP helps you understand the script
better. All of Abaqus' s scripting libraries have been programmed in the form of classes
with properties and methods.!So when you want to create something like a sketch, you
need to create an instance of the 'ConstrainedSketch()' object. And when you wish to use
the built in functions such as 'rectangle()'. you need to reference them from an instance
of a class that defines the method. All this makes a lot more sense now that you
understand OOP.
Aside: If you were looking closely at the code statements we just discussed, you might
have noticed that there was a slight difference in syntax between the cantilever
beam example and the 'person class' example. It is a little more complicated;
notice we do not say beamProfi/eSketch = ConstrainedSketchO, instead we say
beamProfileSketch = beamModel.ConstrainedSketchO. So what is going on
here? Well, ' beamModel' is an·instance ofthe ·~models~ . class. And the ' models'
class has a member caned ' sketches' which is a repository of
'ConstrainedSketch()' objects. And it's one of those 'ConstrainedSketch()'
classes that you· are making an instance of. Hence you refer to it with
beamMod