How to change the "Outliner / Filter / Restriction Toggles" by python script in v2.81

I want to change the Outliner / Filter / Restriction Toggled by the following python script in Blender v2.81 Python Console:

bpy.context.space_data.show_restrict_column_select = True
bpy.context.space_data.show_restrict_column_hide = False
bpy.context.space_data.show_restrict_column_viewport = True
bpy.context.space_data.show_restrict_column_render = True

These command are copied from the “Info” windows when these filters were altered manually. But the following error messages were displayed after executing the scripts:

bpy.context.space_data.show_restrict_column_select = True
Traceback (most recent call last):
File “<blender_console>”, line 1, in
AttributeError: ‘SpaceConsole’ object has no attribute ‘show_restrict_column_select’

bpy.context.space_data.show_restrict_column_hide = False
Traceback (most recent call last):
File “<blender_console>”, line 1, in
AttributeError: ‘SpaceConsole’ object has no attribute ‘show_restrict_column_hide’

bpy.context.space_data.show_restrict_column_viewport = True
Traceback (most recent call last):
File “<blender_console>”, line 1, in
AttributeError: ‘SpaceConsole’ object has no attribute ‘show_restrict_column_viewport’

bpy.context.space_data.show_restrict_column_render = True
Traceback (most recent call last):
File “<blender_console>”, line 1, in
AttributeError: ‘SpaceConsole’ object has no attribute ‘show_restrict_column_render’

The state of filters were not changed.

Anyone know what is wrong with the script statements and how to correct it?

1 Like

Same problem here. Any idea ?

import bpy

# Fetch the area
outliner = next(a for a in bpy.context.screen.areas if a.type == "OUTLINER") 
# Fetch the space
outliner.spaces[0].show_restrict_column_viewport = not outliner.spaces[0].show_restrict_column_viewport

Thank you for the reply.

The two statements you gave seems acting like a toggle.

What if the _column_viewport was already ON and I don’t want to turn it OFF?

Sure, replace the value with True or False :

import bpy

# Fetch the area
outliner = next(a for a in bpy.context.screen.areas if a.type == "OUTLINER") 
# Fetch the space
outliner.spaces[0].show_restrict_column_viewport = True # or False to toggle off

BTW I made a q&a on bse if you’d like to see all the possible calls : https://blender.stackexchange.com/questions/246147/how-can-i-change-the-outliner-restriction-toggles-with-python

1 Like

It works perfectly.

Thanks.