[Closed] having trouble converting a string to a class
i’m trying to remove a bunch of keys from a lot of curves so i’m attempting to patch the names of the controllers together. the only thing that seems to be stopping me is converting the string to the appropriate class.
the command deleteKey calls for the following:
deleteKey <controller> <index>
max returns the following when i run this line:
$Bone01.rotation.controller.x_rotation.controller
Controller:Bezier_Float
here’s my code:
(
foo = $Bone01
foobar = (“$” + foo.name + “.rotation.controller.x_rotation.controller”)
deleteKey (foobar as bezier_float) 22
)
which returns:
– Error occurred in anonymous codeblock
– Frame:
– foo: $Bone01
– foobar: “$Bone01.rotation.controller.x_rotation.controller”
– Type error: Type conversion needs a class argument, got: bezier_float
OK
what class am i suppose to convert the foobar string to?
try
value = "$" + foo.name + ".rotation.controller.x_rotation.controller"
deletekey (execute value) 1
thank for the suggestion rustyKnight. i didn’t try it but here’s what i used as the solution.
(
foo = $Bone01
foobar = (execute(“$” + foo.name)).rotation.controller.x_rotation.controller
deleteKey foobar 22
)
If you already have a reference to the node stored in a variable (foo in your case), you can simply access the controller using
(
foo = $Bone01
foobar = foo.rotation.controller.x_rotation.controller
deleteKey foobar 22
)
or shorter:
deleteKey $Bone01.rotation.controller.x_rotation.controller 22
So in this case there’s no need to use either execute or getNodeByName.
Martijn
You don’t need the execute command here (which is slow and is best avoided whenever possible). Instead, you could use the getNodeByName command:
obj = getNodeByName "InsertObjectNameHere"
ctrl = obj.rotation.controller.x_rotation.controller
deleteKey ctrl 1
getNodeByName accepts a couple of optional arguments, see the maxscript documentation for more info about the command.
Cheers,
Martijn
slaps self on head
If you already have a reference to the node stored in a variable (foo in your case)
Missed that one