display tools: add show/hide by type
This commit is contained in:
parent
46a690e72f
commit
1c3a84f24f
|
@ -402,6 +402,8 @@ class DisplayToolsPanel(Panel):
|
|||
if obj:
|
||||
if obj.mode == 'OBJECT':
|
||||
layout.operator_menu_enum("object.select_by_type", "type", text="Select All by Type...")
|
||||
layout.operator_menu_enum("object.hide_by_type", "type", text="Hide By Type")
|
||||
layout.operator_menu_enum("object.show_by_type", "type", text="Show By Type")
|
||||
col = layout.column(align=True)
|
||||
col.operator("opr.select_all", icon="MOD_MESHDEFORM")
|
||||
col.operator("opr.inverse_selection", icon="MOD_REMESH")
|
||||
|
@ -608,10 +610,20 @@ class DisplayToolsPreferences(AddonPreferences):
|
|||
col.prop(self, "category", text="")
|
||||
|
||||
|
||||
def DRAW_hide_by_type_MENU(self, context):
|
||||
self.layout.operator_menu_enum(
|
||||
"object.hide_by_type",
|
||||
"type", text="Hide By Type"
|
||||
)
|
||||
self.layout.operator_menu_enum(
|
||||
"object.show_by_type",
|
||||
"type", text="Show By Type"
|
||||
)
|
||||
|
||||
# register the classes and props
|
||||
def register():
|
||||
bpy.utils.register_module(__name__)
|
||||
|
||||
bpy.types.VIEW3D_MT_object_showhide.append(DRAW_hide_by_type_MENU)
|
||||
# Register Scene Properties
|
||||
bpy.types.Scene.display_tools = PointerProperty(
|
||||
type=display_tools_scene_props
|
||||
|
@ -623,6 +635,7 @@ def register():
|
|||
def unregister():
|
||||
del bpy.types.Scene.display_tools
|
||||
selection_restrictor.unregister()
|
||||
bpy.types.VIEW3D_MT_object_showhide.remove(DRAW_hide_by_type_MENU)
|
||||
bpy.utils.unregister_module(__name__)
|
||||
|
||||
|
||||
|
|
|
@ -210,6 +210,108 @@ class HideRenderAllSelected(Operator):
|
|||
|
||||
return {'FINISHED'}
|
||||
|
||||
class OBJECT_OT_HideShowByTypeTemplate():
|
||||
|
||||
bl_options = {'UNDO','REGISTER'}
|
||||
|
||||
type = bpy.props.EnumProperty(items=(
|
||||
('MESH', 'Mesh', ''),
|
||||
('CURVE', 'Curve', ''),
|
||||
('SURFACE', 'Surface', ''),
|
||||
('META', 'Meta', ''),
|
||||
('FONT', 'Font', ''),
|
||||
('ARMATURE', 'Armature', ''),
|
||||
('LATTICE', 'Lattice', ''),
|
||||
('EMPTY', 'Empty', ''),
|
||||
('CAMERA', 'Camera', ''),
|
||||
('LAMP', 'Lamp', ''),
|
||||
('ALL', 'All', '')),
|
||||
name='Type',
|
||||
description='Type',
|
||||
default='LAMP',
|
||||
options={'ANIMATABLE'})
|
||||
|
||||
def execute(self, context):
|
||||
|
||||
scene = bpy.context.scene
|
||||
objects = []
|
||||
eligible_objects = []
|
||||
|
||||
# Only Selected?
|
||||
if self.hide_selected:
|
||||
objects = bpy.context.selected_objects
|
||||
else:
|
||||
objects = scene.objects
|
||||
|
||||
# Only Specific Types? + Filter layers
|
||||
for obj in objects:
|
||||
for i in range(0,20):
|
||||
if obj.layers[i] & scene.layers[i]:
|
||||
if self.type == 'ALL' or obj.type == self.type:
|
||||
if obj not in eligible_objects:
|
||||
eligible_objects.append(obj)
|
||||
objects = eligible_objects
|
||||
eligible_objects = []
|
||||
|
||||
|
||||
# Only Render Restricted?
|
||||
if self.hide_render_restricted:
|
||||
for obj in objects:
|
||||
if obj.hide_render == self.hide_or_show:
|
||||
eligible_objects.append(obj)
|
||||
objects = eligible_objects
|
||||
eligible_objects = []
|
||||
|
||||
# Perform Hiding / Showing
|
||||
for obj in objects:
|
||||
obj.hide = self.hide_or_show
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
return self.execute(context)
|
||||
|
||||
|
||||
## show hide by type ## by Felix Schlitter
|
||||
class OBJECT_OT_HideByType(OBJECT_OT_HideShowByTypeTemplate, Operator):
|
||||
bl_idname = 'object.hide_by_type'
|
||||
bl_label = 'Hide By Type'
|
||||
hide_or_show = bpy.props.BoolProperty(
|
||||
name="Hide",
|
||||
description="Inverse effect",
|
||||
options={'HIDDEN'},
|
||||
default=1
|
||||
)
|
||||
hide_selected = bpy.props.BoolProperty(
|
||||
name="Selected",
|
||||
description="Hide only selected objects",
|
||||
default=0
|
||||
)
|
||||
hide_render_restricted = bpy.props.BoolProperty(
|
||||
name="Only Render-Restricted",
|
||||
description="Hide only render restricted objects",
|
||||
default=0
|
||||
)
|
||||
|
||||
class OBJECT_OT_ShowByType(OBJECT_OT_HideShowByTypeTemplate, Operator):
|
||||
bl_idname = 'object.show_by_type'
|
||||
bl_label = 'Show By Type'
|
||||
hide_or_show = bpy.props.BoolProperty(
|
||||
name="Hide",
|
||||
description="Inverse effect",
|
||||
options={'HIDDEN'},
|
||||
default=0
|
||||
)
|
||||
hide_selected = bpy.props.BoolProperty(
|
||||
name="Selected",
|
||||
options={'HIDDEN'},
|
||||
default=0
|
||||
)
|
||||
hide_render_restricted = bpy.props.BoolProperty(
|
||||
name="Only Renderable",
|
||||
description="Show only non render restricted objects",
|
||||
default=0
|
||||
)
|
||||
|
||||
# Register
|
||||
def register():
|
||||
|
|
Loading…
Reference in New Issue