🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Python scripting in ABAQUS

User: "Spencer84"
New Altair Community Member
Updated by Jocelyn

I have a python script to create ABAQUS model and run a job.

I want to create a loop over a variable

index=1:1:4,

create four different models and run the four jobs for each model.

A model is named 'Model-1' for instance in the following line:

##-----------------------------------------------------------------------
mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=sqrlen) 
##-----------------------------------------------------------------------

In creating a loop, I create a string as follows: 

##-----------------------------------------------------------------------
index='1'
modelname='\''+'Model' + index+ '\'' 

# Square Part is created <a rel="nofollow" href="https://www.dgcustomerfirst.review/" title="Link: https://www.dgcustomerfirst.review/">dgcustomerfirst</a>
mdb.models[modelname].ConstrainedSketch(name='__profile__', sheetSize=sqrlen)
##------------------------------------------------------------------------- 

When I run the script in ABAQUS, it gives error saying 'Model1'as follows:

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

  File "d:/abaqus_working_directory/scripting_example/simulation/scripting_loop.py", line 22, in <module>
    mdb.models[modelname].ConstrainedSketch(name='__profile__', sheetSize=sqrlen)  #### sqrlen
KeyError: 'Model1'
Exit from main file  [Kernel]: d:/abaqus_working_directory/scripting_example/simulation/scripting_loop.py
##------------------------------------------------------------------------- 

I want to use the string modelname( with value ='Model-1') instead of writing 'Model-1' in the python script

mdb.models['Model-1'].ConstrainedSketch(name=....)
mdb.models[modelname].ConstrainedSketch(name=...)

when it is called.

Any help is deeply appreciated.

Sincerely, Me.

Find more posts tagged with

Sort by:
1 - 1 of 11
    User: "btamas"
    New Altair Community Member

    without the full code, it is hard to tell, what is the exact problem. However 
    KeyError: 'Model1'
    means, that the 'Model1' object is not defined in your dictionary. You have to first create a 'Model1' element, to access its properties:
    <div>mdb.models['Model1'] = <my-abacus-model>
    </div><div>mdb.models['Model1'].ConstrainedSketch(name='__profile__', sheetSize=sqrlen)</div>
    <my-abacus-model> indicates where you should create your model .

    Hope this helps!