Created
September 16, 2024 12:56
-
-
Save Gus-The-Forklift-Driver/3e00f778d7c2bb35e46b61ad171f926d to your computer and use it in GitHub Desktop.
A quick and dirty Blender addon to toggle visibility / render visibility of objects selected in the ouliner. Tested with Blender 4.2.1 LTS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
bl_info = { | |
"name": "viz toggle outliner", | |
"author": "SmonkingSheep", | |
"description": "", | |
"blender": (4, 2, 0), | |
"version": (0, 0, 2), | |
"location": "", | |
"warning": "", | |
"category": "Generic" | |
} | |
class hide_in_viewports(bpy.types.Operator): | |
bl_idname = "visi.hide_in_viewports" | |
bl_label = 'hide object in viewport' | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
if bpy.context.area.type != 'OUTLINER': | |
# If needed find the outliner area | |
for area in bpy.context.screen.areas: | |
if area.type == 'OUTLINER': | |
areaOverride = area | |
break | |
else: | |
self.report({'ERROR'}, "Failed to find open outliner") | |
return {'CANCELLED'} | |
region = areaOverride.regions[-1] | |
with bpy.context.temp_override(area=areaOverride, region=region): | |
for obj in bpy.context.selected_ids: | |
obj.hide_viewport = True | |
return {'FINISHED'} | |
class show_in_viewports(bpy.types.Operator): | |
bl_idname = "visi.show_in_viewports" | |
bl_label = 'show object in viewport' | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
if bpy.context.area.type != 'OUTLINER': | |
# If needed find the outliner area | |
for area in bpy.context.screen.areas: | |
if area.type == 'OUTLINER': | |
areaOverride = area | |
break | |
else: | |
self.report({'ERROR'}, "Failed to find open outliner") | |
return {'CANCELLED'} | |
region = areaOverride.regions[-1] | |
with bpy.context.temp_override(area=areaOverride, region=region): | |
for obj in bpy.context.selected_ids: | |
obj.hide_viewport = False | |
return {'FINISHED'} | |
class hide_in_renders(bpy.types.Operator): | |
bl_idname = "visi.hide_in_renders" | |
bl_label = 'hide object in render' | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
if bpy.context.area.type != 'OUTLINER': | |
# If needed find the outliner area | |
for area in bpy.context.screen.areas: | |
if area.type == 'OUTLINER': | |
areaOverride = area | |
break | |
else: | |
self.report({'ERROR'}, "Failed to find open outliner") | |
return {'CANCELLED'} | |
region = areaOverride.regions[-1] | |
with bpy.context.temp_override(area=areaOverride, region=region): | |
for obj in bpy.context.selected_ids: | |
obj.hide_render = True | |
return {'FINISHED'} | |
class show_in_renders(bpy.types.Operator): | |
bl_idname = "visi.show_in_renders" | |
bl_label = 'show object in render' | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
if bpy.context.area.type != 'OUTLINER': | |
# If needed find the outliner area | |
for area in bpy.context.screen.areas: | |
if area.type == 'OUTLINER': | |
areaOverride = area | |
break | |
else: | |
self.report({'ERROR'}, "Failed to find open outliner") | |
return {'CANCELLED'} | |
region = areaOverride.regions[-1] | |
with bpy.context.temp_override(area=areaOverride, region=region): | |
for obj in bpy.context.selected_ids: | |
obj.hide_render = False | |
return {'FINISHED'} | |
class keyframe_renders(bpy.types.Operator): | |
bl_idname = "visi.keyframe_renders" | |
bl_label = 'keyframe object in render' | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
if bpy.context.area.type != 'OUTLINER': | |
# If needed find the outliner area | |
for area in bpy.context.screen.areas: | |
if area.type == 'OUTLINER': | |
areaOverride = area | |
break | |
else: | |
self.report({'ERROR'}, "Failed to find open outliner") | |
return {'CANCELLED'} | |
region = areaOverride.regions[-1] | |
with bpy.context.temp_override(area=areaOverride, region=region): | |
for obj in bpy.context.selected_ids: | |
obj.keyframe_insert(data_path='hide_render') | |
return {'FINISHED'} | |
class keyframe_viewports(bpy.types.Operator): | |
bl_idname = "visi.keyframe_viewports" | |
bl_label = 'keyframe object in viewport' | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
if bpy.context.area.type != 'OUTLINER': | |
# If needed find the outliner area | |
for area in bpy.context.screen.areas: | |
if area.type == 'OUTLINER': | |
areaOverride = area | |
break | |
else: | |
self.report({'ERROR'}, "Failed to find open outliner") | |
return {'CANCELLED'} | |
region = areaOverride.regions[-1] | |
with bpy.context.temp_override(area=areaOverride, region=region): | |
for obj in bpy.context.selected_ids: | |
obj.keyframe_insert(data_path='hide_viewport') | |
return {'FINISHED'} | |
class panel(bpy.types.Panel): | |
"""Creates a Panel in the item properties window""" | |
bl_label = "Visibility" | |
bl_idname = "VIEW3D_PT_visi" | |
bl_space_type = 'VIEW_3D' | |
bl_region_type = 'UI' | |
bl_category = 'Item' | |
def draw(self, context): | |
layout = self.layout | |
scene = context.scene | |
layout.operator('visi.hide_in_viewports', text='hide in viewports') | |
layout.operator('visi.show_in_viewports', text='show in viewports') | |
layout.separator() | |
layout.operator('visi.hide_in_renders', text='hide in renders') | |
layout.operator('visi.show_in_renders', text='show in renders') | |
layout.separator() | |
layout.operator('visi.keyframe_viewports', text='keyframe viewport') | |
layout.operator('visi.keyframe_renders', text='keyframe renders') | |
CLASSES = [ | |
panel, | |
hide_in_viewports, | |
show_in_viewports, | |
hide_in_renders, | |
show_in_renders, | |
keyframe_renders, | |
keyframe_viewports | |
] | |
def register(): | |
print('registering') | |
for c in CLASSES: | |
bpy.utils.register_class(c) | |
def unregister(): | |
for c in CLASSES: | |
bpy.utils.unregister_class(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment