Sunday, September 01, 2013

Blender: Automating the Setting and Keying of Visibility in Python

I fractured an object in Blender and wanted to swap out the whole object for the shattered one the frame before the collision that sends the shards flying, but didn't want to have to manually set visibility and renderabilty and keyframes for each of 300+ objects. So I wrote this little script to help

import bpy 

hideObjects = 1

for obj in bpy.context.selected_objects: 
    obj.hide = hideObjects 
    obj.keyframe_insert(data_path="hide") 
    obj.hide_render = hideObjects     
    obj.keyframe_insert(data_path="hide_render")



This simple script will take the selected objects and if you make 'hideObjects' equal to 1 then it will set the visibility and renderability of those objects and turn them off, then keyframe both properties on the current frame. So doing this I set the value to 0 on my unshattered object and keyed frame 1,   went to the frame where it should disappear and set the value to 1 and ran it again. I did the opposite for my shards. Worked like a charm. I hope it helps you out too!

No comments: