ScriptSpot home

Forum topic · General Scripting

getController from array

By JokerMartini · 2013-02-22

Description

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 (8)
JokerMartini

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.

Reply to JokerMartini
Branko Živković

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
)

Reply to JokerMartini
Panayot Karabakalov

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.

JokerMartini

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.

Panayot Karabakalov

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
)
JokerMartini

Thank you very much

Branko Živković

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