我的场景里有三个定位器。
Locator01 - localScaleY值为1
Locator02 - localScaleY值为2
Locator03 - localScaleY值为3
每个localScaleY中都有不同的值。我本来想比较一下这三个定位器的localScaleY值,然后找出其中最高的一个(在本例中是Locator03)
yMax = []
for yValue in pm.ls('locator*'):
yMax.append(getAttr (yValue +'.localScaleY'))
yMaxValue = max(yMax)
print yMaxValue
因此,基于上述编码,这是否是一种可行的方式,因为我将比较更多的项目?还是有更好的办法?
发布于 2014-02-19 09:26:14
构建一个规模/对象元组的生成器,并获取该生成器的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') #
发布于 2014-02-19 15:28:48
虽然mhlester的答案有效,但我看不出有什么理由能产生她。我只想简单地max()
这个列表。
maxLoc = max(l.localScaleY for l in locs)
print '{} has the highest value in localScaleY: {}'.format(maxLoc.split('.')[0], maxLoc.get())
https://stackoverflow.com/questions/21879212
复制