Paste Code
Paste Blends
Paste Images
# ##### 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()
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  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.
  7. #
  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.
  12. #
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18.  
  19. # <pep8-80 compliant>
  20. bl_info = {
  21.     "name": "Edge_Tools",
  22.     "author": "Josh Wedlake",
  23.     "version": (0.7),
  24.     "blender": (2, 5, 6),
  25.     "api": 34675,
  26.     "location": "ToolShelf Search",
  27.     "description": "tools for bevelling, sharps and creases",
  28.     "warning": "",
  29.     "wiki_url": "http://tube.freefac.org",
  30.     "tracker_url": "",
  31.     "category": "Mesh"}
  32.  
  33.  
  34. #import re
  35. #import fnmatch
  36. #from bpy.props import *
  37. import bpy
  38. from bpy.ops import *
  39.  
  40.  
  41. class SetBevelWeights(bpy.types.Operator):
  42.     '''set bevel weights'''
  43.     bl_idname = "mesh.bevel_weight"
  44.     bl_label = "Set Bevel Weight"
  45.     bl_options = {'REGISTER', 'UNDO'}
  46.     new_weight = bpy.props.FloatProperty(name="Bevel Weight", description="bevel weight",min=0,max=1)
  47.     dialog_width = 250
  48.  
  49.     def invoke(self, context, event):
  50.         wm = context.window_manager
  51.         wm.invoke_props_dialog(self, self.dialog_width)
  52.         return {'RUNNING_MODAL'}
  53.  
  54.     def execute(self, context):
  55.         import bpy
  56.         bpy.context.tool_settings.mesh_select_mode=[False,True,False]
  57.         counte=0
  58.         if context.mode=='EDIT_MESH':
  59.             bpy.ops.object.editmode_toggle()
  60.         for iedge in bpy.context.active_object.data.edges:
  61.             if iedge.select==True:
  62.                 iedge.bevel_weight=self.properties.new_weight
  63.                 counte+=1
  64.         bpy.ops.object.editmode_toggle()
  65.         #self.report({'OPERATOR'}, 'Reweighted '+str(counte))
  66.  
  67.         return {'FINISHED'}
  68.  
  69.     def draw(self, context):
  70.         layout = self.layout
  71.         props = self.properties
  72.  
  73.         layout.prop(props, "new_weight")
  74.  
  75.  
  76. class PermanentBevel(bpy.types.Operator):
  77.     '''set bevel weights, add a modifier and apply'''
  78.     bl_idname = "mesh.bevel"
  79.     bl_label = "Bevel"
  80.     bl_options = {'REGISTER', 'UNDO'}
  81.     new_weight = bpy.props.FloatProperty(name="Bevel Weight", description="bevel weight",min=0,max=1)
  82.     bevel_width = bpy.props.FloatProperty(name="Bevel Width", description="bevel width",default=0.1,min=0,max=10)
  83.     limit_method=bpy.props.EnumProperty(items=[('LIMIT','Limit Method','Limit Method'),('AVERAGE','Average','Average'),('SHARPEST','Sharpest','Sharpest'),('LARGEST','Largest','Largest')],default='AVERAGE')
  84.     dialog_width = 250
  85.  
  86.     def edge_to_identifier(self,obdat,edgeid):
  87.         return str(obdat.vertices[obdat.edges[edgeid].vertices[0]].co)+str(obdat.vertices[obdat.edges[edgeid].vertices[1]].co)
  88.  
  89.     def identifier_to_edge(self,obdat,identifier):
  90.         for index,iedge in enumerate(obdat.edges):
  91.             if self.edge_to_identifier(obdat,index)==identifier:
  92.                 return index
  93.         return -1
  94.  
  95.     def invoke(self, context, event):
  96.         wm = context.window_manager
  97.         wm.invoke_props_dialog(self, self.dialog_width)
  98.         return {'RUNNING_MODAL'}
  99.  
  100.     def execute(self, context):
  101.         import bpy
  102.         bpy.context.tool_settings.mesh_select_mode=[False,True,False]
  103.         counte=0
  104.         if context.mode=='EDIT_MESH':
  105.             bpy.ops.object.editmode_toggle()
  106.         #dirty hack to store existing bevel weights in list
  107.         #create edge identifiers from vertex locations
  108.         #add new weights
  109.         old_bevel_weights=[]
  110.         for index,iedge in enumerate(bpy.context.active_object.data.edges):
  111.             if iedge.select!=True:
  112.                 old_bevel_weights.append([self.edge_to_identifier(bpy.context.active_object.data,index),iedge.bevel_weight])
  113.                 iedge.bevel_weight=0
  114.             else:
  115.                 old_bevel_weights.append([self.edge_to_identifier(bpy.context.active_object.data,index),0])
  116.                 iedge.bevel_weight=self.properties.new_weight
  117.                 counte+=1
  118.         print (old_bevel_weights)
  119.         bevel_modifier=bpy.context.active_object.modifiers.new(type='BEVEL', name='bevel_script_target')
  120.         bevel_modifier.limit_method='WEIGHT'
  121.         bevel_modifier.width=self.properties.bevel_width
  122.         bevel_modifier.edge_weight_method=self.properties.limit_method
  123.         bpy.ops.object.modifier_apply(modifier='bevel_script_target')
  124.         for iedge in bpy.context.active_object.data.edges:
  125.             iedge.bevel_weight=0
  126.         for identifier in old_bevel_weights:
  127.             edge_index=self.identifier_to_edge(bpy.context.active_object.data,identifier[0])
  128.             if edge_index!=-1:
  129.                 bpy.context.active_object.data.edges[edge_index].bevel_weight=identifier[1]
  130.         bpy.ops.object.editmode_toggle()
  131.  
  132.         #self.report({'OPERATOR'}, 'Applied to '+str(counte)+' edges')
  133.  
  134.         return {'FINISHED'}
  135.  
  136.     def draw(self, context):
  137.         layout = self.layout
  138.         props = self.properties
  139.  
  140.         layout.prop(props, "new_weight")
  141.         layout.prop(props, "bevel_width")
  142.         layout.prop(props, "limit_method")
  143.  
  144. class SmoothVertexGroupWeights(bpy.types.Operator):
  145.     '''smooths vertex group weights'''
  146.     bl_idname = "mesh.smooth_vertex_group_weights"
  147.     bl_label = "Smooth Vertex Group Weights"
  148.     bl_options = {'REGISTER', 'UNDO'}
  149.  
  150.     smooth_iterations = bpy.props.IntProperty(name="Smooth Iterations", description="Smooth Iterations",default=1,min=1,max=10)
  151.     smooth_amount = bpy.props.FloatProperty(name="Smooth Amount", description="Smooth Amount",default=0.1,min=0,max=1)
  152.  
  153.     def execute(self, context):
  154.         import bpy
  155.         bpy.context.tool_settings.mesh_select_mode=[True,False,False]
  156.         if bpy.context.mode=='EDIT_MESH':
  157.             bpy.ops.object.editmode_toggle()
  158.  
  159.         for this_iteration in range(0,self.properties.smooth_iterations):
  160.             print(this_iteration)
  161.  
  162.             vertex_group_weights=dict()
  163.             vertex_group_indices=dict()
  164.             selected_vertices=[]
  165.             for each_vertex in bpy.context.active_object.data.vertices:
  166.                 if each_vertex.select==True:
  167.                     selected_vertices.append(each_vertex.index)
  168.                 for group_index,each_group in enumerate(each_vertex.groups):
  169.                     if each_group.group==bpy.context.active_object.vertex_groups.active_index:
  170.                         vertex_group_indices[each_vertex.index]=group_index
  171.                         vertex_group_weights[each_vertex.index]=each_group.weight
  172.  
  173.             for each_vertex_index in selected_vertices:
  174.                 if each_vertex_index in vertex_group_weights:
  175.                     neighbour_verts=set()
  176.                     for each_edge in bpy.context.active_object.data.edges:
  177.                         if each_vertex_index in each_edge.vertices:
  178.                             neighbour_verts.update(each_edge.vertices)
  179.                     if len(neighbour_verts)>0:
  180.                         sum_weight=0
  181.                         for each_neighbour_vert in list(neighbour_verts):
  182.                             if each_neighbour_vert in vertex_group_weights:
  183.                                 sum_weight+=vertex_group_weights[each_neighbour_vert]
  184.                         new_weight=sum_weight/len(neighbour_verts)
  185.                         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))
  186.  
  187.         bpy.ops.object.editmode_toggle()
  188.         #self.report({'OPERATOR'}, 'Reweighted '+str(counte)+' to '+str(avbevel))
  189.         return {'FINISHED'}
  190.  
  191.     def draw(self, context):
  192.         layout = self.layout
  193.         props = self.properties
  194.  
  195.         layout.prop(props, "smooth_iterations")
  196.         layout.prop(props, "smooth_amount")
  197.  
  198. class AverageBevelWeights(bpy.types.Operator):
  199.     '''averages out the selected edges bevels'''
  200.     bl_idname = "mesh.average_bevel_weights"
  201.     bl_label = "Average Bevel Weights"
  202.     bl_options = {'REGISTER', 'UNDO'}
  203.  
  204.     def invoke(self, context, event):
  205.         import bpy
  206.         bpy.context.tool_settings.mesh_select_mode=[False,True,False]
  207.         counte=0
  208.         sumbevel=0
  209.         if bpy.context.mode=='EDIT_MESH':
  210.             bpy.ops.object.editmode_toggle()
  211.         for iedge in bpy.context.active_object.data.edges:
  212.             if iedge.select==True:
  213.                 sumbevel+=iedge.bevel_weight
  214.                 counte+=1
  215.         avbevel=sumbevel/counte
  216.         for iedge in bpy.context.active_object.data.edges:
  217.             if iedge.select==True:
  218.                 iedge.bevel_weight=avbevel
  219.         bpy.ops.object.editmode_toggle()
  220.         #self.report({'OPERATOR'}, 'Reweighted '+str(counte)+' to '+str(avbevel))
  221.         return {'FINISHED'}
  222.  
  223. class AverageCreases(bpy.types.Operator):
  224.     '''averages out the selected edges creases'''
  225.     bl_idname = "mesh.average_creases"
  226.     bl_label = "Average Edge Creases"
  227.     bl_options = {'REGISTER', 'UNDO'}
  228.  
  229.     def invoke(self, context, event):
  230.         import bpy
  231.         bpy.context.tool_settings.mesh_select_mode=[False,True,False]
  232.         counte=0
  233.         sumcrease=0
  234.         if bpy.context.mode=='EDIT_MESH':
  235.             bpy.ops.object.editmode_toggle()
  236.         for iedge in bpy.context.active_object.data.edges:
  237.             if iedge.select==True:
  238.                 sumcrease+=iedge.crease
  239.                 counte+=1
  240.         avcrease=sumcrease/counte
  241.         for iedge in bpy.context.active_object.data.edges:
  242.             if iedge.select==True:
  243.                 iedge.crease=avcrease
  244.         bpy.ops.object.editmode_toggle()
  245.         #self.report({'OPERATOR'}, 'Recreased '+str(counte)+' to '+str(avbevel))
  246.         return {'FINISHED'}
  247.  
  248. class SelectSameBevelWeights(bpy.types.Operator):
  249.     '''select same bevel weights as selected edge'''
  250.     bl_idname = "mesh.select_same_bevel_weights"
  251.     bl_label = "Select Same Bevel Weights"
  252.     bl_options = {'REGISTER', 'UNDO'}
  253.  
  254.     def invoke(self, context, event):
  255.         import bpy
  256.         bpy.context.tool_settings.mesh_select_mode=[False,True,False]
  257.         if bpy.context.active_object.data.total_edge_sel!=1:
  258.             #self.report({'OPERATOR'}, 'Needs only one edge to be selected!')
  259.             return {'FINISHED'}
  260.  
  261.         if bpy.context.mode=='EDIT_MESH':
  262.             bpy.ops.object.editmode_toggle()
  263.  
  264.         for iedge in bpy.context.active_object.data.edges:
  265.             if iedge.select==True:
  266.                 selectweight=iedge.bevel_weight
  267.                 break
  268.  
  269.         counte=0
  270.         for iedge in bpy.context.active_object.data.edges:
  271.             if iedge.bevel_weight==selectweight:
  272.                 iedge.select=True
  273.                 counte+=1
  274.         bpy.ops.object.editmode_toggle()
  275.         #self.report({'OPERATOR'}, 'Selected '+str(counte))
  276.         return {'FINISHED'}
  277.  
  278. class SelectSameCreases(bpy.types.Operator):
  279.     '''select same creases as selected edge'''
  280.     bl_idname = "mesh.select_same_creases"
  281.     bl_label = "Select Same Creases"
  282.     bl_options = {'REGISTER', 'UNDO'}
  283.  
  284.     def invoke(self, context, event):
  285.         import bpy
  286.         bpy.context.tool_settings.mesh_select_mode=[False,True,False]
  287.         if bpy.context.active_object.data.total_edge_sel!=1:
  288.             #self.report({'OPERATOR'}, 'Needs only one edge to be selected!')
  289.             return {'FINISHED'}
  290.  
  291.         if bpy.context.mode=='EDIT_MESH':
  292.             bpy.ops.object.editmode_toggle()
  293.  
  294.         for iedge in bpy.context.active_object.data.edges:
  295.             if iedge.select==True:
  296.                 selectcrease=iedge.crease
  297.                 break
  298.  
  299.         counte=0
  300.         for iedge in bpy.context.active_object.data.edges:
  301.             if iedge.crease==selectcrease:
  302.                 iedge.select=True
  303.                 counte+=1
  304.         bpy.ops.object.editmode_toggle()
  305.         #self.report({'OPERATOR'}, 'Selected '+str(counte))
  306.         return {'FINISHED'}
  307.  
  308. class SelectAllBevelledEdges(bpy.types.Operator):
  309.     '''select all edges with bevel weight > 0'''
  310.     bl_idname = "mesh.select_all_bevelled_edges"
  311.     bl_label = "Select All Bevelled Edges"
  312.     bl_options = {'REGISTER', 'UNDO'}
  313.  
  314.     def invoke(self, context, event):
  315.         import bpy
  316.         bpy.context.tool_settings.mesh_select_mode=[False,True,False]
  317.         if bpy.context.mode=='EDIT_MESH':
  318.             bpy.ops.object.editmode_toggle()
  319.  
  320.         counte=0
  321.         for iedge in bpy.context.active_object.data.edges:
  322.             if iedge.bevel_weight>0:
  323.                 iedge.select=True
  324.                 counte+=1
  325.             else:
  326.                 iedge.select=False
  327.         bpy.ops.object.editmode_toggle()
  328.         #self.report({'OPERATOR'}, 'Selected '+str(counte))
  329.         return {'FINISHED'}
  330.  
  331. class SelectAllCreasedEdges(bpy.types.Operator):
  332.     '''select all edges with crease > 0'''
  333.     bl_idname = "mesh.select_all_creased_edges"
  334.     bl_label = "Select All Creased Edges"
  335.     bl_options = {'REGISTER', 'UNDO'}
  336.  
  337.     def invoke(self, context, event):
  338.         import bpy
  339.         bpy.context.tool_settings.mesh_select_mode=[False,True,False]
  340.         if bpy.context.mode=='EDIT_MESH':
  341.             bpy.ops.object.editmode_toggle()
  342.  
  343.         counte=0
  344.         for iedge in bpy.context.active_object.data.edges:
  345.             if iedge.crease>0:
  346.                 iedge.select=True
  347.                 counte+=1
  348.             else:
  349.                 iedge.select=False
  350.         bpy.ops.object.editmode_toggle()
  351.         #self.report({'OPERATOR'}, 'Selected '+str(counte))
  352.         return {'FINISHED'}
  353.  
  354. class SelectAllMarkedSharpEdges(bpy.types.Operator):
  355.     '''select all edges with sharp==True'''
  356.     bl_idname = "mesh.select_all_marked_sharp_edges"
  357.     bl_label = "Select All Marked Sharp Edges"
  358.     bl_options = {'REGISTER', 'UNDO'}
  359.  
  360.     def invoke(self, context, event):
  361.         import bpy
  362.         bpy.context.tool_settings.mesh_select_mode=[False,True,False]
  363.         if bpy.context.mode=='EDIT_MESH':
  364.             bpy.ops.object.editmode_toggle()
  365.  
  366.         counte=0
  367.         for iedge in bpy.context.active_object.data.edges:
  368.             if iedge.use_edge_sharp==True:
  369.                 iedge.select=True
  370.                 counte+=1
  371.             else:
  372.                 iedge.select=False
  373.         bpy.ops.object.editmode_toggle()
  374.         #self.report({'OPERATOR'}, 'Selected '+str(counte))
  375.         return {'FINISHED'}
  376.  
  377. vertex_classes = [SmoothVertexGroupWeights]
  378.  
  379. edge_classes = [SetBevelWeights,
  380.     AverageBevelWeights,
  381.     AverageCreases]
  382.  
  383. select_classes = [SelectSameBevelWeights,
  384.     SelectSameCreases,
  385.     SelectAllBevelledEdges,
  386.     SelectAllCreasedEdges,
  387.     SelectAllMarkedSharpEdges]
  388.  
  389. specials_classes = [PermanentBevel]
  390.  
  391. classes=list(set(edge_classes)|set(select_classes)|set(specials_classes))
  392.  
  393. def gen(c):
  394.     def menu_func(self, context):
  395.         self.layout.operator(c.bl_idname, c.bl_label)
  396.     return(menu_func)
  397.  
  398. def register():
  399.  
  400.     for c in vertex_classes:
  401.         bpy.utils.register_class(c)
  402.         bpy.types.VIEW3D_MT_edit_mesh_vertices.append(gen(c))
  403.     for c in edge_classes:
  404.         bpy.utils.register_class(c)
  405.         bpy.types.VIEW3D_MT_edit_mesh_edges.append(gen(c))
  406.     for c in select_classes:
  407.         bpy.utils.register_class(c)
  408.         bpy.types.VIEW3D_MT_select_edit_mesh.append(gen(c))
  409.     for c in specials_classes:
  410.         bpy.utils.register_class(c)
  411.         bpy.types.VIEW3D_MT_edit_mesh_specials.append(gen(c))
  412.  
  413. def unregister():
  414.  
  415.     for c in vertex_classes:
  416.         bpy.utils.unregister_class(c)
  417.         bpy.types.VIEW3D_MT_edit_mesh_vertices.remove(gen(c))
  418.     for c in edge_classes:
  419.         bpy.utils.unregister_class(c)
  420.         bpy.types.VIEW3D_MT_edit_mesh_edges.remove(gen(c))
  421.     for c in select_classes:
  422.         bpy.utils.unregister_class(c)
  423.         bpy.types.VIEW3D_MT_select_edit_mesh.remove(gen(c))
  424.     for c in specials_classes:
  425.         bpy.utils.unregister_class(c)      
  426.         bpy.types.VIEW3D_MT_edit_mesh_specials.remove(gen(c))
  427.  
  428. if __name__ == "__main__":
  429.     register()
go to heaven