1
$\begingroup$

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.

Two icons 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?

$\endgroup$
2
4
$\begingroup$

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

$\endgroup$
3
$\begingroup$

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)

$\endgroup$
3
  • $\begingroup$ Calling hide_set(True) will still leave the object grayed out in the Outliner. Why? $\endgroup$ Apr 23 at 15:17
  • $\begingroup$ @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() $\endgroup$ Apr 24 at 15:39
  • $\begingroup$ 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. $\endgroup$ Apr 25 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.