×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Repeat actions in python code

Repeat actions in python code

Repeat actions in python code

(OP)
Hello!

Let me preface by saying that I am only a beginner when it comes to Abaqus and, until a few days ago anyway, I had no experience with Python coding at all, so the solution to what I'm asking may be very simple but I'm just not seeing it.

What I want to do is that I want to create a number of identical parts (of stirrups, to be specific). I had, maybe naively, thought that maybe this could be done by a for loop, repeating the action for the appropriate number of iterations. I made a code that looked something like this:

CODE -->

for i in range (1,27):
    s1 = mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=0.5)
    g, v, d, c = s1.geometry, s1.vertices, s1.dimensions, s1.constraints
    s1.setPrimaryObject(option=STANDALONE)
    s1.Line(point1=(0.0, 0.14), point2=(0.0, -0.14))
    s1.VerticalConstraint(entity=g[2], addUndoState=False)
    p = mdb.models['Model-1'].Part(name='Stirrup#i', dimensionality=TWO_D_PLANAR, 
        type=DEFORMABLE_BODY)
    p = mdb.models['Model-1'].parts['Stirrup#i']
    p.BaseWire(sketch=s1)
    s1.unsetPrimaryObject()
    p = mdb.models['Model-1'].parts['Stirrup#i']
    del mdb.models['Model-1'].sketches['__profile__'] 

But it only seems to create a Stirrup#i. Is there a way to repeat the creation of the parts using a for loop or is some other function more appropriate?

RE: Repeat actions in python code

You've made a mistake with the variable part name. The hash sign is not a indicator for a variable in python. It is a comment sign, so you should not use it in the actual code.

You have to do it like that

CODE -->

'Stirrup-'+str(i) 
The plus-sign merges strings and the str(i) converts the integer i into a string i.

I would recommend that you assign this to a variable at the beginning of the loop and then use the variable everywhere you want to have the name.

RE: Repeat actions in python code

(OP)
@Mustaine3

Thank you, it seems to work as intended now!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close