1 # space_view_3d_display_tools.py Copyright (C) 2014, Jordi Vall-llovera
2 # Multiple display tools for fast navigate/interact with the viewport
4 # ***** BEGIN GPL LICENSE BLOCK *****
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # ***** END GPL LICENCE BLOCK *****
24 Author Site: http://www.jordiart.com
28 from bpy
.types
import Operator
29 from bpy
.props
import (
35 # function taken from space_view3d_modifier_tools.py
36 class DisplayApplyModifiersView(Operator
):
37 bl_idname
= "view3d.toggle_apply_modifiers_view"
38 bl_label
= "Hide Viewport"
39 bl_description
= "Shows/Hide modifiers of the active / selected object(s) in 3d View"
42 def poll(cls
, context
):
43 return context
.active_object
is not None
45 def execute(self
, context
):
48 for mod
in context
.active_object
.modifiers
:
53 # active object - no selection
54 for mod
in context
.active_object
.modifiers
:
55 mod
.show_viewport
= is_apply
57 for obj
in context
.selected_objects
:
58 for mod
in obj
.modifiers
:
59 mod
.show_viewport
= is_apply
62 message_a
= "Displaying modifiers in the 3d View"
64 message_a
= "Hiding modifiers in the 3d View"
66 self
.report(type={"INFO"}, message
=message_a
)
71 # define base dummy class for inheritance
74 def poll(cls
, context
):
79 def set_render_settings(context
):
82 render
.simplify_subdivision
= 0
83 render
.simplify_shadow_samples
= 0
84 render
.simplify_child_particles
= 0
85 render
.simplify_ao_sss
= 0
88 # Display Modifiers Render Switch
89 class DisplayModifiersRenderSwitch(Operator
, BasePollCheck
):
90 bl_idname
= "view3d.display_modifiers_render_switch"
92 bl_description
= "Display/Hide modifiers on render"
94 mod_render
= BoolProperty(default
=True)
96 def execute(self
, context
):
99 scene
= context
.scene
.display_tools
102 selection
= context
.selected_objects
105 for obj
in bpy
.data
.objects
:
106 for mod
in obj
.modifiers
:
107 mod
.show_render
= self
.mod_render
109 for obj
in selection
:
110 for mod
in obj
.modifiers
:
111 mod
.show_render
= self
.mod_render
113 self
.report({'ERROR'}, "Display/Hide all modifiers for render failed")
119 # Display Modifiers Viewport switch
120 class DisplayModifiersViewportSwitch(Operator
, BasePollCheck
):
121 bl_idname
= "view3d.display_modifiers_viewport_switch"
123 bl_description
= "Display/Hide modifiers in the viewport"
125 mod_switch
= BoolProperty(default
=True)
127 def execute(self
, context
):
129 selection
= context
.selected_objects
132 for obj
in bpy
.data
.objects
:
133 for mod
in obj
.modifiers
:
134 mod
.show_viewport
= self
.mod_switch
136 for obj
in selection
:
137 for mod
in obj
.modifiers
:
138 mod
.show_viewport
= self
.mod_switch
140 self
.report({'ERROR'}, "Display/Hide modifiers in the viewport failed")
146 # Display Modifiers Edit Switch
147 class DisplayModifiersEditSwitch(Operator
, BasePollCheck
):
148 bl_idname
= "view3d.display_modifiers_edit_switch"
150 bl_description
= "Display/Hide modifiers during edit mode"
152 mod_edit
= BoolProperty(default
=True)
154 def execute(self
, context
):
156 selection
= context
.selected_objects
159 for obj
in bpy
.data
.objects
:
160 for mod
in obj
.modifiers
:
161 mod
.show_in_editmode
= self
.mod_edit
163 for obj
in selection
:
164 for mod
in obj
.modifiers
:
165 mod
.show_in_editmode
= self
.mod_edit
167 self
.report({'ERROR'}, "Display/Hide all modifiers failed")
173 class DisplayModifiersCageSet(Operator
, BasePollCheck
):
174 bl_idname
= "view3d.display_modifiers_cage_set"
176 bl_description
= "Display modifiers editing cage during edit mode"
178 set_cage
= BoolProperty(default
=True)
180 def execute(self
, context
):
181 selection
= context
.selected_objects
184 for obj
in bpy
.data
.objects
:
185 for mod
in obj
.modifiers
:
186 mod
.show_on_cage
= self
.set_cage
188 for obj
in selection
:
189 for mod
in obj
.modifiers
:
190 mod
.show_on_cage
= self
.set_cage
192 self
.report({'ERROR'}, "Setting Editing Cage all modifiers failed")
198 class ModifiersSubsurfLevel_Set(Operator
, BasePollCheck
):
199 bl_idname
= "view3d.modifiers_subsurf_level_set"
200 bl_label
= "Set Subsurf level"
201 bl_description
= "Change subsurf modifier level"
204 name
="Subsurf Level",
205 description
="Change subsurf modifier level",
213 def execute(self
, context
):
214 selection
= context
.selected_objects
217 for obj
in bpy
.data
.objects
:
218 context
.scene
.objects
.active
= obj
219 bpy
.ops
.object.modifier_add(type='SUBSURF')
221 for mod
in obj
.modifiers
:
222 if mod
.type == 'SUBSURF':
224 mod
.levels
= self
.level
226 bpy
.ops
.object.modifier_remove(modifier
="Subsurf")
228 for obj
in selection
:
229 bpy
.ops
.object.subdivision_set(level
=self
.level
, relative
=False)
230 for mod
in obj
.modifiers
:
231 if mod
.type == 'SUBSURF':
232 mod
.levels
= self
.level
234 self
.report({'ERROR'}, "Setting the Subsurf level could not be applied")
242 bpy
.utils
.register_module(__name__
)
246 bpy
.utils
.unregister_module(__name__
)
249 if __name__
== "__main__":