如何从Python中的集合列表创建集合? [英] How to create set from list of sets in Python?

查看:140
本文介绍了如何从Python中的集合列表创建集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在abaqus Python脚本中,几个层具有大量副本,每个副本具有许多纤维.在每个光纤中,已选择一组边缘:App1-1,App1-2,...,App99-1,App99-2,...,App99-88.如何创建一个包含所有或部分这些边缘集的新集合?谢谢.

In abaqus Python script, several Plies have a large number of copies, each of which has many fibers. In each Fiber, a set of edges has been selected: App1-1, App1-2, ..., App99-1, App99-2, ..., App99-88. How to create a new set that will contain all or some of these set of edges? Thank you.

代码:

allApps=[]
...
for i in range(Plies):
    ...
    for j in range (Fiber):
        appSet = Model.rootAssembly.Set(edges=
            Model.rootAssembly.instances['Part'+str(i+1)+'-'+str(1+j)].edges[0:0+1], 
            name='App'+str(i+1)+'-'+str(1+j))
        allApps.append(appSet)

我猜应该是这样的:

Model.rootAssembly.Set(name='allAppEdges', edges=.?.Array(allApps))

但是我不确定这一点,我不知道正确的语法

but I'm not sure about this and I have no idea about correct syntax

推荐答案

我简单地测试了以下内容,它对我有用.我认为您可以对此进行调整,以实现您要针对特定​​模型进行的操作.关键是 part.EdgeArray 类型.无论出于何种原因,Abaqus都要求在该类型中提供边,而不是简单的列表或元组.Abaqus文档尚不清楚,并且当您传递边列表时,它将失败并出现模糊错误:功能创建失败.

I tested the following on a simple part and it worked for me. I think you could adapt this to achieve what you're trying to do for your specific model. The key is the part.EdgeArray type. For whatever reason Abaqus requires your edges be supplied within that type, rather than a simple list or tuple. The Abaqus documentation is not clear on this, and when you pass a list of edges it will fail with a vague error: Feature creation failed.

from abaqus import *
import part

mdl = mdb.models['Model-1']
inst = mdl.rootAssembly.instances['Part-1-1']

# Loop through all edges in the instance and add them to a list
my_edges = []
for e in inst.edges:
    my_edges.append(e)

# Create a new set with these edges
#mdl.rootAssembly.Set(name='my_edges', edges=my_edges) # This will fail because my_edges needs to be an EdgeArray
mdl.rootAssembly.Set(name='my_edges', edges=part.EdgeArray(my_edges))

对于可能会在这里找到自己的其他对象-顶点,面和单元格也可以使用类似的类型: part.VertexArray part.FaceArray part.CellArray .

For others that may find themselves here - similar types are available for vertices, faces, and cells: part.VertexArray, part.FaceArray, and part.CellArray.

这篇关于如何从Python中的集合列表创建集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆