1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # ##### END GPL LICENSE BLOCK #####
22 from bpy.props import *
25 class SelectPattern(bpy.types.Operator):
26 '''Select object matching a naming pattern.'''
27 bl_idname = "object.select_pattern"
28 bl_label = "Select Pattern"
32 pattern = StringProperty(name="Pattern", description="Name filter using '*' and '?' wildcard chars", maxlen=32, default="*")
33 case_sensitive = BoolProperty(name="Case Sensitive", description="Do a case sensitive compare", default=False)
34 extend = BoolProperty(name="Extend", description="Extend the existing selection", default=True)
36 def execute(self, context):
40 if self.properties.case_sensitive:
41 pattern_match = fnmatch.fnmatchcase
43 pattern_match = lambda a, b: fnmatch.fnmatchcase(a.upper(), b.upper())
46 if obj and obj.mode == 'POSE':
47 items = obj.data.bones
48 elif obj and obj.type == 'ARMATURE' and obj.mode == 'EDIT':
49 items = obj.data.edit_bones
51 items = context.visible_objects
53 # Can be pose bones or objects
55 if pattern_match(item.name, self.properties.pattern):
57 elif not self.properties.extend:
62 def invoke(self, context, event):
64 # return wm.invoke_props_popup(self, event)
65 wm.invoke_props_popup(self, event)
66 return ('RUNNING_MODAL',)
68 def draw(self, context):
70 props = self.properties
72 layout.prop(props, "pattern")
74 row.prop(props, "case_sensitive")
75 row.prop(props, "extend")
78 class SubdivisionSet(bpy.types.Operator):
79 '''Sets a Subdivision Surface Level (1-5)'''
81 bl_idname = "object.subdivision_set"
82 bl_label = "Subdivision Set"
86 level = IntProperty(name="Level",
87 default=1, min=0, max=100, soft_min=0, soft_max=6)
89 def poll(self, context):
90 ob = context.active_object
91 return (ob and ob.type == 'MESH')
93 def execute(self, context):
94 level = self.properties.level
96 def set_object_subd(obj):
97 for mod in obj.modifiers:
98 if mod.type == 'MULTIRES':
99 if level < mod.total_levels:
100 if obj.mode == 'SCULPT' and mod.sculpt_levels != level:
101 mod.sculpt_levels = level
102 elif obj.mode == 'OBJECT' and mod.levels != level:
105 elif mod.type == 'SUBSURF':
106 if mod.levels != level:
111 mod = obj.modifiers.new("Subsurf", 'SUBSURF')
114 for obj in context.selected_editable_objects:
120 class Retopo(bpy.types.Operator):
123 bl_idname = "object.retopology"
124 bl_label = "Retopology from Grease Pencil"
128 def execute(self, context):
134 bpy.ops.add(SelectPattern)
135 bpy.ops.add(SubdivisionSet)