0
$\begingroup$

How to keyframe all the objects viewport/render visibility inside the selected collection via python code? And there's a boolean there that you can just type "False" or "True" to decide whether unhide or not. I only have a little bit of knowledge of scripting, especially in blender python library. I was thinking of this after knowing collections viewport/render visibility can't be keyframed, because I want to keyframe the object collections that aren't needed in certain camera shots. But trying to make it myself takes long time now, that I have to meet a certain deadline to pass my project.

$\endgroup$
0
$\begingroup$

After several moments I just got it, but I know there maybe a cleaner approach

import bpy

for ob in bpy.context.collection.all_objects:
    
    ob.keyframe_insert(data_path="hide_render")
    ob.keyframe_insert(data_path="hide_viewport")
    if ob.hide_render == True:
        ob.hide_render = False
    else:
        ob.hide_render = True
    if ob.hide_viewport == True:
        ob.hide_viewport = False
    else:
        ob.hide_viewport = True
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.