mymodel = mdb.models[ 'Cube' ] # 获取模型
mypart = mdb.models[ 'Cube' ].parts[ 'Cube' ] #获取part
for ele_index in mypart.elements: #单元循环
ele = ele_index.label #单元编号
node = ele_index.getNodes() #单元节点坐标
Matname = 'Steel' + str (ele) #材料名
mySteel = mymodel.Material(name = Matname) #创建材料
EE = ele * 1000 + 100.E3 # 变化的材料参数 可以是坐标的函数 或者其他
elasticProperties = (EE, 0.3 )
mySteel.Elastic(table = (elasticProperties, ) ) #设置材料参数
sectionname = 'CubeSec' + str (ele)
mySection = mymodel.HomogeneousSolidSection(name = sectionname,material = Matname,
thickness = 1.0 ) #创建section
elements = mypart.elements[ 0 ]
setname = 'set' + str (ele)
region = mypart. Set (elements = mypart.elements[ele - 1 :ele], name = setname)
# 这里elements要为A sequence of MeshElement objects 即类型为tuple
mypart.SectionAssignment(region = region, sectionName = sectionname) #赋材料属性