1
$\begingroup$

Part 1:

I've got the source code for an add-on for importing a .skn file that won't display in the add-ons menu in the preferences window. I have the folder with the 4 files needed in it in the scripts/addons/ directory but it wont display in the UI. I am able to import it through the python console but it has problems, still doesnt show up in the addons directory

I figured out part 1, was missing the bl_addon_info in the ____init____.py file it was in ____bpy_init____.py"

Part 2:

This has brought a new problem into the light though, I can't activate the addon through the UI, and when trying to activate it through the python console i get a new error:

Traceback (most recent call last):
   File "C:\PROGRA~1\BLENDE~1\Blender\2.54\scripts\ui\space_userpref.py", line 1086, in execute
      mod = __import__(module_name)
   File "C:\PROGRA~1\BLENDE~1\Blender\2.54\scripts\addons\io_scene_skn\__init__.py", line 37, in <module>
      from .__bpy_init__ import *
OverflowError: modification time overflows a 4 byte field

Updating Blender to 2.70 and merging the ____init____.py and the _____bpy_init____.py together mostly solved part 2 and 3 and I am already using this code to register it:

def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_import.append(menu_func_import)
bpy.types.INFO_MT_file_export.append(menu_func_export)

def unregister():
    try:
        bpy.utils.unregister_module(__name__)
    except:
        pass
    try:
        bpy.types.INFO_MT_file_import.remove(menu_func_import)
    except:
        pass
    try:
        bpy.types.INFO_MT_file_export.remove(menu_func_export)
    except:
        pass

if __name__ == '__main__':
    register()

Still doesn't register it correctly but I can run it from the python console, Updating to 2.70 has introduced another problem that I will post a separate question about since it is most likely not connected to this one in any way.

Part 3: (hopefully solving part 2 solves part 3)

When i try to run a function "io_scene_skn.import_char() I get an error:

Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
AttributeError: 'module' object has no attribute 'import_char'

I've tried defining the attributes for import__char both in line, (doesn't work) syntax error, and individually before calling the io_scene_skn.import_char() command.

And here is the code: (import_char is near the bottom of the code)

class IMPORT_OT_skn(bpy.types.Operator, ImportHelper):
bl_label="Import SKN"
bl_idname="import.skn"

SKN_FILE = props.StringProperty(name='Mesh', description='Model .skn file')
SKL_FILE = props.StringProperty(name='Skeleton', description='Model .skl file')
DDS_FILE = props.StringProperty(name='Texture', description='Model .dds file')    
MODEL_DIR = props.StringProperty()
CLEAR_SCENE = props.BoolProperty(name='ClearScene', description='Clear current scene before importing?', default=True)
APPLY_WEIGHTS = props.BoolProperty(name='LoadWeights', description='Load default bone weights from .skn file', default=True)


def draw(self, context):
    layout = self.layout
    fileProps = context.space_data.params
    self.MODEL_DIR = fileProps.directory

    selectedFileExt = path.splitext(fileProps.filename)[-1].lower()
    if selectedFileExt == '.skn':
        self.SKN_FILE = fileProps.filename
    elif selectedFileExt == '.skl':
        self.SKL_FILE = fileProps.filename
    elif selectedFileExt == '.dds':
        self.DDS_FILE = fileProps.filename
    box = layout.box()
    box.prop(self.properties, 'SKN_FILE')
    box.prop(self.properties, 'SKL_FILE')
    box.prop(self.properties, 'DDS_FILE')
    box.prop(self.properties, 'CLEAR_SCENE', text='Clear scene before importing')
    box.prop(self.properties, 'APPLY_WEIGHTS', text='Load mesh weights')

def execute(self, context):

    import_char(MODEL_DIR=self.MODEL_DIR,
                SKN_FILE=self.SKN_FILE,
                SKL_FILE=self.SKL_FILE,
                DDS_FILE=self.DDS_FILE,
                CLEAR_SCENE=self.CLEAR_SCENE,
                APPLY_WEIGHTS=self.APPLY_WEIGHTS)

    return {'FINISHED'}

Can anyone help here?

$\endgroup$
  • 1
    $\begingroup$ The filepath in the first error message shows your using blender 2.54 - that is very old and was considered a beta release. We are about to get 2.71 released this week, so I would start by upgrading to a newer version of blender. The python api has changed a lot since 2.54. You probably want to merge __bpy_init__.py into __init__.py so they are one file. Have a look at the template called addon_add_object.py it has register and unregister functions to enable the addon operators. $\endgroup$ – sambler Jun 25 '14 at 5:35
1
$\begingroup$

Note on comment I agree with @Sambler, you should update to at least a 2.6+ version. I would recommend 2.62 if you are working with mesh data as 2.63 introduced BMesh API changes and you need to make more changes to get that working.

The first issue was that you were missing the bl_info, the following is a sample for an addon I work on.

#: Blender addon info.
bl_info = {
    "name": "NetImmerse/Gamebryo nif format",
    "description": "Import and export files in the NetImmerse/Gamebryo nif format (.nif)",
    "author": "NifTools Team",
    "version": (2, 6, 0), # can't read from VERSION, blender wants it hardcoded
    "blender": (2, 6, 2),
    "api": 39257,
    "location": "File > Import-Export",
    "warning": "not functional, port from 2.49 series still in progress",
    "wiki_url": (
        "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/"\
        "Import-Export/Nif"),
    "tracker_url": (
        "http://sourceforge.net/tracker/?group_id=149157&atid=776343"),
    "support": "COMMUNITY",
    "category": "Import-Export"}

The next issue is that you are not registering your python module as an addon, which can be done either. In in your __init__.py you need to define a register() and unregister() function. The easiest option is the following.

def register():
    bpy.utils.register_module(__name__)

def unregister():
    bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
    register()

If you need more flexibility over registering order you can register each module.

def register():
    _init_loggers()
    properties.register()
    ui.register()
    bpy.utils.register_module(__name__)
    bpy.types.INFO_MT_file_import.append(menu_func_import)
    bpy.types.INFO_MT_file_export.append(menu_func_export)

def unregister():
    # no idea how to do this... oh well, let's not lose any sleep over it
    #_uninit_loggers()
    properties.unregister()
    ui.unregister()
    bpy.utils.unregister_module(__name__)
    bpy.types.INFO_MT_file_import.remove(menu_func_import)
    bpy.types.INFO_MT_file_export.remove(menu_func_export)

if __name__ == "__main__":
    register()

Where properties.register may need to register classes.

def register():
    bpy.utils.register_class(NiftoolsMaterialProps)
    bpy.utils.register_class(NiftoolsObjectProps)
    bpy.utils.register_class(NiftoolsObjectCollisionProps)

For the final syntax error, where is import_char defined? He is not in your __init__.py i.e io_scene_skn Either define the function in your __init__.py, not such a good idea, clutters things up.

def import_char(seif, .., .., ..):
     #code

Import the "submodule" which contains said function, which I suspect is where it is defined anyways.

from io_scene_skn import char_submodule

Then call it via

char_submodule.import_char(args, params, etc)

Obviously you should replace char_submodule with the module/class its defined in.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.