diff options
author | meta-androcto <meta.androcto1@gmail.com> | 2017-03-20 04:32:20 +0300 |
---|---|---|
committer | meta-androcto <meta.androcto1@gmail.com> | 2017-03-20 04:32:20 +0300 |
commit | 5bc826c18500b5f61122e1ea55e3f16248b4d9ef (patch) | |
tree | 66b2db5142e2c52a733b909330f0d44d585574cc /space_view3d_display_tools | |
parent | 8e3bfa5506ea110fe6793401b53da17c61061167 (diff) |
Initial Commit "Display Tools"
Diffstat (limited to 'space_view3d_display_tools')
-rw-r--r-- | space_view3d_display_tools/__init__.py | 630 | ||||
-rw-r--r-- | space_view3d_display_tools/display.py | 251 | ||||
-rw-r--r-- | space_view3d_display_tools/fast_navigate.py | 227 | ||||
-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 | 224 | ||||
-rw-r--r-- | space_view3d_display_tools/selection_restrictor.py | 851 | ||||
-rw-r--r-- | space_view3d_display_tools/shading_menu.py | 68 | ||||
-rw-r--r-- | space_view3d_display_tools/useless_tools.py | 319 |
9 files changed, 2870 insertions, 0 deletions
diff --git a/space_view3d_display_tools/__init__.py b/space_view3d_display_tools/__init__.py new file mode 100644 index 00000000..950f9f09 --- /dev/null +++ b/space_view3d_display_tools/__init__.py @@ -0,0 +1,630 @@ +# 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 + +bl_info = { + "name": "Display Tools", + "author": "Jordi Vall-llovera Medina, Jhon Wallace", + "version": (1, 6, 1), + "blender": (2, 7, 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", + "tracker_url": "", + "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 DisplayToolsPanel(Panel): + bl_label = "Display Tools" + bl_space_type = "VIEW_3D" + bl_region_type = "TOOLS" + bl_category = "Display" + bl_options = {'DEFAULT_CLOSED'} + + draw_type_icons = {'BOUNDS': 'BBOX', + 'WIRE': 'WIRE', + 'SOLID': 'SOLID', + 'TEXTURED': 'POTATO' + } + 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 + gs = scene.game_settings + 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="FACESEL_HLT") + row.prop(obj, "show_name", text="", icon="SORTALPHA") + row.prop(obj, "show_axis", text="", icon="AXIS_TOP") + 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_x_ray", 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", "Simplify", toggle=True) + + if render.use_simplify is True: + col = layout.column(align=True) + col.label("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="MATSPHERE", 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="Maximum:") + col.prop(obj, "draw_type", text="", icon=self.draw_type_icons[obj.draw_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='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("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(gs, "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 or gs.material_mode != 'GLSL': + 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("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("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 SELECT2DROP: + col = layout.column(align=True) + if obj and obj.mode == 'OBJECT': + 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 All", icon="RESTRICT_VIEW_ON") + + col = layout.column(align=True) + col.operator("op.render_show_all_selected", icon="RESTRICT_VIEW_OFF") + col.operator("op.render_hide_all_selected", icon="RESTRICT_VIEW_ON") + + if obj: + if obj.mode == 'OBJECT': + layout.operator_menu_enum("object.select_by_type", "type", text="Select All by Type...") + col = layout.column(align=True) + col.operator("opr.select_all", icon="MOD_MESHDEFORM") + col.operator("opr.inverse_selection", icon="MOD_REMESH") + + if obj_type == 'MESH' and obj.mode == 'EDIT': + col = layout.column(align=True) + col.operator("opr.select_all", icon="MOD_MESHDEFORM") + col.operator("opr.inverse_selection", icon="MOD_REMESH") + + col = layout.column(align=True) + col.operator("mesh.select_linked", icon="ROTATECOLLECTION") + col.operator("opr.loop_multi_select", icon="OUTLINER_DATA_MESH") + else: + col = layout.column(align=True) + col.operator("opr.select_all", icon="MOD_MESHDEFORM") + col.operator("opr.inverse_selection", icon="MOD_REMESH") + + col = layout.column(align=True) + col.operator("view3d.select_border", icon="MESH_PLANE") + col.operator("view3d.select_circle", icon="MESH_CIRCLE") + + # fast nav options + col.separator() + 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 FASTNAVDROP: + col = layout.column(align=True) + col.operator("view3d.fast_navigate_operator") + col.operator("view3d.fast_navigate_stop") + + layout.label("Settings:") + layout.prop(display_tools, "OriginalMode") + layout.prop(display_tools, "FastMode") + layout.prop(display_tools, "EditActive", "Edit mode") + layout.prop(display_tools, "Delay") + layout.prop(display_tools, "DelayTimeGlobal", "Delay time") + layout.prop(display_tools, "ShowParticles") + layout.prop(display_tools, "ParticlesPercentageDisplay") + layout.separator() + + col = layout.column(align=True) + 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="Display", + description="Display only a percentage of particles", + default=25, + min=0, + max=100, + soft_min=0, + soft_max=100, + subtype='FACTOR' + ) + InitialParticles = IntProperty( + name="Count for initial particle setting before entering fast navigate", + description="Display a percentage value of particles", + 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 = [ + DisplayToolsPanel + ] + + +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.user_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="") + + +# register the classes and props +def register(): + bpy.utils.register_module(__name__) + + # Register Scene Properties + bpy.types.Scene.display_tools = PointerProperty( + type=display_tools_scene_props + ) + update_panel(None, bpy.context) + selection_restrictor.register() + + +def unregister(): + del bpy.types.Scene.display_tools + selection_restrictor.unregister() + bpy.utils.unregister_module(__name__) + + +if __name__ == "__main__": + register() diff --git a/space_view3d_display_tools/display.py b/space_view3d_display_tools/display.py new file mode 100644 index 00000000..d0310ee8 --- /dev/null +++ b/space_view3d_display_tools/display.py @@ -0,0 +1,251 @@ +# 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.draw_type = self.drawing + else: + for obj in selection: + obj.draw_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.draw_bounds_type = scene.BoundingMode + else: + for obj in selection: + obj.show_bounds = self.bounds + if self.bounds: + obj.draw_bounds_type = scene.BoundingMode + except: + self.report({'ERROR'}, "Display/Hide Bounding box overlay failed") + return {'CANCELLED'} + + return {'FINISHED'} + + +# Double Sided switch +class DisplayDoubleSidedSwitch(Operator, BasePollCheck): + bl_idname = "view3d.display_double_sided_switch" + bl_label = "On/Off" + bl_description = "Turn on/off face double shaded mode" + + double_side = BoolProperty(default=False) + + def execute(self, context): + try: + selection = bpy.context.selected_objects + + if not selection: + for mesh in bpy.data.meshes: + mesh.show_double_sided = self.double_side + else: + for sel in selection: + if sel.type == 'MESH': + mesh = sel.data + mesh.show_double_sided = self.double_side + except: + self.report({'ERROR'}, "Turn on/off face double shaded mode 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_x_ray = self.xrays + else: + for obj in selection: + obj.show_x_ray = 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 new file mode 100644 index 00000000..5551bd32 --- /dev/null +++ b/space_view3d_display_tools/fast_navigate.py @@ -0,0 +1,227 @@ +# 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 + + +# 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): + scene = bpy.context.scene.display_tools + + if mode is True: + for particles in bpy.data.particles: + if particles.type == 'EMITTER': + particles.draw_method = 'DOT' + particles.draw_percentage = 100 + else: + particles.draw_method = 'RENDER' + particles.draw_percentage = 100 + else: + for particles in bpy.data.particles: + if particles.type == 'EMITTER': + particles.draw_method = 'DOT' + particles.draw_percentage = scene.ParticlesPercentageDisplay + else: + particles.draw_method = 'RENDER' + particles.draw_percentage = scene.ParticlesPercentageDisplay + + +# 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") + + trigger = BoolProperty(default=False) + mode = BoolProperty(default=False) + screen_width = [0, 0] + + def modal(self, context, event): + context.area.tag_redraw() + scene = context.scene.display_tools + + if scene.FastNavigateStop is True: + self.cancel(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'} + + def execute(self, context): + 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) + return {'RUNNING_MODAL'} + + @staticmethod + def calc_delay(scene): + if scene.Delay is True: + if scene.DelayTime < scene.DelayTimeGlobal: + scene.DelayTime += 1 + + 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 context.area.type != 'VIEW_3D': + self.cancel(context) + return {'CANCELLED'} + + if event.type in {'ESC', 'RET', 'SPACE'}: + self.cancel(context) + return {'CANCELLED'} + + if scene.FastNavigateStop is True: + self.cancel(context) + 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 + + if scene.ShowParticles is False: + for particles in bpy.data.particles: + if particles.type == 'EMITTER': + particles.draw_method = 'NONE' + else: + particles.draw_method = 'NONE' + else: + display_particles(self.mode) + + def cancel(self, context): + scene = context.scene.display_tools + for particles in bpy.data.particles: + particles.draw_percentage = scene.InitialParticles + + +# 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 new file mode 100644 index 00000000..af2667dc --- /dev/null +++ b/space_view3d_display_tools/modifier_tools.py @@ -0,0 +1,250 @@ +# 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.scene.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 new file mode 100644 index 00000000..594a894f --- /dev/null +++ b/space_view3d_display_tools/scene_vis.py @@ -0,0 +1,50 @@ +# 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 new file mode 100644 index 00000000..ca429384 --- /dev/null +++ b/space_view3d_display_tools/select_tools.py @@ -0,0 +1,224 @@ +# ***** 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, 1), + "blender": (2, 7, 3), + "location": "3D View > Tools", + "description": "Selection Tools", + "warning": "", + "wiki_url": "", + "tracker_url": "", + "category": "" +} + +import bpy +from bpy.types import Operator + + +class ShowHideObject(Operator): + bl_idname = "opr.show_hide_object" + bl_label = "Show/Hide Object" + bl_description = "Show/Hide all objects in the Data" + 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 = False + + if i.type not in ['CAMERA', 'LAMP']: + 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 Objects" + 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 = False + + if i.type not in ['CAMERA', 'LAMP']: + 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 = False + + if i.type not in ['CAMERA', 'LAMP']: + 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, verticies, 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 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 is True: + ob.hide_render = True + except: + continue + + 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/selection_restrictor.py b/space_view3d_display_tools/selection_restrictor.py new file mode 100644 index 00000000..7f4cde87 --- /dev/null +++ b/space_view3d_display_tools/selection_restrictor.py @@ -0,0 +1,851 @@ +# ##### 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), + "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_LAMP' +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 of 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_LAMP' + else: + lamprestrictorenabled = False + lamp = 'LAMP_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'} + +# hide or unhide 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'} + +# hide or unhide object to restrictor + + +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 for 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 = 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 = 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 = False + + return{'FINISHED'} + +# restrictor for epties + + +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 = 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 = False + + return{'FINISHED'} + + +# restrictor for lamps +class RestrictorLamp(Operator): + bl_idname = "restrictor.lamp" + 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_LAMP' + for ob in bpy.context.scene.objects: + if ob.type == 'LAMP': + if ob.get('ignore_restrictors') is None: + ob.hide_select = False + + else: + lamprestrictorenabled = False + bpy.context.scene['lamprestrictor'] = 1 + lamp = 'LAMP_DATA' + for ob in bpy.context.scene.objects: + if ob.type == 'LAMP': + if ob.get('ignore_restrictors') is None: + ob.hide_select = True + ob.select = 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 = False + + return{'FINISHED'} + +# restrictor for text + + +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 = 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 = 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 = False + + return{'FINISHED'} + + +# restrictor for speaks +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 = 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 + + # refresh meshes + if bpy.context.scene.get('meshrestrictor') is None: + 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: + 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 = False + + # refresh curves + if bpy.context.scene.get('curverestrictor') is None: + 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: + 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 = False + # refresh armatures + if bpy.context.scene.get('armrestrictor') is None: + 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: + 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 = False + # refresh empties + if bpy.context.scene.get('emptyrestrictor') is None: + 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: + 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 = False + + # refresh cameras + if bpy.context.scene.get('camrestrictor') is None: + 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: + 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 = False + + # refresh lamps + if bpy.context.scene.get('lamprestrictor') is None: + lamp = 'OUTLINER_OB_LAMP' + for ob in bpy.context.scene.objects: + if ob.type == 'LAMP': + if ob.get('ignore_restrictors') is None: + ob.hide_select = False + + lamp = 'LAMP_DATA' + for ob in bpy.context.scene.objects: + if ob.type == 'LAMP': + if ob.get('ignore_restrictors') is None: + ob.hide_select = True + ob.select = False + + # refresh lattices + if bpy.context.scene.get('latrestrictor') is None: + 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 + + 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 = False + + # refresh text + if bpy.context.scene.get('fontrestrictor') is None: + 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: + 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 = False + # refresh metaballs + if bpy.context.scene.get('metarestrictor') is None: + 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: + 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 = False + + # refresh surfaces + if bpy.context.scene.get('surfrestrictor') is None: + 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: + 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 = False + + # refresh speakers + if bpy.context.scene.get('speakrestrictor') is None: + 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: + 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 = False + return{'FINISHED'} + + +class 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.lamp", 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.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) + + +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.scene_update_post.append(check_restrictors) diff --git a/space_view3d_display_tools/shading_menu.py b/space_view3d_display_tools/shading_menu.py new file mode 100644 index 00000000..12718a9f --- /dev/null +++ b/space_view3d_display_tools/shading_menu.py @@ -0,0 +1,68 @@ +# 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, 7, 0), + "location": "Toolshelf", + "description": "Display tools for fast navigate/interact with the viewport", + "warning": "", + "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/" + "3D_interaction/Display_Tools", + "tracker_url": "", + "category": "Addon Factory"} + + +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 new file mode 100644 index 00000000..1ff2d99f --- /dev/null +++ b/space_view3d_display_tools/useless_tools.py @@ -0,0 +1,319 @@ +# ##### 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, 1), + "blender": (2, 75, 0), + "location": "3D View > Tools", + "warning": "", + "wiki_url": "", + "tracker_url": "", + "category": "Tools"} + + +import bpy +from bpy.types import Operator +from bpy.props import BoolProperty + + +def print_errors(lists, operators="useless_tools.py"): + if lists: + print("\n[%s]\n\n%s\n" % (operators, "\n".join(lists))) + + +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: + print_errors(errors, "Operator: ut.set_selectable") + self.report({'INFO'}, + "Set Selectable: some operations could not be performed (See console for more info)") + + 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: + print_errors(errors, "Operator: ut.set_renderable") + self.report({'INFO'}, + "Set Renderable: some operations could not be performed (See console for more info)") + + 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: + print_errors(errors, "Operator: ut.all_selectable") + self.report({'INFO'}, + "All Selectable: some operations could not be performed (See console for more info)") + + 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: + print_errors(errors, "Operator: ut.all_renderable") + self.report({'INFO'}, + "All Renderable: some operations could not be performed (See console for more info)") + 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: + print_errors(errors, "Operator: ut.select_ngons") + self.report({'INFO'}, + "Select NGons: some operations could not be performed (See console for more info)") + + 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: + print_errors(errors, "Operator: ut.wire_show_hide") + self.report({'INFO'}, + "Show/Hide Wire: some operations could not be performed (See console for more info)") + + 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 {"LAMP", "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: + print_errors(errors, "Operator: ut.subsurf_show_hide") + self.report({'INFO'}, + "Subsurf Show/Hide: some operations could not be performed (See console for more info)") + + 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 {"LAMP", "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: + print_errors(errors, "Operator: ut.optimaldisplay") + self.report({'INFO'}, + "Optimal Display: some operations could not be performed (See console for more info)") + + 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: + print_errors(errors, "Operator: ut.all_edges") + self.report({'INFO'}, + "Enable All Edges: some operations could not be performed (See console for more info)") + + return {'FINISHED'} + + +class UTDoubleSided(Operator): + bl_idname = "ut.double_sided" + bl_label = "Double Sided Normals" + bl_description = "Disables Double Sided Normals for all objects" + + on = BoolProperty( + default=False + ) + + def execute(self, context): + errors = [] + for e in bpy.data.meshes: + try: + e.show_double_sided = self.on + except Exception as k: + name = getattr(e, "name", "Nameless") + errors.append( + "Applying Double Sided Normals on {} \nError: {}".format(name, k)) + if errors: + print_errors(errors, "Operator: ut.double_sided") + self.report({'INFO'}, + "Double Sided Normals: some operations could not be performed (See console for more info)") + return {'FINISHED'} + + +# Register +def register(): + bpy.utils.register_module(__name__) + + +def unregister(): + bpy.utils.unregister_module(__name__) + + +if __name__ == "__main__": + register() |