Finally, with @MACHIN3 very big help, we got this
import bpy
from bpy.types import Panel
from bpy.app.handlers import persistent
bl_info = {
"name": "Inactive Shading Style",
"author": "APEC",
"version": (1, 0),
"blender": (2, 81, 0),
"location": "View3D > Properties > IS",
"description": "Toggle between shading style for inactive meshes.",
"wiki_url": "",
"tracker_url": "",
"category": "3D View"
}
oldactive = None
oldsel = None
@persistent
def update_shading_style(scene):
'''
watch changes in selection or active object
set display_type accordingly
'''
if scene.inactive_shading:
global oldactive, oldsel
context = bpy.context
active = context.active_object if context.active_object else None
sel = context.selected_objects
if active != oldactive or sel != oldsel:
oldactive = active
oldsel = sel
for obj in context.visible_objects:
obj.display_type = 'TEXTURED' if obj in sel else 'WIRE'
class PanelInactiveShading(Panel):
bl_idname = "VIEW3D_PT_inactive_shading"
bl_label = "Inactive Shading"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = 'IS'
def draw(self, context):
layout = self.layout
col = layout.column()
split = col.split(factor=0.5)
#split.label(text="Inactive Shading")
label = "Wire" if context.scene.inactive_shading else "Current"
split.prop(context.scene, "inactive_shading", text=label, toggle=True)
def register():
def update_inactive_shading(self, context):
'''
reset the display type of all visible objects, when scene.inactive_shading is toggled
'''
vis = context.visible_objects
# enabled - set display style according to 1. object being active or among selection: TEXTURED, 2. object not selected: WIRE
if context.scene.inactive_shading:
active = context.active_object if context.active_object else None
sel = [obj for obj in context.selected_objects if obj != active]
for obj in vis:
if obj in sel or obj == active:
obj.display_type = 'TEXTURED'
else:
obj.display_type = 'WIRE'
# disabled - set all visible objects to TEXUTURED
else:
for obj in vis:
obj.display_type = 'TEXTURED'
bpy.types.Scene.inactive_shading = bpy.props.BoolProperty(name="Inactive Shading", default=True, update=update_inactive_shading)
bpy.utils.register_class(PanelInactiveShading)
bpy.app.handlers.depsgraph_update_post.append(update_shading_style)
bpy.app.handlers.undo_post.append(update_shading_style)
bpy.app.handlers.redo_post.append(update_shading_style)
def unregister():
bpy.app.handlers.depsgraph_update_post.remove(update_shading_style)
bpy.app.handlers.undo_post.remove(update_shading_style)
bpy.app.handlers.redo_post.remove(update_shading_style)
bpy.utils.unregister_class(PanelInactiveShading)
del bpy.types.Scene.inactive_shading
if __name__ == "__main__":
register()
or just install file
Inactive_Shading.py (3.2 KB)
P.S. if some one implement this button in Viewport Shading (Solid) settings let me know how =)
P.P.S. name “Current” because it use current selected shading that you choose in “Viewport Shading (Solid) - Color”