I would need to know how to keyframe multiple (like 300) objects' show/hide property?
A possible solution would be to add a custom property to the scene that reflects the desired visibility state of the objects, and some Python code to apply that desired state to the actual objects.
import bpy def interesting(ob) -> bool: """Returns True for objects to show/hide, and False otherwise. Alter to suit your needs. """ return ob.name.startswith('Plane') def hide_or_show(self, context=None): hide = self.hide_manus_objects for ob in self.objects: if not interesting(ob): continue # Change to ob.hide to hide from viewport instead of from render. # Or use ob.hide = ob.hide_render = hide to change both. ob.hide_render = hide # Some cleanup in case you're running this multiple times. try: del bpy.types.Scene.hide_manus_objects except AttributeError: pass # Responds to manual changes to the property. bpy.types.Scene.hide_manus_objects = bpy.props.BoolProperty( name='hide_manus_objects', update=hide_or_show) # Handles frame changes and thus responds to animation data. bpy.app.handlers.frame_change_post.append(hide_or_show) # Write to the property once to make it show up in the properties panel. bpy.context.scene.hide_manus_objects = bpy.context.scene.hide_manus_objects
This does require you to alter the
interesting() function to return
True for those objects that you want to manage with this. Given that you have 300-ish objects, I'm assuming that there is some naming scheme that'll make this possible.
To use the code, just paste it into a text block and press "Run Script". If you want to have it active every time you open the blend file (you probably do), make sure the name of the text block ends in
.py and enable the "Register" checkbox before saving.
Create an Empty, keyframe its Visibility property, select all the objects you'd like to hide/show, select the newly created Empty, press CtrlL to open up Make Links menu and select Animation Data.
Credit for the idea goes to @p2or, see: How to copy animation attributes to multiple objects?
As an alternative solution:
- manually select all objects you want to show/hide;
- alt-click the eye-icon or the render-icon in the outliner to show/hide them (in resp. the viewport or the render);
run this script in a text block:
import bpy for ob in bpy.context.selected_objects: ob.keyframe_insert(data_path="hide_render") ob.keyframe_insert(data_path="hide")
This is more manual work (you have to click around a lot more), and it produces 300-ish fcurves that you'll have to manually manage (rather than my other answer, which results in one fcurve only). However, the code is simpler, so if that floats your boat, use this approach