Python 比较并获取项目属性

Python 比较并获取项目属性,python,compare,maya,getattr,Python,Compare,Maya,Getattr,我的场景中有3个定位器,例如 Locator01-localScaleY值为1 Locator02-localScaleY值为2 Locator03-localScaleY值为3 每个都在其localScaleY中具有不同的值。我曾想比较这3个定位器的localScaleY值,并获取最高的一个(在本例中是Locator03) 因此,基于上述编码,这是一个可行的方式来写,因为我将比较更多的项目?或者也许有更好的方法?构建一个缩放/对象元组生成器,并取其中的max。通过将标尺放在第一位,max可正确

我的场景中有3个定位器,例如
Locator01-localScaleY值为1
Locator02-localScaleY值为2
Locator03-localScaleY值为3

每个都在其localScaleY中具有不同的值。我曾想比较这3个定位器的localScaleY值,并获取最高的一个(在本例中是Locator03)


因此,基于上述编码,这是一个可行的方式来写,因为我将比较更多的项目?或者也许有更好的方法?

构建一个缩放/对象元组生成器,并取其中的
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') # 

构建一个缩放/对象元组生成器,并取其
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') # 

构建一个缩放/对象元组生成器,并取其
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') # 

构建一个缩放/对象元组生成器,并取其
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') # 

虽然mhlester的答案是正确的,但我看不出有什么理由让她这么做。我只想
max()
列表

maxLoc = max(l.localScaleY for l in locs)
print '{} has the highest value in localScaleY: {}'.format(maxLoc.split('.')[0], maxLoc.get())

虽然mhlester的答案是正确的,但我看不出有什么理由让她这么做。我只想
max()
列表

maxLoc = max(l.localScaleY for l in locs)
print '{} has the highest value in localScaleY: {}'.format(maxLoc.split('.')[0], maxLoc.get())

虽然mhlester的答案是正确的,但我看不出有什么理由让她这么做。我只想
max()
列表

maxLoc = max(l.localScaleY for l in locs)
print '{} has the highest value in localScaleY: {}'.format(maxLoc.split('.')[0], maxLoc.get())

虽然mhlester的答案是正确的,但我看不出有什么理由让她这么做。我只想
max()
列表

maxLoc = max(l.localScaleY for l in locs)
print '{} has the highest value in localScaleY: {}'.format(maxLoc.split('.')[0], maxLoc.get())


你能修正你的缩进吗?你能把
定位器
放在一个列表中吗?然后就是
max(l.localScaleY表示定位器中的l)
。这让人困惑……这些术语是什么?你到底想做什么?你能提供一些输入数据/输出数据吗?@Bach修复了缩进,很抱歉,当我粘贴代码@jornsharpe时,他不小心移动了缩进。你在
列表中的意思是什么?在上面的示例中,定位器只是一个示例,因为我将使用的项目大多是内部导入的,但它们的类型相同@mdscruggs我使用的术语源自Autodesk Maya Python命令,例如
.localScaleY
是否可以修复缩进?是否可以将
定位器
放入列表中?然后就是
max(l.localScaleY表示定位器中的l)
。这让人困惑……这些术语是什么?你到底想做什么?你能提供一些输入数据/输出数据吗?@Bach修复了缩进,很抱歉,当我粘贴代码@jornsharpe时,他不小心移动了缩进。你在
列表中的意思是什么?在上面的示例中,定位器只是一个示例,因为我将使用的项目大多是内部导入的,但它们的类型相同@mdscruggs我使用的术语源自Autodesk Maya Python命令,例如
.localScaleY
是否可以修复缩进?是否可以将
定位器
放入列表中?然后就是
max(l.localScaleY表示定位器中的l)
。这让人困惑……这些术语是什么?你到底想做什么?你能提供一些输入数据/输出数据吗?@Bach修复了缩进,很抱歉,当我粘贴代码@jornsharpe时,他不小心移动了缩进。你在
列表中的意思是什么?在上面的示例中,定位器只是一个示例,因为我将使用的项目大多是内部导入的,但它们的类型相同@mdscruggs我使用的术语源自Autodesk Maya Python命令,例如
.localScaleY
是否可以修复缩进?是否可以将
定位器
放入列表中?然后就是
max(l.localScaleY表示定位器中的l)
。这让人困惑……这些术语是什么?你到底想做什么?你能提供一些输入数据/输出数据吗?@Bach修复了缩进,很抱歉,当我粘贴代码@jornsharpe时,他不小心移动了缩进。你在
列表中的意思是什么?在上面的示例中,定位器只是一个示例,因为我将使用的项目大多是内部导入的,但它们的类型相同@mdscruggs我使用的术语源自Autodesk Maya Python命令,例如,
.localScaleY
Cool,这也适用于。。。我只是想知道,与我的版本相比,有人能指出我哪里做错了吗?最大的区别是每次迭代都会得到
max
。否则,你的工作将获得最大的规模。它不适用于获取具有最大ScaleCol的定位器,这也适用于。。。我只是想知道,与我的版本相比,有人能指出我哪里做错了吗?最大的区别是每次迭代都会得到
max
。否则,你的工作将获得最大的规模。它不适用于获取具有最大ScaleCol的定位器,这也适用于。。。我只是想知道,与我的版本相比,有人能指出我哪里做错了吗?最大的区别是每次迭代都会得到
max
。否则,你的工作将获得最大的规模。它不适用于获取具有最大ScaleCol的定位器,这也适用于。。。我只是想知道,与我的版本相比,有人能指出我哪里做错了吗?最大的区别是每次迭代都会得到
max
。否则,你的工作将获得最大的规模。它不适用于获取最大值的定位器scale@ArgirlKotsaris如果我错了,请纠正我,但是
格式(maxLoc.split('.')[0]
这不是意味着从列表中获取第一项吗?我在场景中测试了它,它确实获取了第一项