提问人:anydel1 提问时间:9/12/2023 更新时间:9/12/2023 访问量:18
如何通过键值删除对象?
How to delete an object by Keyvalue?
问:
我正在使用一个名为 Topologicpy 的 python 软件库。我有 7 个对象。每个人都有一本字典。每个字典都有一个名为“brepStringType”的键,其值为“Face”或“Cell”。我想删除 brepStringType “Cell” 的对象,以便我可以对“Faces”进行进一步的操作。我想概括一下这一点,以便它可以在具有更多面孔和单元格的脚本上工作。
# Retrieve the vertex object list using Graph.Vertices
objectslist = Graph.Vertices(g)
print(type(objectslist))
print(objectslist)
这将返回以下内容
<class 'list'>
[<topologic.Vertex object at 0x00000180C8AA69B0>, <topologic.Vertex object at 0x00000180C8AA6B30>,
<topologic.Vertex object at 0x00000180C8AA74F0>, <topologic.Vertex object at 0x00000180C8AA74B0>,
<topologic.Vertex object at 0x00000180C8AA7470>, <topologic.Vertex object at 0x00000180C8AA6DB0>,
<topologic.Vertex object at 0x00000180C8AA5230>]
for vertexObjects in objectslist:
d = Topology.Dictionary(vertexObjects)
keys = Dictionary.Keys(d)
brepTypeString = Dictionary.ValueAtKey(d, 'brepTypeString')
print(vertexObjects)
print(d)
print(keys)
print(keys[2])
print(brepTypeString)
返回以下内容
<topologic.Vertex object at 0x00000180C8AA69B0>
<topologic.Dictionary object at 0x00000180C8F46D70>
['brep', 'brepType', 'brepTypeString', 'location', 'timestamp', 'x', 'y', 'z']
brepTypeString
Face
<topologic.Vertex object at 0x00000180C8AA6B30>
<topologic.Dictionary object at 0x00000180C6E66DF0>
['brep', 'brepType', 'brepTypeString', 'location', 'timestamp', 'x', 'y', 'z']
brepTypeString
Face
<topologic.Vertex object at 0x00000180C8AA74F0>
<topologic.Dictionary object at 0x00000180C8ED66F0>
['brep', 'brepType', 'brepTypeString', 'location', 'timestamp', 'x', 'y', 'z']
brepTypeString
Face
<topologic.Vertex object at 0x00000180C8AA74B0>
<topologic.Dictionary object at 0x00000180C8A99C70>
['brep', 'brepType', 'brepTypeString', 'location', 'timestamp', 'x', 'y', 'z']
brepTypeString
Cell
<topologic.Vertex object at 0x00000180C8AA7470>
<topologic.Dictionary object at 0x00000180C8F4EA30>
['brep', 'brepType', 'brepTypeString', 'location', 'timestamp', 'x', 'y', 'z']
brepTypeString
Face
<topologic.Vertex object at 0x00000180C8AA6DB0>
<topologic.Dictionary object at 0x00000180C6E66DF0>
['brep', 'brepType', 'brepTypeString', 'location', 'timestamp', 'x', 'y', 'z']
brepTypeString
Face
<topologic.Vertex object at 0x00000180C8AA5230>
<topologic.Dictionary object at 0x00000180C8A9A6B0>
['brep', 'brepType', 'brepTypeString', 'location', 'timestamp', 'x', 'y', 'z']
brepTypeString
Face
# How do I delete all objects with key-value brepTypeString "Cell"?
if brepTypeString == "Cell":
print(brepTypeString)
# del (????)
答: 暂无答案
评论
[vertex for vertex in objectslist if 'Cell' == Dictionary.ValueAtKey(Dictionary.Keys(Topology.Dictionary(vertexObjects)), 'brepTypeString')]
for vertexObjects in objectslist: