简体   繁体   English

如何在Python中创建集列表中的集合?

[英]How to create set from list of sets in Python?

In abaqus Python script, several Plies have a large number of copies, each of which has many fibers. 在abaqus Python脚本中,有几个Plies具有大量副本,每个副本都有许多光纤。 In each Fiber, a set of edges has been selected: App1-1, App1-2, ..., App99-1, App99-2, ..., App99-88. 在每个光纤中,选择了一组边: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. 谢谢。

Code: 码:

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)

I can guess it should be something like this: 我猜它应该是这样的:

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

but I'm not sure about this and I have no idea about correct syntax 但我不确定这一点,我不知道正确的语法

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. 关键是part.EdgeArray类型。 For whatever reason Abaqus requires your edges be supplied within that type, rather than a simple list or tuple. 无论出于何种原因,Abaqus要求在该类型中提供边缘,而不是简单的列表或元组。 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 . Abaqus文档对此不清楚,当您传递边缘列表时,它将失败并出现模糊错误: 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))

For others that may find themselves here - similar types are available for vertices, faces, and cells: part.VertexArray , part.FaceArray , and part.CellArray . 对于可能在这里发现的其他人 - 类似的类型可用于顶点,面和单元: part.VertexArraypart.FaceArraypart.CellArray

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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