我试图从用Python打开的NX软件中的work part文件中获取PMI计数,但得到错误:
TypeError: object of type 'NXOpen.Annotations.PmiCollection' has no len()

代码:
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()等价的vb代码:http://nxjournaling.com/content/find-out-if-part-has-any-pmi
发布于 2019-02-28 01:35:39
下面的代码给出了active part中的PMI计数,并在count更改时进行断言(此处为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 == 3https://stackoverflow.com/questions/54890167
复制相似问题