# Efficient way to hide an object using python?

I was wondering if this is the most efficient way to hide an object using python?

bpy.context.view_layer.objects.active = bpy.data.objects['Cone']; bpy.context.object.hide_viewport = True;

Is there a more efficient way to do this (since I have to turn on/off visibility many times for many objects), maybe something like:

bpy.data.objects['Cube'].visible_set(False); # visible_set doesn't exist unfortunately

Thanks.

• Efficient in which context? What you'd like to do? – brockmann Jul 9 '19 at 20:54
• I have to repeat turning objects on and off constantly so I want it to be efficient speed wise. – L. Phan Jul 9 '19 at 21:04
• Selected objects or random objects in the scene? – brockmann Jul 9 '19 at 21:11
• I have 12 objects which I turn on/off constantly. – L. Phan Jul 9 '19 at 21:25
• Just asking because in case the objects are already selected it will be faster than having an extra loop to select geometry beforehand. ALSO: In case you'd like to render your "on/off" animation then you also need hide_render property. Again, if you'd like to have efficient as possible, provide more context. Related: blender.stackexchange.com/a/133470/31447 – brockmann Jul 9 '19 at 21:42