Gettig错误:类型为…的对象没有len()

2024-06-18 05:31:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从Python的NX软件中打开的工作部件文件获取PMI计数,但得到错误:

TypeError: object of type 'NXOpen.Annotations.PmiCollection' has no len()

enter image description here 代码:

^{pr2}$

文档链接:https://docs.plm.automation.siemens.com/data_services/resources/nx/11/nx_api/custom/en_US/nxopen_python_ref/NXOpen.Annotations.PmiCollection.html

等效vb代码:http://nxjournaling.com/content/find-out-if-part-has-any-pmi


Tags: 文件代码com软件部件错误计数annotations
1条回答
网友
1楼 · 发布于 2024-06-18 05:31:35

下面的代码给出了活动部件的PMI计数,并在计数更改时断言(这里是3):

lw = theSession.ListingWindow
lw.Open()
# Custom code starts to get PMI count in part and check
theSession  = NXOpen.Session.GetSession()
theParts = theSession.Parts
theWorkPart = theParts.Work
allPMIObjects = theWorkPart.PmiManager.Pmis
i = 0
for p in allPMIObjects:
    i = i + 1
lw.WriteLine(str(i))
lw.Close()

#if PMI count is changed from 3, raise AssertionError:
assert i == 3

相关问题 更多 >