__init__.py (2038B)
1 # My first python file 2 # bpy.ops.wm.addon_expand(module="io_vertex_weight") 3 4 import bpy 5 6 bl_info = { 7 "name": "Vertex Weight Export", 8 "author": "Harrison Andrews", 9 "description": "An ascii exporter that stores just a meshs's vertex weights to their skeleton", 10 "location": "File > Import-Export", 11 "version": (2, 0), 12 "blender": (2, 81, 6), 13 "warning": "", # used for warning icon and text in addons panel 14 "category": "Import-Export", 15 "support": 'COMMUNITY', 16 } 17 18 from bpy_extras.io_utils import (ExportHelper, 19 ImportHelper, 20 path_reference_mode, 21 axis_conversion, 22 ) 23 24 def writefile(self): 25 26 filename = self.filepath 27 out = open(filename, 'w') 28 sce = bpy.data.scenes[0] 29 mesh = bpy.data.meshes[0] 30 out.write("#Harry's Vertex Weight Export Version 2.0\n\n") 31 32 for vert in mesh.vertices: 33 out.write("w") 34 35 for i in range(0,4): 36 try: 37 out.write(" %i %f" % (vert.groups[i].group,vert.groups[i].weight)) 38 except: 39 out.write(" %i %f" % (0,0)) 40 out.write("\n") 41 42 out.close() 43 44 45 class ExportWeights(bpy.types.Operator, ExportHelper): 46 47 bl_idname = "export_weights.hvw" 48 bl_label = 'Vertex Weight Export' 49 bl_options = {'PRESET'} 50 51 filename_ext = ".hvw" 52 53 def execute(self, context): 54 bpy.ops.object.vertex_group_normalize_all() 55 writefile(self) 56 return {'FINISHED'} 57 58 def menu_func_export(self, context): 59 self.layout.operator(ExportWeights.bl_idname, text="Harry Vertex Weight (.hvw)") 60 61 def register(): 62 bpy.utils.register_class(ExportWeights) 63 bpy.types.TOPBAR_MT_file_export.append(menu_func_export) 64 65 def unregister(): 66 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export) 67 bpy.utils.unregister_class(ExportWeights) 68 69 if __name__ == "__main__": 70 register()