# Get and Set Hide in viewport and Disable in viewport via Python API

In my plugin I have an operator that needs to iterate through potentially 100's of objects that might be 'hidden in viewport' or 'disabled in viewport' and perform some operations that require the object to be visible in viewport. Afterwards I want to restore whatever visibility the object had, so I need to both get and set these options.

IE, get/set the status of these.

When I hover over the icons, both show the parameter bpy.context.object.hide_viewport. Obviously they can't both be the same parameter as they both do different things. How do I get and set 'hidden in viewport' and how do I get and set 'disabled in viewport' using the Python API?

Edit: I can see that both ObjectBase(bpy_struct) and Object(ID) have the hide_viewport property, however ObjectBase is documented as 'Temporarily hide in viewport' and Object is documented as 'Globally disable in viewports'. How do I access an Object's ObjectBase?

## 2 Answers

To iterate on the other answer which left out the get parts:

bpy.context.active_object.hide_viewport = True for MONITOR icon bpy.context.active_object.hide_set(True) for EYE icon

for collections it's bit different bpy.context.collection.hide_viewport = True will globally hide collection(MONITOR icon) bpy.context.view_layer.layer_collection.children.get('Your_Collection_Name').hide_viewport = True wil hide collectiob locally (EYE icon)

• Calling hide_set(True) will still leave the object grayed out in the Outliner. Why? Apr 23 at 15:17
• @AndreasHaferburg Does object shows in viewport but grayed out in outliner? If you move your cursor in outliner then object should not be grayed out. This happens because blender does not draw particular area unless there are activity in that. You can redraw in code using area.tag_redraw() Apr 24 at 15:39
• I hide the object by clicking the eye icon in the outliner. Then I unhide using hide_set(False). It becomes visible in the viewport, but it stays grayed out in the Outliner, even after clicking on another object in the Outliner. Apr 25 at 8:24