简体   繁体   中英

Creating a for loop in Python for multiple instances in Abaqus

I am new to coding in Python for Abaqus, and I am trying to create a for loop, where I can create X number of instances based on a part, I have made. Furthermore, I would like to update the naming of the X instances.

Currently, when I manually create four instances based on the part CenMid, the code looks like this

mdb.models[panelName].rootAssembly.Instance(dependent=ON, name='CenMid-1', 
    part=mdb.models[panelName].parts['CenMid'])
mdb.models[panelName].rootAssembly.Instance(dependent=ON, name='CenMid-2', 
    part=mdb.models[panelName].parts['CenMid'])
mdb.models[panelName].rootAssembly.Instance(dependent=ON, name='CenMid-3', 
    part=mdb.models[panelName].parts['CenMid'])
mdb.models[panelName].rootAssembly.Instance(dependent=ON, name='CenMid-4', 
    part=mdb.models[panelName].parts['CenMid']) 

This is the code, I would like to transform to a loop, so that I simply can choose X instances and X instances will be created with the respective name, instead of this "hard coding" solution.

Thank you in advance!

You can either use a for loop with range und adjust the names accordingly or use the names from a list of either by for loop created names or, userdefined names.

Here is a for loop approach

pt_name = 'CenMid'
r_A = mdb.models[panelName].rootAssembly # root assembly
inst_basename = 'CenMid-'
inst_numbers = 5 # number of created instances plus 1

for inst_num in range(1,inst_numbers):
    i_name = inst_basename + str(inst_num) # instance name
    
    r_A.Instance(dependent=ON, name=i_name, 
    part=mdb.models[panelName].parts[pt_name])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM