PDA

View Full Version : having trouble converting a string to a class


ballisticPenguin
06-20-2007, 07:40 PM
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?

RustyKnight
06-21-2007, 03:49 AM
try
value = "$" + foo.name + ".rotation.controller.x_rotation.controller"
deletekey (execute value) 1

ballisticPenguin
06-21-2007, 07:04 PM
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
)

magicm
06-21-2007, 07:16 PM
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

magicm
06-21-2007, 07:27 PM
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

RustyKnight
06-21-2007, 11:04 PM
*slaps self on head*

If you already have a reference to the node stored in a variable (foo in your case)

Missed that one

CGTalk Moderation
06-21-2007, 11:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.