[Closed] For and If together in rotation controller
Hi guys.
I’m trying to understand a bit o maxscript, but since I have no programming experience, sometimes I can’t get around some simple things. :banghead:
What I was doing is helping a friend scripting look at with list controller. At first he was having problem removing all look at from a bunch of objects that have list controller and look at as a second controller, so this simple for loop worked:
for i in selection do i.rotation.controller.delete 2
But now he is having problem because sometimes he selects an object without list controller, so I thought about a simple if to check if there is a list controller to remove the second controller. After some reading in the maxscript help and some undefined errors, the best I could get was this:
for i in selection do (
if i.rotation.controller == Rotation_List then
i.rotation.controller.delete 2
)
I just get an OK in the listener but nothing happens, I guess is the for loop mixed with the if giving me some troubles, I bet this must be a simple beginner mistake but I would like to understand what is the right syntax for it.
Thanks in advance!
Flávio
for i in selection do (
if classof i.rotation.controller == Rotation_List then
i.rotation.controller.delete 2
)
or
for i in selection where classof i.rotation.controller == Rotation_List do i.rotation.controller.delete 2
Rotation_List is a class and the actual controller applied to the object is an instance of that class. To find out what class a controller belongs to, you can use the classOf method:
classOf $.rotation.controller
rotation_list
classOf rotation_list
RotationController
classOf RotationController
MAXWrapper
classOf MAXWrapper
Value
classOf Value
Value
Value is the top level class in the mxs class hierarchy, and every value in mxs is a child of the Value class:
Value
-- MAXWrapper
---- RotationController
------ rotation_list
Here’s the modified code:
for i in selection do (
if classOf i.rotation.controller == Rotation_List then
i.rotation.controller.delete 2
)
Or:
for i in selection where
classOf i.rotation.controller == Rotation_List and
i.rotation.controller.count > 1 do --it might contain only one subcontroller
i.rotation.controller.delete 2
)
MAXScript documentation topics worth reading:
Inheritance and Polymorphism
Value Common Properties, Operators, and Methods
The Wonderful World of Classes and Class Instances
Hope this helps,
Martijn
Thanks a lot guys, I knew it was something simple I was missing.
And Martijn, thanks for pointing those readings, sometimes I get really lost in maxscript help and those topics are just where I needed to read. :buttrock: