# ##### 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 #####
# <pep8-80 compliant> bl_info = { "name": "Edge_Tools", "author": "Josh Wedlake", "version": (0.7), "blender": (2, 5, 6), "api": 34675, "location": "ToolShelf Search", "description": "tools for bevelling, sharps and creases", "warning": "", "wiki_url": "http://tube.freefac.org", "tracker_url": "", "category": "Mesh"}
#import re #import fnmatch #from bpy.props import * import bpy from bpy.ops import *
class SetBevelWeights(bpy.types.Operator): '''set bevel weights''' bl_idname = "mesh.bevel_weight" bl_label = "Set Bevel Weight" bl_options = {'REGISTER', 'UNDO'} new_weight = bpy.props.FloatProperty(name="Bevel Weight", description="bevel weight",min=0,max=1) dialog_width = 250
def invoke(self, context, event): wm = context.window_manager wm.invoke_props_dialog(self, self.dialog_width) return {'RUNNING_MODAL'}
def execute(self, context): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] counte=0 if context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() for iedge in bpy.context.active_object.data.edges: if iedge.select==True: iedge.bevel_weight=self.properties.new_weight counte+=1 bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Reweighted '+str(counte))
return {'FINISHED'}
def draw(self, context): layout = self.layout props = self.properties
layout.prop(props, "new_weight")
class PermanentBevel(bpy.types.Operator): '''set bevel weights, add a modifier and apply''' bl_idname = "mesh.bevel" bl_label = "Bevel" bl_options = {'REGISTER', 'UNDO'} new_weight = bpy.props.FloatProperty(name="Bevel Weight", description="bevel weight",min=0,max=1) bevel_width = bpy.props.FloatProperty(name="Bevel Width", description="bevel width",default=0.1,min=0,max=10) limit_method=bpy.props.EnumProperty(items=[('LIMIT','Limit Method','Limit Method'),('AVERAGE','Average','Average'),('SHARPEST','Sharpest','Sharpest'),('LARGEST','Largest','Largest')],default='AVERAGE') dialog_width = 250
def edge_to_identifier(self,obdat,edgeid): return str(obdat.vertices[obdat.edges[edgeid].vertices[0]].co)+str(obdat.vertices[obdat.edges[edgeid].vertices[1]].co)
def identifier_to_edge(self,obdat,identifier): for index,iedge in enumerate(obdat.edges): if self.edge_to_identifier(obdat,index)==identifier: return index return -1
def invoke(self, context, event): wm = context.window_manager wm.invoke_props_dialog(self, self.dialog_width) return {'RUNNING_MODAL'}
def execute(self, context): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] counte=0 if context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() #dirty hack to store existing bevel weights in list #create edge identifiers from vertex locations #add new weights old_bevel_weights=[] for index,iedge in enumerate(bpy.context.active_object.data.edges): if iedge.select!=True: old_bevel_weights.append([self.edge_to_identifier(bpy.context.active_object.data,index),iedge.bevel_weight]) iedge.bevel_weight=0 else: old_bevel_weights.append([self.edge_to_identifier(bpy.context.active_object.data,index),0]) iedge.bevel_weight=self.properties.new_weight counte+=1 print (old_bevel_weights) bevel_modifier=bpy.context.active_object.modifiers.new(type='BEVEL', name='bevel_script_target') bevel_modifier.limit_method='WEIGHT' bevel_modifier.width=self.properties.bevel_width bevel_modifier.edge_weight_method=self.properties.limit_method bpy.ops.object.modifier_apply(modifier='bevel_script_target') for iedge in bpy.context.active_object.data.edges: iedge.bevel_weight=0 for identifier in old_bevel_weights: edge_index=self.identifier_to_edge(bpy.context.active_object.data,identifier[0]) if edge_index!=-1: bpy.context.active_object.data.edges[edge_index].bevel_weight=identifier[1] bpy.ops.object.editmode_toggle()
#self.report({'OPERATOR'}, 'Applied to '+str(counte)+' edges')
return {'FINISHED'}
def draw(self, context): layout = self.layout props = self.properties
layout.prop(props, "new_weight") layout.prop(props, "bevel_width") layout.prop(props, "limit_method")
class SmoothVertexGroupWeights(bpy.types.Operator): '''smooths vertex group weights''' bl_idname = "mesh.smooth_vertex_group_weights" bl_label = "Smooth Vertex Group Weights" bl_options = {'REGISTER', 'UNDO'}
smooth_iterations = bpy.props.IntProperty(name="Smooth Iterations", description="Smooth Iterations",default=1,min=1,max=10) smooth_amount = bpy.props.FloatProperty(name="Smooth Amount", description="Smooth Amount",default=0.1,min=0,max=1)
def execute(self, context): import bpy bpy.context.tool_settings.mesh_select_mode=[True,False,False] if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle()
for this_iteration in range(0,self.properties.smooth_iterations): print(this_iteration)
vertex_group_weights=dict() vertex_group_indices=dict() selected_vertices=[] for each_vertex in bpy.context.active_object.data.vertices: if each_vertex.select==True: selected_vertices.append(each_vertex.index) for group_index,each_group in enumerate(each_vertex.groups): if each_group.group==bpy.context.active_object.vertex_groups.active_index: vertex_group_indices[each_vertex.index]=group_index vertex_group_weights[each_vertex.index]=each_group.weight
for each_vertex_index in selected_vertices: if each_vertex_index in vertex_group_weights: neighbour_verts=set() for each_edge in bpy.context.active_object.data.edges: if each_vertex_index in each_edge.vertices: neighbour_verts.update(each_edge.vertices) if len(neighbour_verts)>0: sum_weight=0 for each_neighbour_vert in list(neighbour_verts): if each_neighbour_vert in vertex_group_weights: sum_weight+=vertex_group_weights[each_neighbour_vert] new_weight=sum_weight/len(neighbour_verts) bpy.context.active_object.data.vertices[each_vertex_index].groups[vertex_group_indices[each_vertex_index]].weight=(new_weight*self.properties.smooth_amount)+(vertex_group_weights[each_vertex_index]*(1-self.properties.smooth_amount))
bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Reweighted '+str(counte)+' to '+str(avbevel)) return {'FINISHED'}
def draw(self, context): layout = self.layout props = self.properties
layout.prop(props, "smooth_iterations") layout.prop(props, "smooth_amount")
class AverageBevelWeights(bpy.types.Operator): '''averages out the selected edges bevels''' bl_idname = "mesh.average_bevel_weights" bl_label = "Average Bevel Weights" bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] counte=0 sumbevel=0 if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() for iedge in bpy.context.active_object.data.edges: if iedge.select==True: sumbevel+=iedge.bevel_weight counte+=1 avbevel=sumbevel/counte for iedge in bpy.context.active_object.data.edges: if iedge.select==True: iedge.bevel_weight=avbevel bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Reweighted '+str(counte)+' to '+str(avbevel)) return {'FINISHED'}
class AverageCreases(bpy.types.Operator): '''averages out the selected edges creases''' bl_idname = "mesh.average_creases" bl_label = "Average Edge Creases" bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] counte=0 sumcrease=0 if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() for iedge in bpy.context.active_object.data.edges: if iedge.select==True: sumcrease+=iedge.crease counte+=1 avcrease=sumcrease/counte for iedge in bpy.context.active_object.data.edges: if iedge.select==True: iedge.crease=avcrease bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Recreased '+str(counte)+' to '+str(avbevel)) return {'FINISHED'}
class SelectSameBevelWeights(bpy.types.Operator): '''select same bevel weights as selected edge''' bl_idname = "mesh.select_same_bevel_weights" bl_label = "Select Same Bevel Weights" bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.active_object.data.total_edge_sel!=1: #self.report({'OPERATOR'}, 'Needs only one edge to be selected!') return {'FINISHED'}
if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle()
for iedge in bpy.context.active_object.data.edges: if iedge.select==True: selectweight=iedge.bevel_weight break
counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.bevel_weight==selectweight: iedge.select=True counte+=1 bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'}
class SelectSameCreases(bpy.types.Operator): '''select same creases as selected edge''' bl_idname = "mesh.select_same_creases" bl_label = "Select Same Creases" bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.active_object.data.total_edge_sel!=1: #self.report({'OPERATOR'}, 'Needs only one edge to be selected!') return {'FINISHED'}
if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle()
for iedge in bpy.context.active_object.data.edges: if iedge.select==True: selectcrease=iedge.crease break
counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.crease==selectcrease: iedge.select=True counte+=1 bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'}
class SelectAllBevelledEdges(bpy.types.Operator): '''select all edges with bevel weight > 0''' bl_idname = "mesh.select_all_bevelled_edges" bl_label = "Select All Bevelled Edges" bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle()
counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.bevel_weight>0: iedge.select=True counte+=1 else: iedge.select=False bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'}
class SelectAllCreasedEdges(bpy.types.Operator): '''select all edges with crease > 0''' bl_idname = "mesh.select_all_creased_edges" bl_label = "Select All Creased Edges" bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle()
counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.crease>0: iedge.select=True counte+=1 else: iedge.select=False bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'}
class SelectAllMarkedSharpEdges(bpy.types.Operator): '''select all edges with sharp==True''' bl_idname = "mesh.select_all_marked_sharp_edges" bl_label = "Select All Marked Sharp Edges" bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle()
counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.use_edge_sharp==True: iedge.select=True counte+=1 else: iedge.select=False bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'}
vertex_classes = [SmoothVertexGroupWeights]
edge_classes = [SetBevelWeights, AverageBevelWeights, AverageCreases]
select_classes = [SelectSameBevelWeights, SelectSameCreases, SelectAllBevelledEdges, SelectAllCreasedEdges, SelectAllMarkedSharpEdges]
specials_classes = [PermanentBevel]
classes=list(set(edge_classes)|set(select_classes)|set(specials_classes))
def gen(c): def menu_func(self, context): self.layout.operator(c.bl_idname, c.bl_label) return(menu_func)
def register():
for c in vertex_classes: bpy.utils.register_class(c) bpy.types.VIEW3D_MT_edit_mesh_vertices.append(gen(c)) for c in edge_classes: bpy.utils.register_class(c) bpy.types.VIEW3D_MT_edit_mesh_edges.append(gen(c)) for c in select_classes: bpy.utils.register_class(c) bpy.types.VIEW3D_MT_select_edit_mesh.append(gen(c)) for c in specials_classes: bpy.utils.register_class(c) bpy.types.VIEW3D_MT_edit_mesh_specials.append(gen(c))
def unregister():
for c in vertex_classes: bpy.utils.unregister_class(c) bpy.types.VIEW3D_MT_edit_mesh_vertices.remove(gen(c)) for c in edge_classes: bpy.utils.unregister_class(c) bpy.types.VIEW3D_MT_edit_mesh_edges.remove(gen(c)) for c in select_classes: bpy.utils.unregister_class(c) bpy.types.VIEW3D_MT_select_edit_mesh.remove(gen(c)) for c in specials_classes: bpy.utils.unregister_class(c) bpy.types.VIEW3D_MT_edit_mesh_specials.remove(gen(c))
if __name__ == "__main__": register()
# ##### 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 ##### # <pep8-80 compliant> bl_info = { "name": "Edge_Tools", "author": "Josh Wedlake", "version": (0.7), "blender": (2, 5, 6), "api": 34675, "location": "ToolShelf Search", "description": "tools for bevelling, sharps and creases", "warning": "", "wiki_url": "http://tube.freefac.org", "tracker_url": "", "category": "Mesh"} #import re #import fnmatch #from bpy.props import * import bpy from bpy.ops import * class SetBevelWeights(bpy.types.Operator): '''set bevel weights''' bl_idname = "mesh.bevel_weight" bl_label = "Set Bevel Weight" bl_options = {'REGISTER', 'UNDO'} new_weight = bpy.props.FloatProperty(name="Bevel Weight", description="bevel weight",min=0,max=1) dialog_width = 250 def invoke(self, context, event): wm = context.window_manager wm.invoke_props_dialog(self, self.dialog_width) return {'RUNNING_MODAL'} def execute(self, context): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] counte=0 if context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() for iedge in bpy.context.active_object.data.edges: if iedge.select==True: iedge.bevel_weight=self.properties.new_weight counte+=1 bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Reweighted '+str(counte)) return {'FINISHED'} def draw(self, context): layout = self.layout props = self.properties layout.prop(props, "new_weight") class PermanentBevel(bpy.types.Operator): '''set bevel weights, add a modifier and apply''' bl_idname = "mesh.bevel" bl_label = "Bevel" bl_options = {'REGISTER', 'UNDO'} new_weight = bpy.props.FloatProperty(name="Bevel Weight", description="bevel weight",min=0,max=1) bevel_width = bpy.props.FloatProperty(name="Bevel Width", description="bevel width",default=0.1,min=0,max=10) limit_method=bpy.props.EnumProperty(items=[('LIMIT','Limit Method','Limit Method'),('AVERAGE','Average','Average'),('SHARPEST','Sharpest','Sharpest'),('LARGEST','Largest','Largest')],default='AVERAGE') dialog_width = 250 def edge_to_identifier(self,obdat,edgeid): return str(obdat.vertices[obdat.edges[edgeid].vertices[0]].co)+str(obdat.vertices[obdat.edges[edgeid].vertices[1]].co) def identifier_to_edge(self,obdat,identifier): for index,iedge in enumerate(obdat.edges): if self.edge_to_identifier(obdat,index)==identifier: return index return -1 def invoke(self, context, event): wm = context.window_manager wm.invoke_props_dialog(self, self.dialog_width) return {'RUNNING_MODAL'} def execute(self, context): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] counte=0 if context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() #dirty hack to store existing bevel weights in list #create edge identifiers from vertex locations #add new weights old_bevel_weights=[] for index,iedge in enumerate(bpy.context.active_object.data.edges): if iedge.select!=True: old_bevel_weights.append([self.edge_to_identifier(bpy.context.active_object.data,index),iedge.bevel_weight]) iedge.bevel_weight=0 else: old_bevel_weights.append([self.edge_to_identifier(bpy.context.active_object.data,index),0]) iedge.bevel_weight=self.properties.new_weight counte+=1 print (old_bevel_weights) bevel_modifier=bpy.context.active_object.modifiers.new(type='BEVEL', name='bevel_script_target') bevel_modifier.limit_method='WEIGHT' bevel_modifier.width=self.properties.bevel_width bevel_modifier.edge_weight_method=self.properties.limit_method bpy.ops.object.modifier_apply(modifier='bevel_script_target') for iedge in bpy.context.active_object.data.edges: iedge.bevel_weight=0 for identifier in old_bevel_weights: edge_index=self.identifier_to_edge(bpy.context.active_object.data,identifier[0]) if edge_index!=-1: bpy.context.active_object.data.edges[edge_index].bevel_weight=identifier[1] bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Applied to '+str(counte)+' edges') return {'FINISHED'} def draw(self, context): layout = self.layout props = self.properties layout.prop(props, "new_weight") layout.prop(props, "bevel_width") layout.prop(props, "limit_method") class SmoothVertexGroupWeights(bpy.types.Operator): '''smooths vertex group weights''' bl_idname = "mesh.smooth_vertex_group_weights" bl_label = "Smooth Vertex Group Weights" bl_options = {'REGISTER', 'UNDO'} smooth_iterations = bpy.props.IntProperty(name="Smooth Iterations", description="Smooth Iterations",default=1,min=1,max=10) smooth_amount = bpy.props.FloatProperty(name="Smooth Amount", description="Smooth Amount",default=0.1,min=0,max=1) def execute(self, context): import bpy bpy.context.tool_settings.mesh_select_mode=[True,False,False] if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() for this_iteration in range(0,self.properties.smooth_iterations): print(this_iteration) vertex_group_weights=dict() vertex_group_indices=dict() selected_vertices=[] for each_vertex in bpy.context.active_object.data.vertices: if each_vertex.select==True: selected_vertices.append(each_vertex.index) for group_index,each_group in enumerate(each_vertex.groups): if each_group.group==bpy.context.active_object.vertex_groups.active_index: vertex_group_indices[each_vertex.index]=group_index vertex_group_weights[each_vertex.index]=each_group.weight for each_vertex_index in selected_vertices: if each_vertex_index in vertex_group_weights: neighbour_verts=set() for each_edge in bpy.context.active_object.data.edges: if each_vertex_index in each_edge.vertices: neighbour_verts.update(each_edge.vertices) if len(neighbour_verts)>0: sum_weight=0 for each_neighbour_vert in list(neighbour_verts): if each_neighbour_vert in vertex_group_weights: sum_weight+=vertex_group_weights[each_neighbour_vert] new_weight=sum_weight/len(neighbour_verts) bpy.context.active_object.data.vertices[each_vertex_index].groups[vertex_group_indices[each_vertex_index]].weight=(new_weight*self.properties.smooth_amount)+(vertex_group_weights[each_vertex_index]*(1-self.properties.smooth_amount)) bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Reweighted '+str(counte)+' to '+str(avbevel)) return {'FINISHED'} def draw(self, context): layout = self.layout props = self.properties layout.prop(props, "smooth_iterations") layout.prop(props, "smooth_amount") class AverageBevelWeights(bpy.types.Operator): '''averages out the selected edges bevels''' bl_idname = "mesh.average_bevel_weights" bl_label = "Average Bevel Weights" bl_options = {'REGISTER', 'UNDO'} def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] counte=0 sumbevel=0 if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() for iedge in bpy.context.active_object.data.edges: if iedge.select==True: sumbevel+=iedge.bevel_weight counte+=1 avbevel=sumbevel/counte for iedge in bpy.context.active_object.data.edges: if iedge.select==True: iedge.bevel_weight=avbevel bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Reweighted '+str(counte)+' to '+str(avbevel)) return {'FINISHED'} class AverageCreases(bpy.types.Operator): '''averages out the selected edges creases''' bl_idname = "mesh.average_creases" bl_label = "Average Edge Creases" bl_options = {'REGISTER', 'UNDO'} def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] counte=0 sumcrease=0 if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() for iedge in bpy.context.active_object.data.edges: if iedge.select==True: sumcrease+=iedge.crease counte+=1 avcrease=sumcrease/counte for iedge in bpy.context.active_object.data.edges: if iedge.select==True: iedge.crease=avcrease bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Recreased '+str(counte)+' to '+str(avbevel)) return {'FINISHED'} class SelectSameBevelWeights(bpy.types.Operator): '''select same bevel weights as selected edge''' bl_idname = "mesh.select_same_bevel_weights" bl_label = "Select Same Bevel Weights" bl_options = {'REGISTER', 'UNDO'} def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.active_object.data.total_edge_sel!=1: #self.report({'OPERATOR'}, 'Needs only one edge to be selected!') return {'FINISHED'} if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() for iedge in bpy.context.active_object.data.edges: if iedge.select==True: selectweight=iedge.bevel_weight break counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.bevel_weight==selectweight: iedge.select=True counte+=1 bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'} class SelectSameCreases(bpy.types.Operator): '''select same creases as selected edge''' bl_idname = "mesh.select_same_creases" bl_label = "Select Same Creases" bl_options = {'REGISTER', 'UNDO'} def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.active_object.data.total_edge_sel!=1: #self.report({'OPERATOR'}, 'Needs only one edge to be selected!') return {'FINISHED'} if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() for iedge in bpy.context.active_object.data.edges: if iedge.select==True: selectcrease=iedge.crease break counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.crease==selectcrease: iedge.select=True counte+=1 bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'} class SelectAllBevelledEdges(bpy.types.Operator): '''select all edges with bevel weight > 0''' bl_idname = "mesh.select_all_bevelled_edges" bl_label = "Select All Bevelled Edges" bl_options = {'REGISTER', 'UNDO'} def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.bevel_weight>0: iedge.select=True counte+=1 else: iedge.select=False bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'} class SelectAllCreasedEdges(bpy.types.Operator): '''select all edges with crease > 0''' bl_idname = "mesh.select_all_creased_edges" bl_label = "Select All Creased Edges" bl_options = {'REGISTER', 'UNDO'} def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.crease>0: iedge.select=True counte+=1 else: iedge.select=False bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'} class SelectAllMarkedSharpEdges(bpy.types.Operator): '''select all edges with sharp==True''' bl_idname = "mesh.select_all_marked_sharp_edges" bl_label = "Select All Marked Sharp Edges" bl_options = {'REGISTER', 'UNDO'} def invoke(self, context, event): import bpy bpy.context.tool_settings.mesh_select_mode=[False,True,False] if bpy.context.mode=='EDIT_MESH': bpy.ops.object.editmode_toggle() counte=0 for iedge in bpy.context.active_object.data.edges: if iedge.use_edge_sharp==True: iedge.select=True counte+=1 else: iedge.select=False bpy.ops.object.editmode_toggle() #self.report({'OPERATOR'}, 'Selected '+str(counte)) return {'FINISHED'} vertex_classes = [SmoothVertexGroupWeights] edge_classes = [SetBevelWeights, AverageBevelWeights, AverageCreases] select_classes = [SelectSameBevelWeights, SelectSameCreases, SelectAllBevelledEdges, SelectAllCreasedEdges, SelectAllMarkedSharpEdges] specials_classes = [PermanentBevel] classes=list(set(edge_classes)|set(select_classes)|set(specials_classes)) def gen(c): def menu_func(self, context): self.layout.operator(c.bl_idname, c.bl_label) return(menu_func) def register(): for c in vertex_classes: bpy.utils.register_class(c) bpy.types.VIEW3D_MT_edit_mesh_vertices.append(gen(c)) for c in edge_classes: bpy.utils.register_class(c) bpy.types.VIEW3D_MT_edit_mesh_edges.append(gen(c)) for c in select_classes: bpy.utils.register_class(c) bpy.types.VIEW3D_MT_select_edit_mesh.append(gen(c)) for c in specials_classes: bpy.utils.register_class(c) bpy.types.VIEW3D_MT_edit_mesh_specials.append(gen(c)) def unregister(): for c in vertex_classes: bpy.utils.unregister_class(c) bpy.types.VIEW3D_MT_edit_mesh_vertices.remove(gen(c)) for c in edge_classes: bpy.utils.unregister_class(c) bpy.types.VIEW3D_MT_edit_mesh_edges.remove(gen(c)) for c in select_classes: bpy.utils.unregister_class(c) bpy.types.VIEW3D_MT_select_edit_mesh.remove(gen(c)) for c in specials_classes: bpy.utils.unregister_class(c) bpy.types.VIEW3D_MT_edit_mesh_specials.remove(gen(c)) if __name__ == "__main__": register()
|