Problems Creating Addon

Hi to all, I’m trying to create an addon for my realtime mesh exporter (http://sketchesofcode.wordpress.com/2011/11/15/blender-real-time-exporter-simple-version/).

When I run the script from text-editor it works fine, but when I try to load as addon nothing happens… :frowning: can anyone help me out?

here is the code:

#-------------------- REALTIME MESH EXPORTER -------------------#
#-------------------------(basic version)-----------------------#
#                                                               #
# Realtime Mesh Exporter is a script that allows you to save    #
# the mesh in real time for immediate reading from external     #
# applications. You can set exporting options for different     #
# objects in "Object Data" menu.                                #
#                                                               #
#                      Alessandro Zomparelli                    #
#                             (2011)                            #
#                                                               #
# http://sketchesofcode.wordpress.com/                          #
#                                                               #
# Creative Commons                                              #
# CC BY-SA 3.0                                                  #
# http://creativecommons.org/licenses/by-sa/3.0/                #


bl_addon_info = {
    "name": "Real-time Mesh Exporter",
    "description": "Allow real-time exportation of individual mesh",
    "author": "Alessandro Zomparelli",
    "version": (1, 0),
    "blender": (2, 6, 2),
    "location": "Object Data > Real-time Mesh Exporter",
    "warning": "", # used for warning icon and text in addons panel
    "wiki_url": "",
    "tracker_url": "",
    "category": "Mesh"}

import bpy


bpy.types.Object.apply_modifiers = bpy.props.BoolProperty(name = "Modifiers", description = "Apply Modifiers", default = False)
bpy.types.Object.only_vertices = bpy.props.BoolProperty(name = "Only Vertices", description = "Export only mesh vertices", default = False)
bpy.types.Object.ascii = bpy.props.BoolProperty(name = "ASCII", description = "Export as ASCII stl", default = True)
bpy.types.Object.exp_normals = bpy.props.BoolProperty(name = "Normals", description = "Export Normals", default = True)
bpy.types.Object.exp_uv = bpy.props.BoolProperty(name = "UV", description = "Export UV map", default = True)
bpy.types.Object.exp_colors = bpy.props.BoolProperty(name = "Colors", description = "Export Vertex Colors", default = True)
bpy.types.Object.prop_path = bpy.props.StringProperty(name="", description="Recording Folder", subtype='FILE_PATH')
bpy.types.Object.file_type = bpy.props.EnumProperty(
    items = [('stl', 'stl', 'Standard Tessellation Language'),
            ('ply', 'ply', 'Stanford Triangle Format'),
            ('simple', 'simple', 'create simple .verts and .faces files')],
    name = "File Type")

class OBJECT_PT_realtime_export(bpy.types.Panel):
    bl_idname = "OBJECT_PT_realtime_export"
    bl_label = "Real-time Mesh Exporter"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    
    def draw(self, context):
        layout = self.layout
        obj = context.object
        
        
        layout.label("File Path:")
        layout.prop(obj, 'prop_path', icon='FILE_FOLDER')
        
        row = layout.row()
        row.prop(obj, 'file_type')
        
        
        row = layout.row()
        row.prop(obj, 'apply_modifiers')
        if obj.file_type == 'simple':
            row.prop(obj, 'only_vertices')
        if obj.file_type == 'stl':
            row.prop(obj, 'ascii')
        if obj.file_type == 'ply':
            row.prop(obj, 'exp_normals')
            row = layout.row()
            row.prop(obj, 'exp_uv')
            row.prop(obj, 'exp_colors')
        
        row = layout.row()
        if obj.file_type == 'simple':
            row.prop(obj, 'prop_record')
        if not obj.prop_record or obj.file_type != 'simple':
            row = layout.row()
            row.operator("export.mesh", text="Export Mesh Now!", emboss=True).ob_name = obj.name

#   Buttons
class OBJECT_OT_ExportMesh(bpy.types.Operator):
    bl_idname = "export.mesh"
    bl_label = "Export Mesh Now!"
    bl_description = "Manually export data of active object"
    bl_options = {'REGISTER'}
    
    def execute(self, context):
        ob = context.active_object
        export(ob)
        return{'FINISHED'}
    

def export(ob):
    if ob.file_type == 'simple':
        simple_export(ob)
    elif ob.file_type == 'ply':
        file_name = ob.prop_path + ".ply"
        bpy.ops.export_mesh.ply(filepath=file_name, check_existing=False, filter_glob="*.ply", use_modifiers=ob.apply_modifiers, use_normals=ob.exp_normals, use_uv_coords=ob.exp_uv, use_colors=ob.exp_colors)
        print("exported " + file_name)
    elif ob.file_type == 'stl':
        file_name = ob.prop_path + ".stl"
        bpy.ops.export_mesh.stl(filepath=file_name, check_existing=False, ascii=ob.ascii, apply_modifiers=ob.apply_modifiers)        
        print("exported ")
    return{'FINISHED'}


def simple_export(obj):    
    
    if obj.apply_modifiers: mesh = obj.to_mesh(bpy.context.scene, apply_modifiers=True, settings = 'RENDER')
    else: mesh = obj.data
    
    v_list = []
    for v in mesh.vertices:
        v_list.append(v.co)
    
    lines = []
    obj_text = open(obj.prop_path + '.vertices', 'w')
    
    lines.append(str(len(v_list)) + '
')    
    for i in range(0, len(v_list)):
        #open mesh
        co_1 = str(v_list[i][0])
        co_2 = str(v_list[i][1])
        co_3 = str(v_list[i][2])
        co = co_1 + ' ' + co_2 + ' ' + co_3 + '
'
        lines.append(co)
    
    obj_text.writelines(lines)
    obj_text.close()
    
    if not obj.only_vertices:    
        obj_text = open(obj.prop_path + '.faces', 'w')
        obj_text.write(str(len(mesh.faces)) + '
')    
        for f in mesh.faces:
            for i in range(0,len(f.vertices)):
                a=str(f.vertices[i])
                if i != len(f.vertices) - 1:
                    a += ' '
                obj_text.write(a)
            obj_text.write('
')
        obj_text.close()
        
        
        
        
def prop_record(self, context):
    ob = bpy.context.active_object
    if hasattr(ob, 'prop_record') and ob.file_type == 'simple':
        export(ob)
    
    

#
# Registration
#


def register():
    print("cvaosidcuvsoicv")
    #bpy.utils.register_module(__name__)
#    bpy.types.Object.prop_record = bpy.props.BoolProperty(name = "Active Real-time", description = "Active realtime recording", default = False)

    bpy.utils.register_class(OBJECT_PT_realtime_export)
    bpy.utils.register_class(OBJECT_OT_ExportMesh)
    bpy.types.OBJECT_PT_realtime_export.append(prop_record)
    
    
def unregister():
    #bpy.utils.unregister_module(__name__)

    bpy.utils.unregister_class(OBJECT_PT_realtime_export)
    bpy.utils.unregister_class(OBJECT_OT_ExportMesh)
    bpy.types.OBJECT_PT_realtime_export.remove(prop_record)

if __name__ == '__main__':
    register()

I’m sorry, but I have not added many comments, I hope it is understandable

thank

Try changing

bl_addon_info = {

to

bl_info = {

Yeah! that’s right! Thank you crazycounter!

Now it load the addon but didn’t allow me to check it for activation… :confused: any idea?

I just tried it, worked for me by installing the addon. The addon itself had a bunch of errors though. But I could definitely enable it.

Ops… another stupid error, I forget to rename correctly the file as “Real-time Mesh Exporter.py” :stuck_out_tongue:

Now I can focus on fixes :wink:

Thanks again!