ScriptSpot

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 · 2013-02-28

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.

barigazy · 2013-02-28

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
)

edit :)

barigazy · 2013-02-28

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

my function do what you ask for :)

Anubis · 2013-03-01

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.

Anubis! Hey bud.

JokerMartini · 2013-02-23

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.

Hi John

Anubis · 2013-02-23

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 · 2013-02-22

Thank you very much

barigazy · 2013-02-22

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