Help making an import addon

Hi, good night to everyone. I’m trying to make an import addon for the .wso format, a format from the TSR Workshop for editing meshes from the Sims 3.
I’ve seen a lot of reference and tutorials, but i cannot realize what it is wrong in the code at all. :spin:
I hope someone can help me, thanks a lot!!! :stuck_out_tongue: Here is the code:


bl_info = { 
    'name': 'TSRW Importer (.wso)', 
    'location': 'File > Import > TSRW format (.wso)', 
    'description': 'Importer for the TSR Workshop format', 
    'category': 'Import-Export' 
} 
 
import struct 
 
def read_byte(file_object, endian = '<'): 
    data = struct.unpack(endian + 'B', file_object.read(1))[0] 
    return data 
 
def read_ushort(file_object, endian = '<'): 
    data = struct.unpack(endian + 'H', file_object.read(2))[0] 
    return data 
 
def read_uint(file_object, endian = '<'): 
    data = struct.unpack(endian + 'I', file_object.read(4))[0] 
    return data 
 
def read_int(file_object, endian = '<'): 
    data = struct.unpack(endian + 'i', file_object.read(4))[0] 
    return data 
 
def read_float(file_object, endian = '<'): 
    data = struct.unpack(endian + 'f', file_object.read(4))[0] 
    return data 
 
# Importer definition 
 
import bpy 
 
def import_wso_file(context, filepath): 
    file = open(filepath, 'rb') 
    wso_version = read_int(file) 
    print(wso_version) 
     
# Class definition 
 
from bpy_extras.io_utils import ImportHelper 
from bpy.props import StringProperty 
from bpy.types import Operator 
 
class ImportWSO_Class(Operator, ImportHelper): 
    """TSR Workshop format importer""" 
    bl_idname = "import_wso" 
    bl_label = "Import TSRW Format" 
     
    filename_ext = ".wso" 
    filter_glob = StringProperty(default="*.wso", options={"HIDDEN"}) 
     
    def execute(self, context): 
        import_wso_file(context, self.filepath)  
        return {"FINISHED"} 
 
def menu_func(self, context): 
    self.layout.operator(ImportWSO_Class.bl_idname, text="TSR Workshop (.wso)") 
 
def register(): 
    bpy.utils.register_class(ImportWSO_Class) 
    bpy.types.INFO_MT_file_import.append(menu_func) 
 
def unregister(): 
    bpy.utils.unregister_class(ImportWSO_Class) 
    bpy.types.INFO_MT_file_import.remove(menu_func) 
 
if __name__ == "__main__": 
    register() 
     
bpy.types.import_wso('INVOKE_DEFAULT')

bpy.types.import_wso(‘INVOKE_DEFAULT’)
is not a valid operator call, and your operator’s bl_idname is bad.

It needs to be

bl_idname = “import.wso”

And the call to it

bpy.ops.import.wso(‘INVOKE_DEFAULT’)

Thanks a lot!!! I managed to get it run, now i can start with the import code :stuck_out_tongue:
Thanks again for your help.

Hi, good morning. I have another problem with my addon, and I found appropiate not to start another thread.
I have already functional code, i’ve put it all in a file called init.py.
The problem is that when I import the addon from the addon tab of the preferences window in Blender, it doesn’t appear in the list. The menu commands for importing and exporting doesn’t appear too. It only works when running the script in the text editor.
I’d like to make it an installable addon, i think there may be a problem in the code (I’ve remover all that i think it’s irrelevant, for easier reading):


# Addon info 
bl_info = { 
    "blender": (2, 65, 0), 
    'category': 'Import-Export', 
    'description': 'Importer-exporter for the TSR Workshop format', 
    'location': 'File > Import-Export', 
    'name': 'TSRW Importer-Exporter (.wso)', 
} 
 
# Irrelevant helper functions 
 
# Importer definition 
def import_wso_file(context, filepath): 
    # Irrelevant and functional import code 
    # ... ... 
 
# Exporter definition 
def export_wso_file(context, filepath, only_visible): 
    # Irrelevant and functional export code 
    # ... ... 
 
# Class definitions 
from bpy_extras.io_utils import ImportHelper, ExportHelper 
from bpy.props import StringProperty 
from bpy.types import Operator 
 
class ImportWSO_Class(Operator, ImportHelper): 
    """TSR Workshop format importer""" 
    bl_idname = "import_file.wso" 
    bl_label = "Import TSRW Format" 
     
    filename_ext = ".wso" 
    filter_glob = StringProperty(default="*.wso", options={"HIDDEN"}) 
     
    def execute(self, context): 
        import_wso_file(context, self.filepath)  
        return {"FINISHED"} 
 
class ExportWSO_Class(Operator, ExportHelper): 
    """TSR Workshop format exporter""" 
    bl_idname = "export_file.wso" 
    bl_label = "Export TSRW Format" 
     
    filename_ext = ".wso" 
    filter_glob = StringProperty(default="*.wso", options={"HIDDEN"}) 
     
    only_visible = bpy.props.BoolProperty(name="Only visible objects", 
                                          description="Export only visible objects", 
                                          default=True) 
     
    def execute(self, context): 
        export_wso_file(context, self.filepath, self.only_visible)  
        return {"FINISHED"} 
 
def menu_func_import(self, context): 
    self.layout.operator(ImportWSO_Class.bl_idname, text="TSR Workshop (.wso)") 
 
def menu_func_export(self, context): 
    self.layout.operator(ExportWSO_Class.bl_idname, text="TSR Workshop (.wso)") 
 
def register(): 
    bpy.utils.register_class(ImportWSO_Class) 
    bpy.utils.register_class(ExportWSO_Class) 
    bpy.types.INFO_MT_file_import.append(menu_func_import) 
    bpy.types.INFO_MT_file_export.append(menu_func_export) 
 
def unregister(): 
    bpy.utils.unregister_class(ImportWSO_Class) 
    bpy.utils.unregister_class(ExportWSO_Class) 
    bpy.types.INFO_MT_file_import.remove(menu_func_import) 
    bpy.types.INFO_MT_file_export.remove(menu_func_export) 
 
if __name__ == "__main__": 
    register()

Thanks a lot!!

Are there any errors printed to the system console?

Do you have the support level “Testing” enabled?

No, there are no errors at all. Not in the info panel of Blender, nor in the console window (Dos-like terminal in Windows)
It says (in the info panel) “Modules installed from ‘… …_init_.py’ into ‘C:… …\Blender Foundation… \addons’ ()” highlighted in green.
The addon does not appear in the addons browser of the preferences window, for whatever category or support level I choose. It doesn’t exist at all.

It’s missing the bpy module import (import bpy), but other than that, it works for me. It appears in the Community support level.

It may be a bad idea at call the file init.py if it’s not a module (but a single-file addon). Call it e.g. import_wso.py

¡¡¡Thanks a lot!!!, as soon as I’ve changed the filename it started to work like all other addons!!! It seems i misunderstood the purpose of naming something init.py
:yes:;):eyebrowlift::p:D