我试图从在NX软件中以Python打开的工作零件文件中获取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
答案 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