diff options
-rw-r--r-- | space_view3d_display_tools/__init__.py | 667 | ||||
-rw-r--r-- | space_view3d_display_tools/display.py | 224 | ||||
-rw-r--r-- | space_view3d_display_tools/fast_navigate.py | 278 | ||||
-rw-r--r-- | space_view3d_display_tools/modifier_tools.py | 250 | ||||
-rw-r--r-- | space_view3d_display_tools/scene_vis.py | 50 | ||||
-rw-r--r-- | space_view3d_display_tools/select_tools.py | 338 | ||||
-rw-r--r-- | space_view3d_display_tools/selection_restrictor.py | 737 | ||||
-rw-r--r-- | space_view3d_display_tools/shading_menu.py | 65 | ||||
-rw-r--r-- | space_view3d_display_tools/useless_tools.py | 282 |
9 files changed, 0 insertions, 2891 deletions
diff --git a/space_view3d_display_tools/__init__.py b/space_view3d_display_tools/__init__.py deleted file mode 100644 index 78409ff7..00000000 --- a/space_view3d_display_tools/__init__.py +++ /dev/null @@ -1,667 +0,0 @@ -# space_view_3d_display_tools.py Copyright (C) 2014, Jordi Vall-llovera -# Multiple display tools for fast navigate/interact with the viewport - -# ##### BEGIN GPL LICENSE BLOCK ##### -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENCE BLOCK ##### -# Contributed to by: -# Jasperge, Pixaal, Meta-androcto, Lapineige, lijenstina, -# Felix Schlitter, Ales Sidenko, Jakub Belcik - -bl_info = { - "name": "Display Tools", - "author": "Jordi Vall-llovera Medina, Jhon Wallace", - "version": (1, 6, 6), - "blender": (2, 79, 0), - "location": "Toolshelf", - "description": "Display tools for fast navigation/interaction with the viewport", - "warning": "", - "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/" - "Py/Scripts/3D_interaction/Display_Tools", - "category": "3D View"} - - -# Import From Files -if "bpy" in locals(): - import importlib - importlib.reload(display) - importlib.reload(fast_navigate) - importlib.reload(modifier_tools) - - importlib.reload(shading_menu) - importlib.reload(select_tools) - importlib.reload(useless_tools) -# importlib.reload(selection_restrictor) - -else: - from . import display - from . import fast_navigate - from . import modifier_tools - - from . import shading_menu - from . import select_tools - from . import useless_tools -# from . import selection_restrictor - -import bpy -from bpy.types import ( - Panel, - PropertyGroup, - AddonPreferences, - ) -from bpy.props import ( - IntProperty, - BoolProperty, - BoolVectorProperty, - EnumProperty, - StringProperty, - PointerProperty, - ) - - -class DISPLAY_PT_ToolsPanel(Panel): - bl_label = "Display Tools" - bl_space_type = "VIEW_3D" - bl_region_type = "UI" - bl_category = "Display" - bl_options = {'DEFAULT_CLOSED'} - - display_type_icons = { - 'BOUNDS': 'SHADING_BBOX', - 'WIRE': 'SHADING_WIRE', - 'SOLID': 'SHADING_SOLID', - 'TEXTURED': 'SHADING_RENDERED' - } - bounds_icons = { - 'BOX': 'MESH_CUBE', - 'SPHERE': 'MATSPHERE', - 'CYLINDER': 'MESH_CYLINDER', - 'CONE': 'MESH_CONE' - } - - def draw(self, context): - scene = context.scene - display_tools = scene.display_tools - render = scene.render - view = context.space_data - obj = context.object - obj_type = obj.type if obj else None - fx_settings = view.fx_settings - - DISPLAYDROP = display_tools.UiTabDrop[0] - SHADINGDROP = display_tools.UiTabDrop[1] - SCENEDROP = display_tools.UiTabDrop[2] - MODIFIERDROP = display_tools.UiTabDrop[3] - SELECT2DROP = display_tools.UiTabDrop[4] - FASTNAVDROP = display_tools.UiTabDrop[5] - icon_active_0 = "TRIA_RIGHT" if not DISPLAYDROP else "TRIA_DOWN" - icon_active_1 = "TRIA_RIGHT" if not SHADINGDROP else "TRIA_DOWN" - icon_active_2 = "TRIA_RIGHT" if not SCENEDROP else "TRIA_DOWN" - icon_active_3 = "TRIA_RIGHT" if not MODIFIERDROP else "TRIA_DOWN" - icon_active_4 = "TRIA_RIGHT" if not SELECT2DROP else "TRIA_DOWN" - icon_active_5 = "TRIA_RIGHT" if not FASTNAVDROP else "TRIA_DOWN" - icon_wt_handler = "X" if display_tools.WT_handler_enable else "MOD_WIREFRAME" - - layout = self.layout - - # Display Scene options - box1 = self.layout.box() - col = box1.column(align=True) - row = col.row(align=True) - row.prop(display_tools, "UiTabDrop", index=2, text="Display", icon=icon_active_2) - - if not SCENEDROP: - if obj: - row.prop(obj, "show_texture_space", text="", icon="UV_DATA") - row.prop(obj, "show_name", text="", icon="OUTLINER_OB_FONT") - row.prop(obj, "show_axis", text="", icon="OBJECT_ORIGIN") - else: - col = layout.column() - col.prop(view, "show_manipulator") - - col = layout.column(align=True) - col.alignment = 'EXPAND' - col.prop(view, "show_only_render", toggle=True) - col.prop(view, "show_world", toggle=True) - col.prop(view, "show_outline_selected", toggle=True) - col.prop(view, "show_all_objects_origin", toggle=True) - col.prop(view, "show_backface_culling", toggle=True) - if obj: - col.prop(obj, "show_in_front", text="X-Ray", toggle=True) - - if obj and obj_type == 'MESH': - col.prop(obj, "show_transparent", text="Transparency", toggle=True) - - col = layout.column() - col.prop(render, "use_simplify", text ="Simplify", toggle=True) - - if render.use_simplify is True: - col = layout.column(align=True) - col.label(text="Settings :") - col.prop(render, "simplify_subdivision", "Subdivision") - col.prop(render, "simplify_shadow_samples", "Shadow Samples") - col.prop(render, "simplify_child_particles", "Child Particles") - col.prop(render, "simplify_ao_sss", "AO and SSS") - - # Draw Type options - box1 = self.layout.box() - col = box1.column(align=True) - row = col.row(align=True) - row.prop(display_tools, "UiTabDrop", index=0, text="Draw Type", icon=icon_active_0) - - if not DISPLAYDROP: - hide_wires = row.operator("ut.wire_show_hide", icon="MESH_CIRCLE", text="") - hide_wires.show = False - hide_wires.selected = False - show_wires = row.operator("ut.wire_show_hide", icon="MESH_UVSPHERE", text="") - show_wires.show = True - show_wires.selected = False - row.operator("ut.all_edges", icon="MESH_GRID", text="").on = True - else: - if obj: - col = layout.column(align=True) - col.alignment = 'EXPAND' - col.label(text="Display As:") - col.prop(obj, "display_type", text="", icon=self.display_type_icons[obj.display_type]) - - col = layout.column(align=True) - col.alignment = 'CENTER' - col.label(text="Selected Object(s):") - row = col.row(align=True) - row.operator("view3d.display_draw_change", text="Wire", - icon='SHADING_WIRE').drawing = 'WIRE' - row.operator("view3d.display_draw_change", text="Solid", - icon='SOLID').drawing = 'SOLID' - row = col.row() - row = col.row(align=True) - row.operator("view3d.display_draw_change", text="Textured", - icon="TEXTURE_SHADED").drawing = 'TEXTURED' - row.operator("view3d.display_draw_change", text="Bounds", - icon="BBOX").drawing = 'BOUNDS' - - col = layout.column(align=True) - col.alignment = 'CENTER' - col.label(text="Wire Overlay:") - - row = col.row() - row.operator("object.wt_selection_handler_toggle", icon=icon_wt_handler) - - col = layout.column(align=True) - col.alignment = 'CENTER' - row = col.row(align=True) - row.operator("object.wt_hide_all_wire", icon="SOLID", text="Hide All") - row.operator("af_ops.wire_all", text="Toggle", icon="WIRE") - - row = col.row() - row1 = col.row(align=True) - hide_wire = row1.operator("ut.wire_show_hide", icon="MATSPHERE", text="Hide") - hide_wire.show = False - hide_wire.selected = True - show_wire = row1.operator("ut.wire_show_hide", icon="MESH_UVSPHERE", text="Show") - show_wire.show = True - show_wire.selected = True - - col = layout.column(align=True) - col.alignment = 'CENTER' - row = col.row() - row3 = col.row(align=True) - row3.alignment = 'CENTER' - row3.label(text="All Edges:") - row3.operator("ut.all_edges", icon="MESH_PLANE", text="Off").on = False - row3.operator("ut.all_edges", icon="MESH_GRID", text="On").on = True - - col = layout.column(align=True) - col.alignment = 'EXPAND' - col.label(text="Bounding Box:") - row = col.row() - row.prop(display_tools, "BoundingMode", text="Type") - row = col.row() - col.separator() - col.operator("view3d.display_bounds_switch", "Bounds On", - icon='BBOX').bounds = True - col.operator("view3d.display_bounds_switch", "Bounds Off", - icon='BBOX').bounds = False - - # Shading options - box1 = self.layout.box() - col = box1.column(align=True) - row = col.row(align=True) - row.prop(display_tools, "UiTabDrop", index=1, text="Shading", icon=icon_active_1) - - if not SHADINGDROP: - row.operator("object.shade_smooth", icon="SMOOTH", text="") - row.operator("object.shade_flat", icon="MESH_ICOSPHERE", text="") - row.menu("VIEW3D_MT_Shade_menu", icon='SOLID', text="") - else: - col = layout.column(align=True) - col.alignment = 'EXPAND' - - if not scene.render.use_shading_nodes: - col.prop("material_mode", text="", toggle=True) - - if view.viewport_shade == 'SOLID': - col.prop(view, "show_textured_solid", toggle=True) - col.prop(view, "use_matcap", toggle=True) - if view.use_matcap: - col.template_icon_view(view, "matcap_icon") - if view.viewport_shade == 'TEXTURED' or context.mode == 'PAINT_TEXTURE': - if scene.render.use_shading_nodes: - col.prop(view, "show_textured_shadeless", toggle=True) - - col.prop(view, "show_backface_culling", toggle=True) - - if view.viewport_shade not in {'BOUNDBOX', 'WIREFRAME'}: - if obj and obj.mode == 'EDIT': - col.prop(view, "show_occlude_wire", toggle=True) - if obj and obj_type == 'MESH' and obj.mode in {'EDIT'}: - col = layout.column(align=True) - col.label(text="Faces:") - row = col.row(align=True) - row.operator("mesh.faces_shade_smooth", text="Smooth") - row.operator("mesh.faces_shade_flat", text="Flat") - col.label(text="Edges:") - row = col.row(align=True) - row.operator("mesh.mark_sharp", text="Smooth").clear = True - row.operator("mesh.mark_sharp", text="Sharp") - col.label(text="Vertices:") - row = col.row(align=True) - props = row.operator("mesh.mark_sharp", text="Smooth") - props.use_verts = True - props.clear = True - row.operator("mesh.mark_sharp", text="Sharp").use_verts = True - - col = layout.column(align=True) - col.label(text="Normals:") - col.operator("mesh.normals_make_consistent", text="Recalculate") - col.operator("mesh.flip_normals", text="Flip Direction") - col.operator("mesh.set_normals_from_faces", text="Set From Faces") - col.separator() - - if view.viewport_shade not in {'BOUNDBOX', 'WIREFRAME'}: - sub = col.column() - sub.active = view.region_3d.view_perspective == 'CAMERA' - sub.prop(fx_settings, "use_dof", toggle=True) - col.prop(fx_settings, "use_ssao", text="Ambient Occlusion", toggle=True) - if fx_settings.use_ssao: - ssao_settings = fx_settings.ssao - subcol = col.column(align=True) - subcol.prop(ssao_settings, "factor") - subcol.prop(ssao_settings, "distance_max") - subcol.prop(ssao_settings, "attenuation") - subcol.prop(ssao_settings, "samples") - subcol.prop(ssao_settings, "color") - - # Modifier options - box1 = self.layout.box() - col = box1.column(align=True) - row = col.row(align=True) - row.prop(display_tools, "UiTabDrop", index=3, text="Modifiers", icon=icon_active_3) - - if not MODIFIERDROP: - mod_all_hide = row.operator("ut.subsurf_show_hide", icon="MOD_SOLIDIFY", text="") - mod_all_hide.show = False - mod_all_hide.selected = False - mod_all_show = row.operator("ut.subsurf_show_hide", icon="MOD_SUBSURF", text="") - mod_all_show.show = True - mod_all_show.selected = False - mod_optimal = row.operator("ut.optimaldisplay", icon="MESH_PLANE", text="") - mod_optimal.on = True - mod_optimal.selected = False - else: - col = layout.column(align=True) - col.alignment = 'EXPAND' - - row = col.row(align=True) - row.label(text="Viewport Visibility:", icon="RESTRICT_VIEW_OFF") - row = col.row(align=True) - row.operator("view3d.toggle_apply_modifiers_view", text="Viewport Vis") - col.separator() - - row = col.row() - row.label(text="Render Visibility:", icon="RENDER_STILL") - row = col.row(align=True) - row.operator("view3d.display_modifiers_render_switch", text="On").mod_render = True - row.operator("view3d.display_modifiers_render_switch", text="Off").mod_render = False - col.separator() - - row = col.row() - row.label(text="Subsurf Visibility:", icon="ALIASED") - - col = layout.column(align=True) - row1 = col.row(align=True) - mod_all2_hide = row1.operator("ut.subsurf_show_hide", icon="MOD_SOLIDIFY", text="Hide") - mod_all2_hide.show = False - mod_all2_hide.selected = True - mod_all2_show = row1.operator("ut.subsurf_show_hide", icon="MOD_SUBSURF", text="Show") - mod_all2_show.show = True - mod_all2_show.selected = True - - row2 = col.row(align=True) - mod_sel_hide = row2.operator("ut.subsurf_show_hide", icon="MOD_SOLIDIFY", text="Hide All") - mod_sel_hide.show = False - mod_sel_hide.selected = False - mod_sel_show = row2.operator("ut.subsurf_show_hide", icon="MOD_SUBSURF", text="Show All") - mod_sel_show.show = True - mod_sel_show.selected = False - col.separator() - - col = layout.column() - row = col.row(align=True) - row.label(text="Edit Mode:", icon="EDITMODE_HLT") - row = col.row(align=True) - row.operator("view3d.display_modifiers_edit_switch", text="On").mod_edit = True - row.operator("view3d.display_modifiers_edit_switch", text="Off").mod_edit = False - col.separator() - - row = col.row() - row.label(text="Modifier Cage:", icon="MOD_LATTICE") - row = col.row(align=True) - row.operator("view3d.display_modifiers_cage_set", text="On").set_cage = True - row.operator("view3d.display_modifiers_cage_set", text="Off").set_cage = False - col.separator() - - row = col.row(align=True) - row.label(text="Subdivision Level:", icon="MOD_SUBSURF") - - row = col.row(align=True) - row.operator("view3d.modifiers_subsurf_level_set", text="0").level = 0 - row.operator("view3d.modifiers_subsurf_level_set", text="1").level = 1 - row.operator("view3d.modifiers_subsurf_level_set", text="2").level = 2 - row.operator("view3d.modifiers_subsurf_level_set", text="3").level = 3 - row.operator("view3d.modifiers_subsurf_level_set", text="4").level = 4 - row.operator("view3d.modifiers_subsurf_level_set", text="5").level = 5 - row.operator("view3d.modifiers_subsurf_level_set", text="6").level = 6 - - # Selection options - box1 = self.layout.box() - col = box1.column(align=True) - row = col.row(align=True) - row.prop(display_tools, "UiTabDrop", index=4, text="Selection", icon=icon_active_4) - - if not SELECT2DROP: - row.operator("view3d.select_box", text="", icon="MESH_PLANE") - row.operator("view3d.select_circle", text="", icon="MESH_CIRCLE") - row.label(text="", icon="BLANK1") - else: - if obj and obj.mode == 'OBJECT': - col = layout.column(align=True) - col.label(text="Render Visibility:") - col.operator("op.render_show_all_selected", icon="RESTRICT_VIEW_OFF") - col.operator("op.render_hide_all_selected", icon="RESTRICT_VIEW_ON") - col.label(text="Show/Hide:") - col.operator("opr.show_hide_object", text="Show/Hide", icon="GHOST_ENABLED") - col.operator("opr.show_all_objects", text="Show All", icon="RESTRICT_VIEW_OFF") - col.operator("opr.hide_all_objects", text="Hide Inactive", icon="RESTRICT_VIEW_ON") - - if obj: - if obj.mode == 'OBJECT': - col = layout.column(align=True) - col.operator_menu_enum("object.show_by_type", "type", text="Show By Type") - col.operator_menu_enum("object.hide_by_type", "type", text="Hide By Type") - layout.label(text="Selection:") - col = layout.column(align=True) - col.operator_menu_enum("object.select_by_type", "type", - text="Select All by Type...") - - if obj_type == 'MESH' and obj.mode == 'EDIT': - col = layout.column(align=True) - col.operator("mesh.select_linked", icon="ROTATECOLLECTION") - col.operator("opr.loop_multi_select", icon="OUTLINER_DATA_MESH") - - col = layout.column(align=True) - col.operator("opr.select_all", icon="MOD_MESHDEFORM") - col.operator("opr.inverse_selection", icon="MOD_REMESH") - - # fast nav options - box1 = layout.box() - col = box1.column(align=True) - row = col.row(align=True) - row.prop(display_tools, "UiTabDrop", index=5, text="Fast Nav", icon=icon_active_5) - - if not FASTNAVDROP: - row.operator("view3d.fast_navigate_operator", text="", icon="NEXT_KEYFRAME") - row.operator("view3d.fast_navigate_stop", text="", icon="PANEL_CLOSE") - row.label(text="", icon="BLANK1") - else: - col = layout.column(align=True) - col.operator("view3d.fast_navigate_operator", icon="NEXT_KEYFRAME") - col.operator("view3d.fast_navigate_stop", icon="PANEL_CLOSE") - - layout.label(text="Settings:") - layout.prop(display_tools, "OriginalMode") - layout.prop(display_tools, "FastMode") - layout.prop(display_tools, "EditActive", "Edit mode") - - layout.prop(display_tools, "Delay") - col = layout.column(align=True) - col.active = display_tools.Delay - col.prop(display_tools, "DelayTimeGlobal", "Delay time") - - layout.prop(display_tools, "ShowParticles") - col = layout.column(align=True) - col.active = display_tools.ShowParticles - col.prop(display_tools, "InitialParticles") - col.prop(display_tools, "ParticlesPercentageDisplay") - - col = layout.column(align=True) - col.label(text="Screen Active Area:") - col.prop(display_tools, "ScreenStart") - col.prop(display_tools, "ScreenEnd") - - -# define scene props -class display_tools_scene_props(PropertyGroup): - # Init delay variables - Delay: BoolProperty( - default=False, - description="Activate delay return to normal viewport mode" - ) - DelayTime: IntProperty( - default=30, - min=0, - max=500, - soft_min=10, - soft_max=250, - description="Delay time to return to normal viewport" - "mode after move your mouse cursor" - ) - DelayTimeGlobal: IntProperty( - default=30, - min=1, - max=500, - soft_min=10, - soft_max=250, - description="Delay time to return to normal viewport" - "mode after move your mouse cursor" - ) - # Init variable for fast navigate - EditActive: BoolProperty( - default=True, - description="Activate for fast navigate in edit mode too" - ) - # Init properties for scene - FastNavigateStop: BoolProperty( - name="Fast Navigate Stop", - description="Stop fast navigate mode", - default=False - ) - OriginalMode: EnumProperty( - items=[('TEXTURED', 'Texture', 'Texture display mode'), - ('SOLID', 'Solid', 'Solid display mode')], - name="Normal", - default='SOLID' - ) - BoundingMode: EnumProperty( - items=[('BOX', 'Box', 'Box shape'), - ('SPHERE', 'Sphere', 'Sphere shape'), - ('CYLINDER', 'Cylinder', 'Cylinder shape'), - ('CONE', 'Cone', 'Cone shape')], - name="BB Mode" - ) - FastMode: EnumProperty( - items=[('WIREFRAME', 'Wireframe', 'Wireframe display'), - ('BOUNDBOX', 'Bounding Box', 'Bounding Box display')], - name="Fast" - ) - ShowParticles: BoolProperty( - name="Show Particles", - description="Show or hide particles on fast navigate mode", - default=True - ) - ParticlesPercentageDisplay: IntProperty( - name="Fast Display", - description="Display only a percentage of particles when active", - default=25, - min=0, - max=100, - soft_min=0, - soft_max=100, - subtype='FACTOR' - ) - InitialParticles: IntProperty( - name="Normal Display", - description="When idle, how much particles are displayed\n" - "Overrides the Particles settings", - default=100, - min=0, - max=100, - soft_min=0, - soft_max=100 - ) - Symplify: IntProperty( - name="Integer", - description="Enter an integer" - ) - ScreenStart: IntProperty( - name="Left Limit", - default=0, - min=0, - max=1024, - subtype='PIXEL', - description="Limit the screen active area width from the left side\n" - "Changed values will take effect on the next run", - ) - ScreenEnd: IntProperty( - name="Right Limit", - default=0, - min=0, - max=1024, - subtype='PIXEL', - description="Limit the screen active area width from the right side\n" - "Changed values will take effect on the next run", - ) - # Define the UI drop down prop - UiTabDrop: BoolVectorProperty( - name="Tab", - description="Expand/Collapse UI elements", - default=(False,) * 6, - size=6, - ) - WT_handler_enable: BoolProperty( - default=False - ) - WT_handler_previous_object: StringProperty( - default="" - ) - - -# Addons Preferences Update Panel -# Define Panels for updating -panels = ( - DISPLAY_PT_ToolsPanel, - ) - - -def update_panel(self, context): - message = "Display Tools: Updating Panel locations has failed" - try: - for panel in panels: - if "bl_rna" in panel.__dict__: - bpy.utils.unregister_class(panel) - - for panel in panels: - panel.bl_category = context.preferences.addons[__name__].preferences.category - bpy.utils.register_class(panel) - - except Exception as e: - print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e)) - pass - - -class DisplayToolsPreferences(AddonPreferences): - # this must match the addon name, use '__package__' - # when defining this in a submodule of a python package. - bl_idname = __name__ - - category: StringProperty( - name="Tab Category", - description="Choose a name for the category of the panel", - default="Display", - update=update_panel - ) - - def draw(self, context): - layout = self.layout - row = layout.row() - col = row.column() - col.label(text="Tab Category:") - 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 -classes = [ - DISPLAY_PT_ToolsPanel, - display_tools_scene_props, - DisplayToolsPreferences -] - -# register the classes and props -def register(): - from bpy.utils import register_class - for cls in classes: - register_class(cls) - - 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 - ) - update_panel(None, bpy.context) -# selection_restrictor.register() - - -def unregister(): -# selection_restrictor.unregister() - bpy.types.VIEW3D_MT_object_showhide.remove(DRAW_hide_by_type_MENU) - from bpy.utils import unregister_class - for cls in reversed(classes): - unregister_class(cls) - del bpy.types.Scene.display_tools - - -if __name__ == "__main__": - register() diff --git a/space_view3d_display_tools/display.py b/space_view3d_display_tools/display.py deleted file mode 100644 index a0ed0e87..00000000 --- a/space_view3d_display_tools/display.py +++ /dev/null @@ -1,224 +0,0 @@ -# space_view_3d_display_tools.py Copyright (C) 2014, Jordi Vall-llovera -# Multiple display tools for fast navigate/interact with the viewport -# wire tools by Lapineige - -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ***** END GPL LICENCE BLOCK ***** - - -import bpy -from bpy.types import Operator -from bpy.props import ( - BoolProperty, - EnumProperty, - ) - - -# define base dummy class for inheritance -class BasePollCheck: - @classmethod - def poll(cls, context): - return True - - -class View3D_AF_Wire_All(Operator): - bl_idname = "af_ops.wire_all" - bl_label = "Wire on All Objects" - bl_description = "Toggle Wire on all objects in the scene" - - @classmethod - def poll(cls, context): - return (context.active_object is not None and - not context.scene.display_tools.WT_handler_enable) - - def execute(self, context): - - for obj in bpy.data.objects: - if obj.show_wire: - obj.show_wire = False - else: - obj.show_wire = True - - return {'FINISHED'} - - -# Change draw type -class DisplayDrawChange(Operator, BasePollCheck): - bl_idname = "view3d.display_draw_change" - bl_label = "Draw Type" - bl_description = "Change Display objects' mode" - - drawing: EnumProperty( - items=[('TEXTURED', 'Texture', 'Texture display mode'), - ('SOLID', 'Solid', 'Solid display mode'), - ('WIRE', 'Wire', 'Wire display mode'), - ('BOUNDS', 'Bounds', 'Bounds display mode'), - ], - name="Draw Type", - default='SOLID' - ) - - def execute(self, context): - try: - view = context.space_data - view.viewport_shade = 'TEXTURED' - context.scene.game_settings.material_mode = 'GLSL' - selection = context.selected_objects - - if not selection: - for obj in bpy.data.objects: - obj.display_type = self.drawing - else: - for obj in selection: - obj.display_type = self.drawing - except: - self.report({'ERROR'}, "Setting Draw Type could not be applied") - return {'CANCELLED'} - - return {'FINISHED'} - - -# Bounds switch -class DisplayBoundsSwitch(Operator, BasePollCheck): - bl_idname = "view3d.display_bounds_switch" - bl_label = "On/Off" - bl_description = "Display/Hide Bounding box overlay" - - bounds: BoolProperty(default=False) - - def execute(self, context): - try: - scene = context.scene.display_tools - selection = context.selected_objects - - if not selection: - for obj in bpy.data.objects: - obj.show_bounds = self.bounds - if self.bounds: - obj.display_bounds_type = scene.BoundingMode - else: - for obj in selection: - obj.show_bounds = self.bounds - if self.bounds: - obj.display_bounds_type = scene.BoundingMode - except: - self.report({'ERROR'}, "Display/Hide Bounding box overlay failed") - return {'CANCELLED'} - - return {'FINISHED'} - - -# XRay switch -class DisplayXRayOn(Operator, BasePollCheck): - bl_idname = "view3d.display_x_ray_switch" - bl_label = "On" - bl_description = "X-Ray display on/off" - - xrays: BoolProperty(default=False) - - def execute(self, context): - try: - selection = context.selected_objects - - if not selection: - for obj in bpy.data.objects: - obj.show_in_front = self.xrays - else: - for obj in selection: - obj.show_in_front = self.xrays - except: - self.report({'ERROR'}, "Turn on/off X-ray mode failed") - return {'CANCELLED'} - - return {'FINISHED'} - - -# wire tools by Lapineige -class WT_HideAllWire(Operator): - bl_idname = "object.wt_hide_all_wire" - bl_label = "Hide Wire And Edges" - bl_description = "Hide All Objects' wire and edges" - - @classmethod - def poll(cls, context): - return not context.scene.display_tools.WT_handler_enable - - def execute(self, context): - for obj in bpy.data.objects: - if hasattr(obj, "show_wire"): - obj.show_wire, obj.show_all_edges = False, False - return {'FINISHED'} - - -class WT_SelectionHandlerToggle(Operator): - bl_idname = "object.wt_selection_handler_toggle" - bl_label = "Wire Selection (auto)" - bl_description = "Display the wire of the selection, auto update when selecting another object" - bl_options = {'INTERNAL'} - - def execute(self, context): - display_tools = context.scene.display_tools - if display_tools.WT_handler_enable: - try: - bpy.app.handlers.scene_update_post.remove(wire_on_selection_handler) - except: - self.report({'INFO'}, - "Wire Selection: auto mode exit seems to have failed. If True, reload the file") - - display_tools.WT_handler_enable = False - if hasattr(context.object, "show_wire"): - context.object.show_wire, context.object.show_all_edges = False, False - else: - bpy.app.handlers.scene_update_post.append(wire_on_selection_handler) - display_tools.WT_handler_enable = True - if hasattr(context.object, "show_wire"): - context.object.show_wire, context.object.show_all_edges = True, True - return {'FINISHED'} - - -# handler -def wire_on_selection_handler(scene): - obj = bpy.context.object - - if not scene.display_tools.WT_handler_previous_object: - if hasattr(obj, "show_wire"): - obj.show_wire, obj.show_all_edges = True, True - scene.display_tools.WT_handler_previous_object = obj.name - else: - if scene.display_tools.WT_handler_previous_object != obj.name: - previous_obj = bpy.data.objects[scene.display_tools.WT_handler_previous_object] - if hasattr(previous_obj, "show_wire"): - previous_obj.show_wire, previous_obj.show_all_edges = False, False - - scene.display_tools.WT_handler_previous_object = obj.name - - if hasattr(obj, "show_wire"): - obj.show_wire, obj.show_all_edges = True, True - - -# Register -def register(): - bpy.utils.register_module(__name__) - - -def unregister(): - bpy.utils.unregister_module(__name__) - - -if __name__ == "__main__": - register() diff --git a/space_view3d_display_tools/fast_navigate.py b/space_view3d_display_tools/fast_navigate.py deleted file mode 100644 index e3577df5..00000000 --- a/space_view3d_display_tools/fast_navigate.py +++ /dev/null @@ -1,278 +0,0 @@ -# space_view_3d_display_tools.py Copyright (C) 2014, Jordi Vall-llovera -# Multiple display tools for fast navigate/interact with the viewport - -# ##### BEGIN GPL LICENSE BLOCK ##### -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENCE BLOCK ##### - -""" -Additional links: - Author Site: http://www.jordiart.com -""" - -import bpy -from bpy.types import Operator -from bpy.props import BoolProperty -from collections import defaultdict - - -# Fast Navigate toggle function -def trigger_fast_navigate(trigger): - scene = bpy.context.scene.display_tools - scene.FastNavigateStop = False - trigger = not trigger - - -# Control how to display particles during fast navigate -def display_particles(mode, dis_particles): - scene = bpy.context.scene.display_tools - - for particles in bpy.data.particles: - if scene.ShowParticles is False: - particles.display_method = 'NONE' - else: - if particles.type == 'EMITTER': - particles.display_method = 'DOT' - particles.display_percentage = 100 - else: - particles.display_method = 'RENDER' - particles.display_percentage = dis_particles - - return dis_particles - - -# Fast Navigate operator -class FastNavigate(Operator): - bl_idname = "view3d.fast_navigate_operator" - bl_label = "Fast Navigate" - bl_description = ("Limit the objects drawing in the 3D view for faster navigation\n" - "Runs in modal mode until Stop is pressed or Esc, Return, Space") - - trigger: BoolProperty(default=False) - mode: BoolProperty(default=False) - screen_width = [0, 0] - store_fail = False - store_init_particles = {} - store_viewport_shade = None - check_particles_draw = False - fast_particles_draw = 0 - - def modal(self, context, event): - context.area.tag_redraw() - scene = context.scene.display_tools - - if scene.FastNavigateStop is True: - self.execute(context) - return {'FINISHED'} - - if context.area.type != 'VIEW_3D': - self.execute(context) - return {'FINISHED'} - - if scene.EditActive is True: - self.fast_navigate_stuff(context, event) - return {'PASS_THROUGH'} - else: - obj = context.active_object - if obj: - if obj.mode != 'EDIT': - self.fast_navigate_stuff(context, event) - return {'PASS_THROUGH'} - else: - return {'PASS_THROUGH'} - else: - self.fast_navigate_stuff(context, event) - return {'PASS_THROUGH'} - - return {'RUNNING_MODAL'} - - def invoke(self, context, event): - if context.area.type != 'VIEW_3D': - self.report({'WARNING'}, - "Fast Navigate: View3D not found. Operation Cancelled") - return {'CANCELLED'} - - self.store_init_particles = defaultdict(list) - self.store_fail = False - - context.window_manager.modal_handler_add(self) - trigger_fast_navigate(self.trigger) - scene = context.scene.display_tools - scene.DelayTime = scene.DelayTimeGlobal - self.get_screen_size(context, scene) - self.start_settings_store(context, store=False) - self.check_particles_draw = True - - return {'RUNNING_MODAL'} - - def execute(self, context): - scene = context.scene.display_tools - scene.FastNavigateStop = True - - self.start_settings_store(context, store=True) - - mess, mess_txt = ('WARNING', "Fast Navigate: Some Settings could not be restored") if \ - self.store_fail else ('INFO', "Exited the Fast Navigate mode") - - self.report({mess}, mess_txt) - - return {'FINISHED'} - - @staticmethod - def calc_delay(scene): - if scene.Delay is True: - if scene.DelayTime < scene.DelayTimeGlobal: - scene.DelayTime += 1 - - def start_settings_store(self, context, store=False): - try: - view = context.space_data - shade = view.viewport_shade if view.type == 'VIEW_3D' else None - if store is False: - if not shade: - self.store_fail = True - else: - self.store_viewport_shade = shade - for particle in bpy.data.particles: - self.store_init_particles[particle.name] = \ - [particle.display_method, particle.display_percentage] - else: - if not shade: - self.store_fail = True - else: - shade = self.store_viewport_shade or 'SOLID' - for particle in bpy.data.particles: - particle.display_method = self.store_init_particles[particle.name][0] - particle.display_percentage = self.store_init_particles[particle.name][1] - except: - self.store_fail = True - - def get_screen_size(self, context, scene): - if context.area.type == 'VIEW_3D': - coord_x = context.area.x + scene.ScreenStart - coord_max_x = context.area.width - scene.ScreenEnd - self.screen_width = [coord_x, coord_max_x] - - # Do repetitive fast navigate related stuff - def fast_navigate_stuff(self, context, event): - scene = context.scene.display_tools - view = context.space_data - - if scene.FastNavigateStop is True: - return {'FINISHED'} - - if context.area.type != 'VIEW_3D': - scene.FastNavigateStop = True - return {'FINISHED'} - - if event.type in {'ESC', 'RET', 'SPACE'}: - scene.FastNavigateStop = True - return {'CANCELLED'} - - # limit the active area - if event.mouse_x not in range(self.screen_width[0], self.screen_width[1]): - return {'PASS_THROUGH'} - - # fast navigate while orbit/panning - if event.type == 'MIDDLEMOUSE': - self.calc_delay(scene) - view.viewport_shade = scene.FastMode - self.mode = False - - # fast navigate while transform operations - if event.type in {'G', 'R', 'S'}: - self.calc_delay(scene) - view.viewport_shade = scene.FastMode - self.mode = False - - # fast navigate while menu popups or duplicates - if event.type in {'W', 'D', 'L', 'U', 'I', 'M', 'A', 'B'}: - self.calc_delay(scene) - view.viewport_shade = scene.FastMode - self.mode = False - - # fast navigate while numpad navigation - if event.type in {'NUMPAD_PERIOD', 'NUMPAD_1', 'NUMPAD_2', 'NUMPAD_3', - 'NUMPAD_4', 'NUMPAD_5', 'NUMPAD_6', 'NUMPAD_7', - 'NUMPAD_8', 'NUMPAD_9'}: - self.calc_delay(scene) - view.viewport_shade = scene.FastMode - self.mode = False - - # fast navigate while zooming with mousewheel too - if event.type in {'WHEELUPMOUSE', 'WHEELDOWNMOUSE'}: - scene.DelayTime = scene.DelayTimeGlobal - view.viewport_shade = scene.FastMode - self.mode = False - - if event.type == 'MOUSEMOVE': - if scene.Delay is True: - if scene.DelayTime == 0: - view.viewport_shade = scene.OriginalMode - scene.DelayTime = scene.DelayTimeGlobal - self.mode = True - else: - view.viewport_shade = scene.OriginalMode - self.mode = True - - if scene.Delay is True: - scene.DelayTime -= 1 - if scene.DelayTime == 0: - view.viewport_shade = scene.OriginalMode - scene.DelayTime = scene.DelayTimeGlobal - self.mode = True - - # update particles draw (only update call when the fast draw or the percentage are changed) - self.check_particles_draw = not self.mode - dis_particles = scene.InitialParticles if self.mode else scene.ParticlesPercentageDisplay - - if self.check_particles_draw is True: - self.fast_particles_draw = display_particles(self.mode, dis_particles) - else: - if self.fast_particles_draw != dis_particles: - self.fast_particles_draw = display_particles(self.mode, dis_particles) - - -# Fast Navigate Stop -def fast_navigate_stop(context): - scene = context.scene.display_tools - scene.FastNavigateStop = True - - -# Fast Navigate Stop Operator -class FastNavigateStop(Operator): - bl_idname = "view3d.fast_navigate_stop" - bl_label = "Stop" - bl_description = "Stop Fast Navigate" - - def execute(self, context): - fast_navigate_stop(context) - - return {'FINISHED'} - - -# Register -def register(): - bpy.utils.register_module(__name__) - - -def unregister(): - bpy.utils.unregister_module(__name__) - - -if __name__ == "__main__": - register() diff --git a/space_view3d_display_tools/modifier_tools.py b/space_view3d_display_tools/modifier_tools.py deleted file mode 100644 index a04c731d..00000000 --- a/space_view3d_display_tools/modifier_tools.py +++ /dev/null @@ -1,250 +0,0 @@ -# space_view_3d_display_tools.py Copyright (C) 2014, Jordi Vall-llovera -# Multiple display tools for fast navigate/interact with the viewport - -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ***** END GPL LICENCE BLOCK ***** - -""" -Additional links: - Author Site: http://www.jordiart.com -""" - -import bpy -from bpy.types import Operator -from bpy.props import ( - IntProperty, - BoolProperty, - ) - - -# function taken from space_view3d_modifier_tools.py -class DisplayApplyModifiersView(Operator): - bl_idname = "view3d.toggle_apply_modifiers_view" - bl_label = "Hide Viewport" - bl_description = "Shows/Hide modifiers of the active / selected object(s) in 3d View" - - @classmethod - def poll(cls, context): - return context.active_object is not None - - def execute(self, context): - is_apply = True - message_a = "" - for mod in context.active_object.modifiers: - if mod.show_viewport: - is_apply = False - break - - # active object - no selection - for mod in context.active_object.modifiers: - mod.show_viewport = is_apply - - for obj in context.selected_objects: - for mod in obj.modifiers: - mod.show_viewport = is_apply - - if is_apply: - message_a = "Displaying modifiers in the 3d View" - else: - message_a = "Hiding modifiers in the 3d View" - - self.report(type={"INFO"}, message=message_a) - - return {'FINISHED'} - - -# define base dummy class for inheritance -class BasePollCheck: - @classmethod - def poll(cls, context): - return True - - -# Set Render Settings -def set_render_settings(context): - scene = context.scene - render = scene.render - render.simplify_subdivision = 0 - render.simplify_shadow_samples = 0 - render.simplify_child_particles = 0 - render.simplify_ao_sss = 0 - - -# Display Modifiers Render Switch -class DisplayModifiersRenderSwitch(Operator, BasePollCheck): - bl_idname = "view3d.display_modifiers_render_switch" - bl_label = "On/Off" - bl_description = "Display/Hide modifiers on render" - - mod_render: BoolProperty(default=True) - - def execute(self, context): - try: - if self.mod_render: - scene = context.scene.display_tools - scene.Simplify = 1 - - selection = context.selected_objects - - if not selection: - for obj in bpy.data.objects: - for mod in obj.modifiers: - mod.show_render = self.mod_render - else: - for obj in selection: - for mod in obj.modifiers: - mod.show_render = self.mod_render - except: - self.report({'ERROR'}, "Display/Hide all modifiers for render failed") - return {'CANCELLED'} - - return {'FINISHED'} - - -# Display Modifiers Viewport switch -class DisplayModifiersViewportSwitch(Operator, BasePollCheck): - bl_idname = "view3d.display_modifiers_viewport_switch" - bl_label = "On/Off" - bl_description = "Display/Hide modifiers in the viewport" - - mod_switch: BoolProperty(default=True) - - def execute(self, context): - try: - selection = context.selected_objects - - if not(selection): - for obj in bpy.data.objects: - for mod in obj.modifiers: - mod.show_viewport = self.mod_switch - else: - for obj in selection: - for mod in obj.modifiers: - mod.show_viewport = self.mod_switch - except: - self.report({'ERROR'}, "Display/Hide modifiers in the viewport failed") - return {'CANCELLED'} - - return {'FINISHED'} - - -# Display Modifiers Edit Switch -class DisplayModifiersEditSwitch(Operator, BasePollCheck): - bl_idname = "view3d.display_modifiers_edit_switch" - bl_label = "On/Off" - bl_description = "Display/Hide modifiers during edit mode" - - mod_edit: BoolProperty(default=True) - - def execute(self, context): - try: - selection = context.selected_objects - - if not(selection): - for obj in bpy.data.objects: - for mod in obj.modifiers: - mod.show_in_editmode = self.mod_edit - else: - for obj in selection: - for mod in obj.modifiers: - mod.show_in_editmode = self.mod_edit - except: - self.report({'ERROR'}, "Display/Hide all modifiers failed") - return {'CANCELLED'} - - return {'FINISHED'} - - -class DisplayModifiersCageSet(Operator, BasePollCheck): - bl_idname = "view3d.display_modifiers_cage_set" - bl_label = "On/Off" - bl_description = "Display modifiers editing cage during edit mode" - - set_cage: BoolProperty(default=True) - - def execute(self, context): - selection = context.selected_objects - try: - if not selection: - for obj in bpy.data.objects: - for mod in obj.modifiers: - mod.show_on_cage = self.set_cage - else: - for obj in selection: - for mod in obj.modifiers: - mod.show_on_cage = self.set_cage - except: - self.report({'ERROR'}, "Setting Editing Cage all modifiers failed") - return {'CANCELLED'} - - return {'FINISHED'} - - -class ModifiersSubsurfLevel_Set(Operator, BasePollCheck): - bl_idname = "view3d.modifiers_subsurf_level_set" - bl_label = "Set Subsurf level" - bl_description = "Change subsurf modifier level" - - level: IntProperty( - name="Subsurf Level", - description="Change subsurf modifier level", - default=1, - min=0, - max=10, - soft_min=0, - soft_max=6 - ) - - def execute(self, context): - selection = context.selected_objects - try: - if not selection: - for obj in bpy.data.objects: - context.view_layer.objects.active = obj - bpy.ops.object.modifier_add(type='SUBSURF') - value = 0 - for mod in obj.modifiers: - if mod.type == 'SUBSURF': - value = value + 1 - mod.levels = self.level - if value > 1: - bpy.ops.object.modifier_remove(modifier="Subsurf") - else: - for obj in selection: - bpy.ops.object.subdivision_set(level=self.level, relative=False) - for mod in obj.modifiers: - if mod.type == 'SUBSURF': - mod.levels = self.level - except: - self.report({'ERROR'}, "Setting the Subsurf level could not be applied") - return {'CANCELLED'} - - return {'FINISHED'} - - -# Register -def register(): - bpy.utils.register_module(__name__) - - -def unregister(): - bpy.utils.unregister_module(__name__) - - -if __name__ == "__main__": - register() diff --git a/space_view3d_display_tools/scene_vis.py b/space_view3d_display_tools/scene_vis.py deleted file mode 100644 index 594a894f..00000000 --- a/space_view3d_display_tools/scene_vis.py +++ /dev/null @@ -1,50 +0,0 @@ -# space_view_3d_display_tools.py Copyright (C) 2014, Jordi Vall-llovera -# Multiple display tools for fast navigate/interact with the viewport - -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ***** END GPL LICENCE BLOCK ***** - -""" -Additional links: - Author Site: http://www.jordiart.com -""" - -import bpy - - -# Set Render Settings -def set_render_settings(context): - scene = context.scene - render = scene.render - render.simplify_subdivision = 0 - render.simplify_shadow_samples = 0 - render.simplify_child_particles = 0 - render.simplify_ao_sss = 0 - - -# Register -def register(): - bpy.utils.register_module(__name__) - - -def unregister(): - bpy.utils.unregister_module(__name__) - - -if __name__ == "__main__": - register() diff --git a/space_view3d_display_tools/select_tools.py b/space_view3d_display_tools/select_tools.py deleted file mode 100644 index 0835f408..00000000 --- a/space_view3d_display_tools/select_tools.py +++ /dev/null @@ -1,338 +0,0 @@ -# ##### BEGIN GPL LICENSE BLOCK ##### -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENCE BLOCK ##### - - -bl_info = { - "name": "Select Tools", - "author": "Jakub Belcik", - "version": (1, 0, 2), - "blender": (2, 73, 0), - "location": "3D View > Tools", - "description": "Selection Tools", - "warning": "", - "wiki_url": "", - "category": "" -} - -import bpy -from bpy.types import Operator -from bpy.props import ( - BoolProperty, - EnumProperty, - ) - - -class ShowHideObject(Operator): - bl_idname = "opr.show_hide_object" - bl_label = "Show/Hide Object" - bl_description = ("Flip the viewport visibility for all objects in the Data\n" - "(Hidden to Visible and Visible to Hidden)") - bl_options = {'REGISTER', 'UNDO'} - - def execute(self, context): - if context.object is None: - self.report({'INFO'}, - "Show/Hide: No Object found. Operation Cancelled") - return {'CANCELLED'} - - if context.object.mode != 'OBJECT': - self.report({'INFO'}, - "Show/Hide: This operation can be performed only in object mode") - return {'CANCELLED'} - - for i in bpy.data.objects: - try: - if i.hide: - i.hide = False - i.hide_select = False - i.hide_render = False - else: - i.hide = True - i.select_set(False) - - if i.type not in ['CAMERA', 'LIGHT']: - i.hide_render = True - except: - continue - - return {'FINISHED'} - - -class ShowAllObjects(Operator): - bl_idname = "opr.show_all_objects" - bl_label = "Show All Objects" - bl_description = "Show all objects" - bl_options = {'REGISTER', 'UNDO'} - - def execute(self, context): - for i in bpy.data.objects: - try: - i.hide = False - i.hide_select = False - i.hide_render = False - except: - continue - - return {'FINISHED'} - - -class HideAllObjects(Operator): - bl_idname = "opr.hide_all_objects" - bl_label = "Hide All Inactive" - bl_description = "Hide all inactive objects" - bl_options = {'REGISTER', 'UNDO'} - - def execute(self, context): - if context.object is None: - for i in bpy.data.objects: - i.hide = True - i.select_set(False) - - if i.type not in ['CAMERA', 'LIGHT']: - i.hide_render = True - else: - obj_name = context.object.name - - for i in bpy.data.objects: - if i.name != obj_name: - i.hide = True - i.select_set(False) - - if i.type not in ['CAMERA', 'LIGHT']: - i.hide_render = True - - return {'FINISHED'} - - -class SelectAll(Operator): - bl_idname = "opr.select_all" - bl_label = "(De)select All" - bl_description = "(De)select all objects, vertices, edges or faces" - bl_options = {'REGISTER', 'UNDO'} - - def execute(self, context): - if context.object is None: - bpy.ops.object.select_all(action='TOGGLE') - elif context.object.mode == 'EDIT': - bpy.ops.mesh.select_all(action='TOGGLE') - elif context.object.mode == 'OBJECT': - bpy.ops.object.select_all(action='TOGGLE') - else: - self.report({'ERROR'}, - "(De)select All: Cannot perform this operation in this mode") - return {'CANCELLED'} - - return {'FINISHED'} - - -class InverseSelection(Operator): - bl_idname = "opr.inverse_selection" - bl_label = "Inverse Selection" - bl_description = "Inverse selection" - bl_options = {'REGISTER', 'UNDO'} - - def execute(self, context): - if context.object is None: - bpy.ops.object.select_all(action='INVERT') - elif context.object.mode == 'EDIT': - bpy.ops.mesh.select_all(action='INVERT') - elif context.object.mode == 'OBJECT': - bpy.ops.object.select_all(action='INVERT') - else: - self.report({'ERROR'}, - "Inverse Selection: Cannot perform this operation in this mode") - return {'CANCELLED'} - - return {'FINISHED'} - - -class LoopMultiSelect(Operator): - bl_idname = "opr.loop_multi_select" - bl_label = "Edge Loop Select" - bl_description = "Select a loop of connected edges" - bl_options = {'REGISTER', 'UNDO'} - - @classmethod - def poll(cls, context): - return context.active_object is not None - - def execute(self, context): - if context.object.mode != 'EDIT': - self.report({'ERROR'}, "This operation can be performed only in edit mode") - return {'CANCELLED'} - try: - bpy.ops.mesh.loop_multi_select(ring=False) - except: - self.report({'WARNING'}, - "Edge loop select: Operation could not be performed (See Console for more info)") - return {'CANCELLED'} - - return {'FINISHED'} - - -class ShowRenderAllSelected(Operator): - bl_idname = "op.render_show_all_selected" - bl_label = "Render On" - bl_description = "Render all objects" - - def execute(self, context): - for ob in bpy.data.objects: - try: - if ob.select_get() is True: - ob.hide_render = False - except: - continue - - return {'FINISHED'} - - -class HideRenderAllSelected(Operator): - bl_idname = "op.render_hide_all_selected" - bl_label = "Render Off" - bl_description = "Hide Selected Object(s) from Render" - - def execute(self, context): - for ob in bpy.data.objects: - try: - if ob.select_get() is True: - ob.hide_render = True - except: - continue - - return {'FINISHED'} - - -class OBJECT_OT_HideShowByTypeTemplate(): - - bl_options = {'UNDO', 'REGISTER'} - - type: EnumProperty( - items=( - ('MESH', 'Mesh', ''), - ('CURVE', 'Curve', ''), - ('SURFACE', 'Surface', ''), - ('META', 'Meta', ''), - ('FONT', 'Font', ''), - ('ARMATURE', 'Armature', ''), - ('LATTICE', 'Lattice', ''), - ('EMPTY', 'Empty', ''), - ('CAMERA', 'Camera', ''), - ('LIGHT', 'Lamp', ''), - ('ALL', 'All', '')), - name="Type", - description="Type", - default='LIGHT', - 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: BoolProperty( - name="Hide", - description="Inverse effect", - options={'HIDDEN'}, - default=1 - ) - hide_selected: BoolProperty( - name="Selected", - description="Hide only selected objects", - default=0 - ) - hide_render_restricted: 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: BoolProperty( - name="Hide", - description="Inverse effect", - options={'HIDDEN'}, - default=0 - ) - hide_selected: BoolProperty( - name="Selected", - options={'HIDDEN'}, - default=0 - ) - hide_render_restricted: BoolProperty( - name="Only Renderable", - description="Show only non render restricted objects", - default=0 - ) - - -# Register -def register(): - bpy.utils.register_module(__name__) - - -def unregister(): - bpy.utils.unregister_module(__name__) - - -if __name__ == '__main__': - register() diff --git a/space_view3d_display_tools/selection_restrictor.py b/space_view3d_display_tools/selection_restrictor.py deleted file mode 100644 index ca416194..00000000 --- a/space_view3d_display_tools/selection_restrictor.py +++ /dev/null @@ -1,737 +0,0 @@ -# ##### BEGIN GPL LICENSE BLOCK ##### -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENSE BLOCK ##### - - -bl_info = { - "name": "Selection Restrictor", - "author": "Ales Sidenko", - "version": (0, 1, 1), - "location": "3d viewer header", - "warning": "", - "description": "This addon helps to restrict the selection of objects by type. " - "Please email me if you find a bug (sidenkoai@gmail.com)", - "category": "3D View" - } - -import bpy -from bpy.types import ( - Menu, - Operator, - ) -from bpy.props import ( - BoolProperty, - StringProperty, - ) - -from bpy.app.handlers import persistent - -mesh = 'OBJECT_DATA' -curve = 'OUTLINER_OB_CURVE' -arm = 'OUTLINER_OB_ARMATURE' -empty = 'OUTLINER_OB_EMPTY' -cam = 'OUTLINER_OB_CAMERA' -lamp = 'OUTLINER_OB_LIGHT' -lat = 'OUTLINER_OB_LATTICE' -font = 'OUTLINER_OB_FONT' -meta = 'OUTLINER_OB_META' -surf = 'OUTLINER_OB_SURFACE' -speak = 'OUTLINER_OB_SPEAKER' - -show = 'TRIA_RIGHT' -show_restrictor = False -hide = True - - -# checking properties in scene to update icons when opening file -# or switching between scenes (executing in end of script) - -@persistent -def check_restrictors(dummy): - global mesh - global curve - global arm - global empty - global cam - global lamp - global lat - global font - global meta - global surf - global speak - global show - - global meshrestrictorenabled - global curverestrictorenabled - global armrestrictorenabled - global emptyrestrictorenabled - global camrestrictorenabled - global lamprestrictorenabled - global latrestrictorenabled - global fontrestrictorenabled - global metarestrictorenabled - global surfrestrictorenabled - global speakrestrictorenabled - - # show restrictors? - if bpy.context.scene.get('show_restrictor') is not None: - show_restrictor = False - show = 'TRIA_RIGHT' - else: - show_restrictor = True - show = 'TRIA_DOWN' - - # mesh - if bpy.context.scene.get('meshrestrictor') is None: - meshrestrictorenabled = True - mesh = 'OBJECT_DATA' - else: - meshrestrictorenabled = False - mesh = 'MESH_CUBE' - # curve - if bpy.context.scene.get('curverestrictor') is None: - curverestrictorenabled = True - curve = 'OUTLINER_OB_CURVE' - else: - curverestrictorenabled = False - curve = 'CURVE_DATA' - # armature - if bpy.context.scene.get('armrestrictor') is None: - armrestrictorenabled = True - arm = 'OUTLINER_OB_ARMATURE' - else: - armrestrictorenabled = False - arm = 'ARMATURE_DATA' - - # empty - if bpy.context.scene.get('emptyrestrictor') is None: - emptyrestrictorenabled = True - empty = 'OUTLINER_OB_EMPTY' - else: - emptyrestrictorenabled = False - empty = 'EMPTY_DATA' - - # camera - if bpy.context.scene.get('camrestrictor') is None: - camrestrictorenabled = True - cam = 'OUTLINER_OB_CAMERA' - else: - camrestrictorenabled = False - cam = 'CAMERA_DATA' - # lamp - if bpy.context.scene.get('lamprestrictor') is None: - lamprestrictorenabled = True - lamp = 'OUTLINER_OB_LIGHT' - else: - lamprestrictorenabled = False - lamp = 'LIGHT_DATA' - - # lattice - if bpy.context.scene.get('latrestrictor') is None: - latrestrictorenabled = True - lat = 'OUTLINER_OB_LATTICE' - else: - latrestrictorenabled = False - lat = 'LATTICE_DATA' - - # text - if bpy.context.scene.get('fontrestrictor') is None: - fontrestrictorenabled = True - font = 'OUTLINER_OB_FONT' - else: - fontrestrictorenabled = False - font = 'FONT_DATA' - - # metaballs - if bpy.context.scene.get('metarestrictor') is None: - metarestrictorenabled = True - meta = 'OUTLINER_OB_META' - else: - metarestrictorenabled = False - meta = 'META_DATA' - - # surfaces - if bpy.context.scene.get('surfrestrictor') is None: - surfrestrictorenabled = True - surf = 'OUTLINER_OB_SURFACE' - else: - surfrestrictorenabled = False - surf = 'SURFACE_DATA' - - # sounds - if bpy.context.scene.get('speakrestrictor') is None: - speakrestrictorenabled = True - speak = 'OUTLINER_OB_SPEAKER' - else: - speakrestrictorenabled = False - speak = 'SPEAKER' - return{'FINISHED'} - - -# Show / Hide buttons - -class RestrictorShow(Operator): - bl_idname = "restrictor.show" - bl_label = "Show/Hide Selection Restrictors" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Show/Hide Selection Restrictors" - - hide: StringProperty() - - def execute(self, context): - global show - - if bpy.context.scene.get('show_restrictor') is None: - bpy.context.scene['show_restrictor'] = 1 - show = 'TRIA_DOWN' - else: - if bpy.context.scene.get('show_restrictor') is not None: - del bpy.context.scene['show_restrictor'] - show = 'TRIA_RIGHT' - - return {'FINISHED'} - - -# Ignore the restrictor for selected objects - -class IgnoreRestrictors(Operator): - bl_idname = "ignore.restrictors" - bl_label = "Ignore Restrictor by Selected Objects" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Ignore or do not ignore Restrictor by selected objects" - ignore: BoolProperty() - - def execute(self, context): - if self.ignore is True: - for ob in bpy.context.selected_objects: - ob['ignore_restrictors'] = 1 - else: - for ob in bpy.context.selected_objects: - if ob.get('ignore_restrictors') is not None: - del ob["ignore_restrictors"] - bpy.ops.refresh.restrictors() - - return{'FINISHED'} - - -# Enable or Disable restrictors - -# Restrictor Mesh - -class RestrictorMesh(Operator): - bl_idname = "restrictor.mesh" - bl_label = "restrictor meshes" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Meshes selection restrictor" - mesh: StringProperty() - - def execute(self, context): - global mesh - global meshrestrictorenabled - if bpy.context.scene.get('meshrestrictor') is not None: - meshrestrictorenabled = True - if bpy.context.scene.get('meshrestrictor') is not None: - del bpy.context.scene['meshrestrictor'] - mesh = 'OBJECT_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'MESH': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - - else: - meshrestrictorenabled = False - bpy.context.scene['meshrestrictor'] = 1 - mesh = 'MESH_CUBE' - for ob in bpy.context.scene.objects: - if ob.type == 'MESH': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor for Curves - -class RestrictorCurve(Operator): - bl_idname = "restrictor.curve" - bl_label = "restrictor curves" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Curves selection restrictor" - - def execute(self, context): - global curve - global curverestrictorenabled - - if bpy.context.scene.get('curverestrictor') is not None: - curverestrictorenabled = True - if bpy.context.scene.get('curverestrictor') is not None: - del bpy.context.scene['curverestrictor'] - curve = 'OUTLINER_OB_CURVE' - for ob in bpy.context.scene.objects: - if ob.type == 'CURVE': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - - else: - curverestrictorenabled = False - bpy.context.scene['curverestrictor'] = 1 - curve = 'CURVE_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'CURVE': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor for Armatures - -class RestrictorArm(Operator): - bl_idname = "restrictor.arm" - bl_label = "restrictor armatures" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Armatures selection restrictor" - - def execute(self, context): - global arm - global armrestrictorenabled - - if bpy.context.scene.get('armrestrictor') is not None: - armrestrictorenabled = True - if bpy.context.scene.get('armrestrictor') is not None: - del bpy.context.scene['armrestrictor'] - arm = 'OUTLINER_OB_ARMATURE' - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - - else: - armrestrictorenabled = False - bpy.context.scene['armrestrictor'] = 1 - arm = 'ARMATURE_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor for Empties - -class RestrictorEmpty(Operator): - bl_idname = "restrictor.empty" - bl_label = "Restrictor Empties" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Empties selection restrictor" - - def execute(self, context): - global empty - global emptyrestrictorenabled - - if bpy.context.scene.get('emptyrestrictor') is not None: - emptyrestrictorenabled = True - if bpy.context.scene.get('emptyrestrictor') is not None: - del bpy.context.scene['emptyrestrictor'] - empty = 'OUTLINER_OB_EMPTY' - for ob in bpy.context.scene.objects: - if ob.type == 'EMPTY': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - - else: - emptyrestrictorenabled = False - bpy.context.scene['emptyrestrictor'] = 1 - empty = 'EMPTY_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'EMPTY': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor for Cameras - -class RestrictorCam(Operator): - bl_idname = "restrictor.cam" - bl_label = "restrictor cameras" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Cameras selection restrictor" - - def execute(self, context): - global cam - global camrestrictorenabled - - if bpy.context.scene.get('camrestrictor') is not None: - camrestrictorenabled = True - if bpy.context.scene.get('camrestrictor') is not None: - del bpy.context.scene['camrestrictor'] - cam = 'OUTLINER_OB_CAMERA' - for ob in bpy.context.scene.objects: - if ob.type == 'CAMERA': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - - else: - camrestrictorenabled = False - bpy.context.scene['camrestrictor'] = 1 - cam = 'CAMERA_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'CAMERA': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor for Lamps - -class RestrictorLamp(Operator): - bl_idname = "restrictor.light" - bl_label = "Restrictor Lamps" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Lamps selection restrictor" - - def execute(self, context): - global lamp - global lamprestrictorenabled - - if bpy.context.scene.get('lamprestrictor') is not None: - lamprestrictorenabled = True - if bpy.context.scene.get('lamprestrictor') is not None: - del bpy.context.scene['lamprestrictor'] - lamp = 'OUTLINER_OB_LIGHT' - for ob in bpy.context.scene.objects: - if ob.type == 'LIGHT': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - - else: - lamprestrictorenabled = False - bpy.context.scene['lamprestrictor'] = 1 - lamp = 'LIGHT_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'LIGHT': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor for Lattice - -class RestrictorLat(Operator): - bl_idname = "restrictor.lat" - bl_label = "Restrictor Lattices" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Lattices selection restrictor" - - def execute(self, context): - global lat - global latrestrictorenabled - - if bpy.context.scene.get('latrestrictor') is not None: - latrestrictorenabled = True - if bpy.context.scene.get('latrestrictor') is not None: - del bpy.context.scene['latrestrictor'] - lat = 'OUTLINER_OB_LATTICE' - for ob in bpy.context.scene.objects: - if ob.type == 'LATTICE': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - else: - latrestrictorenabled = False - bpy.context.scene['latrestrictor'] = 1 - lat = 'LATTICE_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'LATTICE': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor Font - -class RestrictorFont(Operator): - bl_idname = "restrictor.font" - bl_label = "Restrictor Font" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Text selection restrictor" - - def execute(self, context): - global font - global fontrestrictorenabled - - if bpy.context.scene.get('fontrestrictor') is not None: - fontrestrictorenabled = True - if bpy.context.scene.get('fontrestrictor') is not None: - del bpy.context.scene['fontrestrictor'] - font = 'OUTLINER_OB_FONT' - for ob in bpy.context.scene.objects: - if ob.type == 'FONT': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - else: - fontrestrictorenabled = False - bpy.context.scene['fontrestrictor'] = 1 - font = 'FONT_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'FONT': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor for Metaballs - -class RestrictorMeta(Operator): - bl_idname = "restrictor.meta" - bl_label = "restrictor metaballs" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Metaballs selection restrictor" - - def execute(self, context): - global meta - global metarestrictorenabled - - if bpy.context.scene.get('metarestrictor') is not None: - metarestrictorenabled = True - if bpy.context.scene.get('metarestrictor') is not None: - del bpy.context.scene['metarestrictor'] - meta = 'OUTLINER_OB_META' - for ob in bpy.context.scene.objects: - if ob.type == 'META': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - else: - metarestrictorenabled = False - bpy.context.scene['metarestrictor'] = 1 - meta = 'META_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'META': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor for Surfaces - -class RestrictorSurf(Operator): - bl_idname = "restrictor.surf" - bl_label = "Restrictor Surfaces" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Surfaces selection restrictor" - - def execute(self, context): - global surf - global surfrestrictorenabled - - if bpy.context.scene.get('surfrestrictor') is not None: - surfrestrictorenabled = True - if bpy.context.scene.get('surfrestrictor') is not None: - del bpy.context.scene['surfrestrictor'] - surf = 'OUTLINER_OB_SURFACE' - for ob in bpy.context.scene.objects: - if ob.type == 'SURFACE': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - else: - surfrestrictorenabled = False - bpy.context.scene['surfrestrictor'] = 1 - surf = 'SURFACE_DATA' - for ob in bpy.context.scene.objects: - if ob.type == 'SURFACE': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# Restrictor for Speakers - -class RestrictorSound(Operator): - bl_idname = "restrictor.speak" - bl_label = "Restrictor Speakers" - bl_description = "Sounds selection restrictor" - bl_option = {'REGISTER', 'UNDO'} - - def execute(self, context): - global speak - global speakrestrictorenabled - - if bpy.context.scene.get('speakrestrictor') is not None: - speakrestrictorenabled = True - if bpy.context.scene.get('speakrestrictor') is not None: - del bpy.context.scene['speakrestrictor'] - speak = 'OUTLINER_OB_SPEAKER' - for ob in bpy.context.scene.objects: - if ob.type == 'SPEAKER': - if ob.get('ignore_restrictors') is None: - ob.hide_select = False - - else: - speakrestrictorenabled = False - bpy.context.scene['speakrestrictor'] = 1 - speak = 'SPEAKER' - for ob in bpy.context.scene.objects: - if ob.type == 'SPEAKER': - if ob.get('ignore_restrictors') is None: - ob.hide_select = True - ob.select_set(False) - - return{'FINISHED'} - - -# refresh restrictors for newly created objects - -class RefreshRestrictors(Operator): - bl_idname = "refresh.restrictors" - bl_label = "Refresh Selection Restrictors" - bl_option = {'REGISTER', 'UNDO'} - bl_description = "Refresh restrictors" - - def execute(self, context): - global mesh - global curve - global arm - global empty - global cam - global lamp - global lat - global font - global meta - global surf - global speak - - datas = { - 'meshrestrictor': ("OBJECT_DATA", "MESH_CUBE", "MESH"), - 'curverestrictor': ("OUTLINER_OB_CURVE", "CURVE_DATA", "CURVE"), - 'armrestrictor': ("OUTLINER_OB_ARMATURE", "ARMATURE_DATA", "ARMATURE"), - 'emptyrestrictor': ("OUTLINER_OB_EMPTY", "EMPTY_DATA", "EMPTY"), - 'camrestrictor': ("OUTLINER_OB_CAMERA", "CAMERA_DATA", "CAMERA"), - 'lamprestrictor': ("OUTLINER_OB_LIGHT", "LIGHT_DATA", "LIGHT"), - 'latrestrictor': ("OUTLINER_OB_LATTICE", "LATTICE", "LATTICE"), - 'fontrestrictor': ("OUTLINER_OB_FONT", "FONT", "FONT"), - 'metarestrictor': ("OUTLINER_OB_META", "META_DATA", "META"), - 'surfrestrictor': ("SURFACE", "SURFACE_DATA", "SURFACE"), - 'speakrestrictor': ("OUTLINER_OB_SPEAKER", "SPEAKER", "SPEAKER"), - } - - for prop, values in datas.items(): - icon_i, icon_a, types = values - get_props = bpy.context.scene.get(prop) - - gl_icon = icon_a if get_props else icon_i - - for ob in bpy.context.scene.objects: - if ob.type == types: - if ob.get('ignore_restrictors') is None: - ob.hide_select = False if get_props is None else True - if get_props is None: - ob.select_set(False) - - mesh = gl_icon if types == "MESH" else mesh - curve = gl_icon if types == "CURVE" else curve - arm = gl_icon if types == "ARMATURE" else arm - empty = gl_icon if types == "EMPTY" else empty - cam = gl_icon if types == "CAMERA" else cam - lamp = gl_icon if types == "LIGHT" else lamp - lat = gl_icon if types == "LATTICE" else lat - font = gl_icon if types == "FONT" else font - meta = gl_icon if types == "META" else meta - surf = gl_icon if types == "SURFACE" else surf - speak = gl_icon if types == "SPEAKER" else speak - - return{'FINISHED'} - - -class RS_MT_RestrictorSelection(Menu): - """Restrict Selection""" - bl_label = "Selection" - bl_idname = "RestrictorSelection" - - def draw(self, context): - global mesh - global curve - global arm - global empty - global cam - global lamp - global lat - global font - global meta - global surf - global speak - global show_buttons - global show - - layout = self.layout - - layout.operator("restrictor.mesh", icon=mesh, text="Mesh") - layout.operator("restrictor.curve", icon=curve, text="Curve") - layout.operator("restrictor.arm", icon=arm, text="Armature") - layout.operator("restrictor.empty", icon=empty, text="Empty") - layout.operator("restrictor.cam", icon=cam, text="Camera") - layout.operator("restrictor.light", icon=lamp, text="Lamp") - layout.operator("restrictor.lat", icon=lat, text="Lattice") - layout.operator("restrictor.font", icon=font, text="Font") - layout.operator("restrictor.meta", icon=meta, text="MetaBall") - layout.operator("restrictor.surf", icon=surf, text="Surface") - layout.operator("restrictor.speak", icon=speak, text="Speaker") - layout.separator() - layout.operator("ignore.restrictors", icon='GHOST_ENABLED', text="Enable").ignore = True - layout.operator("ignore.restrictors", icon='GHOST_DISABLED', text="Disable").ignore = False - layout.operator("refresh.restrictors", icon='FILE_REFRESH', text="Refresh") - - -def view3d_select_menu(self, context): - self.layout.menu(RestrictorSelection.bl_idname) - - -def register(): - bpy.types.VIEW3D_HT_header.append(view3d_select_menu) - bpy.utils.register_class(RefreshRestrictors) - -def unregister(): - bpy.types.VIEW3D_HT_header.remove(view3d_select_menu) - - bpy.utils.unregister_class(RefreshRestrictors) - - -if __name__ == "__main__": - register() - -# update icons when opening file and updating scene data -# I don't know what does "updating scene data" mean -# But I've added it here to refresh icons while switching scenes -bpy.app.handlers.load_post.append(check_restrictors) -bpy.app.handlers.depsgraph_update_post.append(check_restrictors) diff --git a/space_view3d_display_tools/shading_menu.py b/space_view3d_display_tools/shading_menu.py deleted file mode 100644 index 894feff5..00000000 --- a/space_view3d_display_tools/shading_menu.py +++ /dev/null @@ -1,65 +0,0 @@ -# space_view_3d_display_tools.py Copyright (C) 2014, Jordi Vall-llovera -# Multiple display tools for fast navigate/interact with the viewport - -# ##### BEGIN GPL LICENSE BLOCK ##### -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENCE BLOCK ##### - -bl_info = { - "name": "shade Tools", - "author": "Jordi Vall-llovera Medina, Jhon Wallace", - "version": (1, 6, 0), - "blender": (2, 70, 0), - "location": "Toolshelf", - "description": "Display tools for fast navigate/interact with the viewport", - "warning": "", - "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/" - "Py/Scripts/3D_interaction/Display_Tools", - "category": "3D View"} - - -import bpy -from bpy.types import Menu - - -class VIEW3D_MT_Shade_menu(Menu): - bl_label = "Shade" - bl_description = "Global Shading settings" - - def draw(self, context): - layout = self.layout - - layout.prop(context.space_data, "viewport_shade", expand=True) - - if context.space_data.use_matcap: - row = layout.column(1) - row.scale_y = 0.3 - row.scale_x = 0.5 - row.template_icon_view(context.space_data, "matcap_icon") - - -# Register -def register(): - bpy.utils.register_module(__name__) - - -def unregister(): - bpy.utils.unregister_module(__name__) - - -if __name__ == "__main__": - register() diff --git a/space_view3d_display_tools/useless_tools.py b/space_view3d_display_tools/useless_tools.py deleted file mode 100644 index eb4c3f16..00000000 --- a/space_view3d_display_tools/useless_tools.py +++ /dev/null @@ -1,282 +0,0 @@ -# ##### BEGIN GPL LICENSE BLOCK ##### -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENSE BLOCK ##### - -bl_info = { - "name": "Useless Tools", - "description": "Just a little collection of scripts and tools I use daily", - "author": "Greg Zaal", - "version": (1, 2, 2), - "blender": (2, 75, 0), - "location": "3D View > Tools", - "warning": "", - "wiki_url": "", - "category": "Tools"} - - -import bpy -from bpy.types import Operator -from bpy.props import BoolProperty - - -def error_handlers(self, op_name, errors, reports="ERROR"): - if self and reports: - self.report({'INFO'}, - reports + ": some operations could not be performed " - "(See Console for more info)") - - str_errors = "\n".join(errors) - print("\n[Display Tools]\nOperator: {}\nErrors: {}\n".format(op_name, str_errors)) - - -class UTSetSelectable(Operator): - bl_idname = "ut.set_selectable" - bl_label = "Set Selectable" - bl_description = "Sets selectability for the selected objects" - - selectable: BoolProperty() - - def execute(self, context): - errors = [] - for obj in bpy.context.selected_objects: - try: - if self.selectable is True: - obj.hide_select = False - else: - obj.hide_select = True - except Exception as k: - name = getattr(obj, "name", "Nameless") - errors.append("Error on {} - {}".format(name, k)) - if errors: - error_handlers(self, "ut.set_selectable", errors, "Set Selectable") - - return {'FINISHED'} - - -class UTSetRenderable(Operator): - bl_idname = "ut.set_renderable" - bl_label = "Set Renderable" - bl_description = "Sets renderability for the selected objects" - - renderable: BoolProperty() - - def execute(self, context): - errors = [] - for obj in bpy.context.selected_objects: - try: - if self.renderable is True: - obj.hide_render = False - else: - obj.hide_render = True - except Exception as k: - name = getattr(obj, "name", "Nameless") - errors.append("Error on {} - {}".format(name, k)) - if errors: - error_handlers(self, "ut.set_renderable", errors, "Set Renderable") - - return {'FINISHED'} - - -class UTAllSelectable(Operator): - bl_idname = "ut.all_selectable" - bl_label = "All Selectable" - bl_description = "Allows all objects to be selected" - - def execute(self, context): - errors = [] - for obj in bpy.data.objects: - try: - obj.hide_select = False - except Exception as k: - name = getattr(obj, "name", "Nameless") - errors.append("Error on {} - {}".format(name, k)) - if errors: - error_handlers(self, "ut.all_selectable", errors, "All Selectable") - - return {'FINISHED'} - - -class UTAllRenderable(Operator): - bl_idname = "ut.all_renderable" - bl_label = "All Renderable" - bl_description = "Allow all objects to be rendered" - - def execute(self, context): - errors = [] - for obj in bpy.data.objects: - try: - obj.hide_render = False - except Exception as k: - name = getattr(obj, "name", "Nameless") - errors.append("Error on {} - {}".format(name, k)) - if errors: - error_handlers(self, "ut.all_renderable", errors, "All Renderable") - - return {'FINISHED'} - - -class UTSelNGon(Operator): - bl_idname = "ut.select_ngons" - bl_label = "Select NGons" - bl_description = "Select faces with more than 4 vertices" - - @classmethod - def poll(cls, context): - if not context.active_object or context.mode != 'EDIT_MESH': - return False - return True - - def execute(self, context): - errors = [] - try: - context.tool_settings.mesh_select_mode = (False, False, True) - bpy.ops.mesh.select_face_by_sides(number=4, type='GREATER', extend=True) - except Exception as k: - errors.append("Error - {}".format(k)) - if errors: - error_handlers(self, "ut.select_ngons", errors, "Select NGons") - - return {'FINISHED'} - - -class UTWireShowHideSelAll(Operator): - bl_idname = "ut.wire_show_hide" - bl_label = "Show / Hide Wire Selected or All" - bl_description = "Change the status of the Wire display on Selected Objects" - - show: BoolProperty( - default=False - ) - selected: BoolProperty( - default=False - ) - - @classmethod - def poll(cls, context): - return not context.scene.display_tools.WT_handler_enable - - def execute(self, context): - errors = [] - objects = bpy.context.selected_objects if self.selected else bpy.data.objects - for e in objects: - try: - e.show_wire = self.show - except Exception as k: - name = getattr(e, "name", "Nameless") - errors.append("Error on {} - {}".format(name, k)) - if errors: - error_handlers(self, "ut.wire_show_hide", errors, - "Show / Hide Wire Selected or All") - - return {'FINISHED'} - - -class UTSubsurfHideSelAll(Operator): - bl_idname = "ut.subsurf_show_hide" - bl_label = "Subsurf Show/Hide" - bl_description = ("Sets the Subsurf modifier on objects:\n" - "Hide and Show operate on Selected Objects only\n" - "Hide All and Show All operate on All Objects in the data") - - show: BoolProperty( - default=False - ) - selected: BoolProperty( - default=False - ) - - def execute(self, context): - errors = [] - objects = bpy.context.selected_objects if self.selected else bpy.data.objects - for e in objects: - try: - if e.type not in {"LIGHT", "CAMERA", "EMPTY"}: - e.modifiers['Subsurf'].show_viewport = self.show - except Exception as k: - name = getattr(e, "name", "Nameless") - errors.append( - "No subsurf on {} or it is not named Subsurf\nError: {}".format(name, k)) - if errors: - error_handlers(self, "ut.subsurf_show_hide", errors, "Subsurf Show/Hide") - - return {'FINISHED'} - - -class UTOptimalDisplaySelAll(Operator): - bl_idname = "ut.optimaldisplay" - bl_label = "Optimal Display" - bl_description = "Disables Optimal Display for all Subsurf modifiers on objects" - - on: BoolProperty( - default=False - ) - selected: BoolProperty( - default=False - ) - - def execute(self, context): - errors = [] - objects = bpy.context.selected_objects if self.selected else bpy.data.objects - for e in objects: - try: - if e.type not in {"LIGHT", "CAMERA", "EMPTY"}: - e.modifiers['Subsurf'].show_only_control_edges = self.on - except Exception as k: - name = getattr(e, "name", "Nameless") - errors.append( - "No subsurf on {} or it is not named Subsurf\nError: {}".format(name, k)) - if errors: - error_handlers(self, "ut.optimaldisplay", errors, "Optimal Display") - - return {'FINISHED'} - - -class UTAllEdges(Operator): - bl_idname = "ut.all_edges" - bl_label = "All Edges" - bl_description = "Change the status of All Edges overlay on all objects" - - on: BoolProperty( - default=False - ) - - def execute(self, context): - errors = [] - for e in bpy.data.objects: - try: - e.show_all_edges = self.on - except Exception as k: - name = getattr(e, "name", "Nameless") - errors.append( - "Enabling All Edges on {} \nError: {}".format(name, k)) - if errors: - error_handlers(self, "ut.all_edges", errors, "All Edges") - - return {'FINISHED'} - - -# Register -def register(): - bpy.utils.register_module(__name__) - - -def unregister(): - bpy.utils.unregister_module(__name__) - - -if __name__ == "__main__": - register() |