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:
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?
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 have to do it like that
CODE -->
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
Thank you, it seems to work as intended now!