Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeat actions in python code

Status
Not open for further replies.

CC21

Structural
Mar 8, 2018
5
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?
 
Replies continue below

Recommended for you

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

Thank you, it seems to work as intended now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor