getController from array

Say for example I have an array that contains the numbers which represent a subAnim controller.

How could I build a variable which would allow me to directly get to that controller.

(
	delete objects
	obj = teapot()
	subIndexes = #(3,1,1) -- SubAnim:X_Position
	clearlistener()
 
-- example b = obj[3][1][1]
-- I need to build an array with the subIndexes that would return SubAnim:X Position
-- Keep in mind that the length of the subIndexes could change depending on the situation.
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JokerMartini's picture

Anubis after further messing

Anubis after further messing around your script returns just the controller, I need it to return the object and controller

ex. Yours returns
'subAnim: X_position'

I need
'Node[3][1][1]'

Which would be the controller path and the node.

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

my function do what you ask for :)

You can work with both "subAnum.value = get/set value" or "controller.value = get/set value", but if you prefer the function to return controller instead of subAnim, then just change last line to "sa.track".

fn returnSubAnim obj arr = (
	local sa = obj[arr[1]]
	if arr.count > 1 do
		for i = 2 to arr.count do
			sa = sa[arr[i]]
	sa.track -- return result
)
 
b = box()
c = returnSubAnim b #(3,1,1)
isController c --> true

And Node[3][1][1] is still SubAnim. If you need string, then use exprForMaxObject as Branko suggest.

my recent MAXScripts RSS (archive here)

barigazy's picture

Soory for intrusion. Maybe

Soory for intrusion. Maybe this will help

fn returnSubAnim obj arr = (
	local sa = obj[arr[1]]
	if arr.count > 1 do
		for i = 2 to arr.count do
			sa = sa[arr[i]]
	exprForMaxObject sa -- return result
)

barigazy

barigazy's picture

edit :)

edit
Now we will use again "excute" fn after u get the result from below fn

barigazy

JokerMartini's picture

Anubis! Hey bud.

Thanks for the snippet. It seems like that is more of what I'm after. I'm never a bit fan of execute. Thanks guys.

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

Hi John

or maybe just...
fn returnSubAnim obj arr = (obj[arr[1]][arr[2]][arr[3]])

woops, I miss last note... the sub tree is not fixed to 3, right?

P.S. corrected:

fn returnSubAnim obj arr = (
	local sa = obj[arr[1]]
	if arr.count > 1 do
		for i = 2 to arr.count do
			sa = sa[arr[i]]
	sa -- return result
)

my recent MAXScripts RSS (archive here)

JokerMartini's picture

Thank you very much

Thank you very much

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

barigazy's picture

Hi John Try this fn

Hi John
Try this

fn returnSubAnim obj arr =
(
	local str = "$"+obj.name
	for i in 1 to arr.count do append str ("[" + arr[i] as string + "]")
	execute str
)
tea = teapot()
subIndexes = #(3,1,1)
returnSubAnim tea subIndexes 

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.