Script to Bake controller not working on custom attribut controller


#1

Hi,
I’m working on a simple script to batch a controller with several options, it work perfectly on a classic controller like a position but not on a custom attribut and i can’t find my error. Please find bellow a short version of my script ( this part bake controller ).

fn bakeMe ctrl fromRange:animationRange.start toRange:animationRange.end  = (    
    fromRange = fromRange as time
    toRange = toRange as time 

    if (superclassof ctrl.controller) != FloatController do -- ctrl doit-être un controler de type float
        (
            print "Only work on FloatController superClass"
            return false 
        )        

    undo "BakeControler " on (            
        tmpVal=#()
        try (                        
            -- record value
                for i = fromRange to toRange do (
                    at time i (
                        append tmpVal ctrl.controller.value                        
                    )
            )
            -- assign new controller
                ctrl.controller=linear_float()   
        
            --applying value to the new controller
                for i = fromRange to toRange do (
                    at time i (
                        numID =((i.frame)+1-(fromRange.frame as integer)) as integer
                        with animate on (
                            ctrl.controller.value = tmpVal[numID]                                
                        )
                    )                
                )
                        
        )catch(
            format "*** BakingError: % ***\n" (getCurrentException())            
        )        
    )
)

 bakeMe $.position.controller[1]   -- Work perfeclty 

bakeMe $.baseObject.Custom_Attributes.param1 -- Crash with Unknown property: "controller" in 6.69115 (value )

Thanks for idea and help


#2

Hi,

There is a few day i’m working on the problem, but it’s look that write it has helped me. I understand the problem but i don’t no how to solve it …

I’m not sending the same information because $.position.controller[1] give me the possibility to access the controller keeping the link to the node, but for the custom attribut it’s not the same, i can not anymore access the node and the controller… so i’ve updated my script like this :

fn bakeMe ctrl fromRange:animationRange.start toRange:animationRange.end  = (	
	fromRange = fromRange as time
	toRange = toRange as time 
	
	if (superclassof ctrl) != FloatController do -- ctrl doit-être un controler de type float
		(
			print "Only work on FloatController superClass"
			return false 
		)		
	
	undo "BakeControler " on (			
		tmpVal=#()
		try (						
			-- record value
				for i = fromRange to toRange do (
					at time i (
						append tmpVal ctrl.value						
					)
				)
			-- assign new controller
				--ctrl=linear_float()   
			
			--applying value to the new controller
				for i = fromRange to toRange do (
					at time i (
						numID =((i.frame)+1-(fromRange.frame as integer)) as integer
						with animate on (
							ctrl.value = tmpVal[numID]								
						)
					)				
				)
							
		)catch(
			format "*** BakingError: % ***\n" (getCurrentException())			
		)		
	)
)

bakeMe $.position.controller[1].controller
bakeMe $.pc.controller

it’s work great, but only if i comment the ctrl=linear_float() because it’s overiding my var … how to change the controller that’s now the good question ;o(

An idea ?


#3

here is how i would do it… there are several reasons to do it this way:

fn bakeFloatController c type:#linear range: step:1 = if iskindof c FloatController do
(
	if range == unsupplied do range = getTimeRange c
	_c = if type == #linear then linear_float() else bezier_float()

	for t = range.start to range.end by step do at time t 
	(
		k = addNewKey _c t
		k.value = c.value
	)
	replaceinstances c _c
	numkeys _c
)

#4

Hi,

Thanks for your feedback, really appreciate it.

I found the error/problem in my function using &ctrl to pass variable as instance. but i will integrate your solution that look really more efficent than mine.
It’s important to keep the numkeys at end or it’s only to display count ?

Thanks again


#5

it just shows that something reasonable happened :slight_smile: