例如,我的场景中有3个定位器。
Locator01-localScaleY值为1
Locator02-localScaleY值为2
Locator03-localScaleY值为3
每个在其localScaleY中具有变化的值。我本想比较这3个定位器的localScaleY值并获取最高的一个(在本例中为Locator03)
yMax = []
for yValue in pm.ls('locator*'):
yMax.append(getAttr (yValue +'.localScaleY'))
yMaxValue = max(yMax)
print yMaxValue
因此,根据以上编码,由于我将比较更多项目,因此这是一种可行的书写方式吗?还是有更好的方法?
构建规模/对象元组的生成器,并采用该生成器max
。通过将秤放在第一位,max
正确地将其关掉。
locators = ((getAttr(locator+'.localScaleY'), locator) for locator in pm.ls('locator*'))
yMaxValue, locator = max(locators)
一些输出供参考:
>>> list(locators)
# Result: [(1.0, nt.Transform(u'locator01')),
(2.0, nt.Transform(u'locator02')),
(3.0, nt.Transform(u'locator03')),
(1.0, nt.Locator(u'locator0Shape1')),
(2.0, nt.Locator(u'locator0Shape2')),
(3.0, nt.Locator(u'locator0Shape3'))] #
>>> yMaxValue
# Result: 3.0 #
>>> locator
# Result: nt.Locator(u'locator0Shape3') #
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句