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

时间:2019-02-26 16:37:04

标签: python

我试图从在NX软件中以Python打开的工作零件文件中获取PMI计数,但出现错误:

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

enter image description here 代码:

lw = theSession.ListingWindow
lw.Open()
theSession  = NXOpen.Session.GetSession()
theParts = theSession.Parts
theWorkPart = theParts.Work
allPMIObjects = theWorkPart.PmiManager.Pmis
count1 = len(allPMIObjects)
lw.WriteLine(count1)
lw.Close()

文档链接: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

1 个答案:

答案 0 :(得分:0)

以下是提供活动部件中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