How to keyframe all the objects viewport/render visibility inside the selected collection via python code?
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=&quot;hide_render&quot;)
    ob.keyframe_insert(data_path=&quot;hide_viewport&quot;)
    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