首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gettig错误: type...has no len()的对象

Gettig错误: type...has no len()的对象
EN

Stack Overflow用户
提问于 2019-02-27 00:37:04
回答 1查看 318关注 0票数 0

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

代码语言:javascript
复制
TypeError: object of type 'NXOpen.Annotations.PmiCollection' has no len()

代码:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-28 01:35:39

下面的代码给出了active part中的PMI计数,并在count更改时进行断言(此处为3):

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54890167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档