how do we hide show a collection in blender 2.8
let say that this is the path to my collection
bpy.data.collections['SCATTER: [Plane.001] Particles']
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityhow do we hide show a collection in blender 2.8
let say that this is the path to my collection
bpy.data.collections['SCATTER: [Plane.001] Particles']
The operator that toggles the collection visibility in the outliner is bpy.ops.outliner.item_openclose()
. Unfortunately it depends on the cursor position to determine the collection that should be toggled. While we could position the cursor with bpy.context.window.cursor_warp()
the x and y coordinates of the collection in the UI remain unknown. It's therefore not realistically possible to perform this operation in a script or add-on.
I could get it to work with manually determined coordinates to position the cursor on the arrow icon in front of the collection.
import bpy
context = bpy.context.copy()
for area in bpy.context.screen.areas:
if area.type == 'OUTLINER':
for region in area.regions:
if region.type == 'WINDOW':
context['area'] = area
context['region'] = region
break
break
# Places the cursor directly on the arrow icon for the first collection with
# my screen resolution and UI layout.
bpy.context.window.cursor_warp(2150,1250)
bpy.ops.outliner.item_openclose(context, 'INVOKE_DEFAULT')
bpy.ops.outliner.show_one_level()
for expanding or collapsing one level or bpy.ops.outliner.expanded_toggle()
to expand or collapse all elements.
$\endgroup$
– Robert Gützkow♦
Nov 7 '19 at 15:54
bpy.ops.outliner.item_openclose()
. Besides a custom context it also requires the cursor to be placed at the element that is toggled. I don't think this is practically possible for an add-on to do both because shifting the cursor withbpy.context.window.cursor_warp()
would be very irritating to the user, but more importantly the x,y position of the collection in the outliner is unknown. $\endgroup$ – Robert Gützkow♦ Nov 7 '19 at 14:57