Bpy.ops.object.hide_view_clear() command not working

Hi there!

For some reasons I need to create a button that shows hidden objects (so it would work exactly as alt+h). I found in the info window that the operator called behind this shortcut is bpy.ops.object.hide_view_clear() but when I call it manually from the python console I get an error telling me that the context is incorrect :

>>> bpy.ops.object.hide_view_clear()
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "C:\Program Files\Blender Foundation\Blender 3.0\3.0\scripts\modules\bpy\ops.py", line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.object.hide_view_clear.poll() failed, context is incorrect

Can anyone helps me to understand what am I doing wrong and how to solve my problem?


I think you have the operator right but the context wrong. I’m pretty sure you need to get the scene, bpy.ops is too high of a selection level

Thank you for your answer.
I understand that the context is wrong but I think I don’t get what you mean by getting the scene, the operator isn’t available in the scene context

Check the documentation on Operator Poll()

I think this may be what you need, as if you put your mouse over the script editor and press alt-H is also won’t unhide objects, so you need to poll to say run this in the 3D view.

1 Like

Thank you for your answer,

Actually I was calling this operator from the N pannel so thanks to your answer I knew that my problem wasn’t about context and I found the solution to it.

But thanks to you I also learned how to deal with context issues with poll operator so thank you very much :slight_smile: