Sei sulla pagina 1di 4

Workshop 7

Creating a Macro and Getting Input Interactively

Goals
When you complete this workshop, you will be able to create and use an Abaqus macro
and requests input interactively using getInput.

Task 1:
Create a macro that adds three materials, in SI units, to Model-1.

Other information

1. Start Abaqus/CAE.
2. Open the Macro Manager (File→Macro Manager).
3. Create a macro named add_SI_Materials in the Work directory. This will limit
access of the macro to Abaqus/CAE sessions started from this directory. For
macros intended to be more widely used, it is often better to store them in the
home directory.
4. Switch to the Property module, and use the Materials Manager to create three
materials with the following properties:

Steel.
Young's Modulus 200 E 9
Poisson's ratio 0.3
Density 7800
Yield Stress, Plastic Strain 400 E 6, 0.00
420 E 6, 0.02
500 E 6, 0.20
600 E 6, 0.50

Copper
Young's Modulus 110 E 9
Poisson's ratio 0.3
Density 8970
Yield Stress, Plastic Strain 314 E 6, 0.00

© Dassault Systèmes, 2019 Introduction to Abaqus Scripting


W7.2

Aluminum
Young's Modulus 70 E 9
Poisson's ratio 0.35
Density 2700
Yield Stress, Plastic Strain, Temp 270 E 6, 0, 0
300 E 6, 1, 0
243 E 6, 0, 300
270 E 6, 1, 300

5. Stop recording.
6. Exit Abaqus/CAE (do not save changes).
7. In an editor, open the file abaqusMacros.py. Review the file and close it when
completed.
8. Start Abaqus/CAE. Create a new model named Model-2, and run the macro.
Confirm that the materials have been added to Model-1. How can you get the
material from Model-1 to Model-2? What could you do to the macro to create this
material data in the current model?

Note: You will use the file called abaqusMacros.py again. You may want to
create a backup copy at this time.

Task 2:
Modify the material library macro that you created in Task 1.

1. In an editor, open the file abaqusMacros.py.


2. At the start of the function named add_SI_Materials, add a line to get the model
name from the user using getInput. The getInput function should prompt with
the name of the last model in the model repository.
Hint: Use mdb.models.keys()[-1] to get the name of the last model .
(This will only get the last model if the models are numbered in order).
3. Replace instances of 'Model-1' with the name obtained from the user.
4. Save the file, and exit the editor.
5. Start Abaqus/CAE. Create a new model named Model-2, and run the revised
macro. Use the name of the new model. Confirm that the materials have been
added to the new model and not to Model-1.

© Dassault Systèmes, 2019 Introduction to Abaqus Scripting


Workshop 7 Answers

Creating a Macro and Getting Input interactively

Task 1:
Create a macro that prompts the user for the name of the model and adds three materials,
in SI units, to the model.

Answers

from abaqus import *

def add_SI_Materials():

import material

m = mdb.models['Model-1'].Material('Steel')
m.Elastic(table=((200.0E9, 0.3), ))
m.Plastic(table=((400.E6, 0.0), (420.E6, 0.02),
(500.E6, 0.2), (600.E6, 0.5)))
m.Density(table=((7800.0, ), ))

m = mdb.models['Model-1'].Material('Aluminum')
m.Elastic(table=((70.0E9, 0.35), ))
m.Plastic(temperatureDependency=ON, table=((270e6,0,0),
(300e6,1.0,0),(243e6,0,300),(270e6,1.0,300)))
m.Density(table=((2700,), ))

m = mdb.models['Model-1'].Material('Copper')
m.Elastic(table=((110e9,.3),))
m.Plastic(table=((314e6,0),))
m.Density(table=((8970,),))

If you have trouble completing this workshop, the file


ws_scr_abaqusMacros_1_answer.py contains the answer to the workshop. It is
provided for your convenience and must be renamed abaqusMacros.py before it may be
used.

© Dassault Systèmes, 2019 Introduction to Abaqus Scripting


WA7.2

Task 2:

from abaqus import *

def add_SI_Materials():
"""
Add Steel, Copper, Aluminum in SI units
"""

import material

name = getInput('Enter model name',


mdb.models.keys()[-1])

if not name in mdb.models.keys():


raise KeyError, 'mdb.models[%r] not found' % (name)

m = mdb.models[name].Material('Steel')
m.Elastic(table=((200.0E9, 0.3), ))
m.Plastic(table=((400.E6, 0.0), (420.E6, 0.02),
(500.E6, 0.2), (600.E6, 0.5)))
m.Density(table=((7800.0, ), ))

m = mdb.models[name].Material('Aluminum')
m.Elastic(table=((70.0E9, 0.35), ))
m.Plastic(temperatureDependency=ON, table=((270e6,0,0),
(300e6,1.0,0),(243e6,0,300),(270e6,1.0,300)))
m.Density(table=((2700,), ))

m = mdb.models[name].Material('Copper')
m.Elastic(table=((110e9,.3),))
m.Plastic(table=((314e6,0),))
m.Density(table=((8970,),))

If you have trouble completing this workshop, the file


ws_scr_abaqusMacros_2_answer.py contains the answer to the workshop. It is
provided for your convenience. Note that it must be renamed abaqusMacros.py before it
can be used.

© Dassault Systèmes, 2019 Introduction to Abaqus Scripting

Potrebbero piacerti anche