Notifications
Clear all

[Closed] loop through sub anims

I need to run a function on some nodes which runs through each nodes subAnims like visibility, transform etc… as well as any modifiers and their subAnims.

How can I condense this function? It’s redundant and I was hoping to get some help on this one. Right now it’s hard coded to run on modifiers and then the node’s transform. But in reality it needs to check any subAnim of the node and it’s modifiers.

Thank you.


fn OffsetCache node =
(
	val = 1 --(frameOffset-startFrame) / framerate as float
	str = "current * factor + offset" + " - "
	str += val as string
	
	/* Modifiers */
	for m = 1 to node.modifiers.count do --loop through each modifier
	(
		for s = 1 to node.modifiers[m].numSubs do --loop through each modifiers subAnim controllers
		(
			ctrl = node.modifiers[m][s].controller
			if classof ctrl == Float_Expression do
			(
				ctrl.SetExpression str --set controller expression
				ctrl.Update() --updates controller
				
				format "Modified: %
" ctrl
			)
		)		
	)
	
	/* Node */
	for s = 1 to node[3].numSubs do --loop through transform
	(
		ctrl = node[3][s].controller
		if classof ctrl == Float_Expression do
		(
 			ctrl.SetExpression str --set controller expression
 			ctrl.Update() --updates controller
			
			format "Modified: %
" ctrl
		)
	)
	--p.baseObject[1].controller.SetExpression str --set controller expression for particles only i believe
	
)
clearlistener()

OffsetCache $Teapot001

2 Replies
fn RecurseSubAnims o =
  (
  	-- do something
  	print o
  	
  	-- recurse
  	for i = 1 to o.numsubs do RecurseSubAnims o[i]
  )

subanim 4 of an object contains modifiers and the base object. this function should cover all bases but due to max being max i’m sure there will be special cases…

EDIT: here’s something for your specific requirements.
i am assuming that you only want to search visibility, transform, modifiers and base object and not material subanim for example.

fn UpdateFloatExpressionsRecursive o str =
 (
 	ctrl = o.controller
 	if isKindOf ctrl Float_Expression do
 	(
 		ctrl.SetExpression str --set controller expression
 		ctrl.Update() --updates controller
 		
 		format "Modified: %
" ctrl
 	)
 	
 	-- recurse
 	for i = 1 to o.numsubs do UpdateFloatExpressions o[i] str
 )
 
 fn OffsetCache node =
 (
 	val = 1 --(frameOffset-startFrame) / framerate as float
 	str = "current * factor + offset - " + val as string
 	
 	-- 1 is visibiliy
 	-- 3 is transform
 	-- 4 is modified object ie. base object and modifiers
 	for i in #(1,3,4) do UpdateFloatExpressions node[i] str
 )
 
 OffsetCache $

fn RecurseSubAnims o =
(
– do something
print o

-- recurse
for i = 1 to o.numsubs do RecurseSubAnims o[i]

)

Works great.
Thank you