0
$\begingroup$

The goal is to change the hue of objects based on the difference between the frame when the object is made visible to the scene renderer and the frame_current. What code will allow me to access the frame number of an object's visibility keyframe? Something like:

import bpy

objs=bpy.data.objects[0:-3]      #select multitude of objects barring a camera, 
                                                                     # light, and curve
scene=bpy.context.scene
endF=scene.frame_end
currentF=scene.frame_current
while currentF != endF:
    for o in objs:
        start=o.visible.frame # <-??              #set variable for the frame number 
                                                  # when each object is made visible
        hue=o.material.diffuse.color        #set variable for hue of object's 
                                                                         # material

    #set hue based on difference between current frame and visible frame
        if currentF-start==1: hue=0x6E00E7

The line of code I really need help with is marked with "# <-??", i.e., line 12.


Solved. It works now.

import bpy 
objs=bpy.data.objects      #make list of all objects in scene
scene=bpy.context.scene
endF=scene.frame_end
currentF=scene.frame_current
keyframes=[]
meshObs=[]         

for o in objs:
 if  o.type == 'MESH' and o.animation_data !=None:      
     fc = o.animation_data.action.fcurves.find('hide') 
     keyframes.append([kfp.co[0] for kfp in fc.keyframe_points if kfp.co[1]==0][0])
     meshObs.append(o)
$\endgroup$

1 Answer 1

1
$\begingroup$

The following will give you an array of all the frame numbers (as float) where the visibility is True

fc = o.animation_data.action.fcurves.find('hide')
frameNos = [kfp.co[0] for kfp in fc.keyframe_points if kfp.co[1] == 0]

you can find the previous one from the current with

start = max([kfp.co[0] for kfp in fc.keyframe_points if kfp.co[1] == 0 and kfp.co[0] < currentF])
$\endgroup$
3
  • $\begingroup$ Thank you, Blender Dadaist. That part works perfectly now. I used the code in your first code block, edited to invoke append method. These are the start frames which is all I needed. I don't understand what the code in the second code block is supposed to do. $\endgroup$ Commented Oct 4, 2018 at 17:34
  • $\begingroup$ Also, I added [0] to extract the value from it's coordinate array in kfp. Now, I have float values for keyed frames to compare with the float value of the current frame. $\endgroup$ Commented Oct 4, 2018 at 19:14
  • 1
    $\begingroup$ I just thought you want the 'visible' keyframe immediately preceding the currentF in the variable 'start' (in case you have multiple keyframes that turn on the visibility). That's what the second codeblock does. But glad that you were able to solve the problem :) $\endgroup$ Commented Oct 5, 2018 at 4:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .