0

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
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.

2 Answers 2

2

You are mixing two different names, Model-1 and Model1

In your loop creation, include - in the modelname. You can do something like this:

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

# Square Part is created
mdb.models[modelname].ConstrainedSketch(name='__profile__', sheetSize=sqrlen)
##------------------------------------------------------------------------- 

Also, you should use

modelname='Model-' + index

since that will give you a string without the extra quotes.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the reply. Modelname can be anything like 'Square', 'Trapezium-Model' etc... The basic question is how to code the string Modelname so that python can read : mdb.model[modelname].Constrained~~~. etc as mdb.model['Square'].Constrained~~~
@gama I think you missed the point. Your name can not be "anything", it has to be a name that exists and you need to spell it exactly right including a hyphen as needed.
1

don't work with the string names at all. Early in the script define:

 model=mdb.models['Model-1']

then do for example:

 model.ConstrainedSketch..

if you are working with multiple models then similarly create a list of model objects.

1 Comment

Thank you for your help. I solved it in June First week.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.