问题描述
上下文: 我正在尝试在 Abaqus 中制作一个脚本,该脚本将自动在所有面的顶点之间创建分区。分区不会很完美,但用户可以轻松删除多余的分区。
问题:
v1 看起来像一本字典
({'featureName': 'Solid extrude-1','index': 1,'instanceName': None,'isReferenceRep': False,'pointOn': ((10.0,-10.0,20.0),)})
所以我尝试按索引对其进行排序(第 5 行)
如何在 ABAQUS 中获取顶点类型对象的索引,即 'index':1?
>>> p = mdb.models[myString].parts[myPart]
>>> f = p.faces
>>> pickedFaces = f[:]
>>> v1,e1,d1 = p.vertices,p.edges,p.datums
>>> pickedFaces_r=sorted(pickedFaces,key = lambda k:k['index'],reverse=True)
#reverse picked faces due to additional faces and nodes problem
TypeError: 'Face' object has no attribute '__getitem__'
我的调试尝试
>>> print(v1[1])
({'featureName': 'Solid extrude-1','isReferenceRep':
False,)})
#It looks like a dictionary so I thought it was one.
>>> print(v1[1].get['index'])
**AttributeError: 'Vertex' object has no attribute 'get'**
>>> a=v1[1]
>>> print(a.get['index'])
**AttributeError: 'Vertex' object has no attribute 'get'**
>>> print(a.values())
**AttributeError: 'Vertex' object has no attribute 'values'**
>>> print(type(a))
<type 'Vertex'>
解决方法
所有 Abaqus 的内部对象都是专门开发的类,它们可能(在某些方面)类似于标准 Python 类型。例如,正如您发现的那样,如果您尝试打印其中的一些,您可能会得到类似字典的表示,但这并不意味着它是一本字典。
找出可以对对象执行的操作的两种最佳方法是:
- 看看 documentation;
- 使用标准 Python 库中的
dir()
方法。
因此,在您的特定情况下,您可以这样做:
count
另外,这一行是不必要的:
pickedFaces_r=sorted(pickedFaces,key=lambda k: k.index,reverse=True)