Python MAXScript:按名称在我的选择中搜索特定对象
我想在我的选择中按名称搜索特定对象。Python MAXScript:按名称在我的选择中搜索特定对象,python,object,search,selection,maxscript,Python,Object,Search,Selection,Maxscript,我想在我的选择中按名称搜索特定对象。 例如:在3ds max中,我选择了两个对象。 在选择中搜索名为“BOX”的对象,并将其重命名为“test” 目前,我只能使用[1]&[2]进行过滤。我想要的是更多的[“盒子”],但它不起作用。 on button1 pressed do with undo on ( object1 = selection[1] object2 = selection[2] if selection.count == 2 and Superclasso
例如:在3ds max中,我选择了两个对象。
在
选择中
搜索名为“BOX”
的对象,并将其重命名为“test”
目前,我只能使用[1]&[2]进行过滤。我想要的是更多的[“盒子”],但它不起作用。
on button1 pressed do with undo on
(
object1 = selection[1]
object2 = selection[2]
if selection.count == 2 and Superclassof object1 == Geometryclass and Superclassof object2 == Geometryclass then
for i in selection do
(
object1.name = "test"
object2.name = "test2"
freeze object2
)
else
messagebox ("!") title:"ERROR:"
)
多亏了剑客,我成功做到了这一点:
on button pressed do with undo on
(
if selection.count == 2 and Superclassof obj1 == Geometryclass and Superclassof obj2 == Geometryclass then
(
for obj1 in selection where obj1.name == "BOX" do
(obj1.name = "test")
for obj2 in selection where obj2.name == "_high" do
(obj.name = "test2")
)
else
messagebox ("!") title:"ERROR:"
)
不幸的是,限制超类不再有效 像往常一样,根据你想如何实际使用它,有很多方法可以做到这一点,例如
for obj in selection where obj.name == "BOX" do obj.name = "test"
或
甚至
$selection/*Box.name = "test"
编辑:如果确实只选择了两个对象:
if selection.count == 2 do case of
(
(selection[1].name as name == #box) : selection[1].name = uniqueName selection[2].name
(selection[2].name as name == #box) : selection[2].name = uniqueName selection[1].name
default: messageBox "Error"
)
谢谢你!它正在工作,但是我的超类不再工作了,剩下的代码将是一个完全不同的问题。。。这就是为什么我说这真的取决于您实际想要做什么。在代码中:
对于obj,在选择中,obj.name==“BOX”do obj.name=“test”。如何替换“test”以获得object2的名称?请参见编辑,我认为您的示例只是一个示例。
if selection.count == 2 do case of
(
(selection[1].name as name == #box) : selection[1].name = uniqueName selection[2].name
(selection[2].name as name == #box) : selection[2].name = uniqueName selection[1].name
default: messageBox "Error"
)