developing new export script

Hy,

I just started developing an exporter for blender because I need some specific file format. I have a basic script I use to load the addon which looks like this:

import bpy  import os  
  
filename = os.path.join(os.path.dirname(bpy.data.filepath), "export.py")  
exec(compile(open(filename).read(), filename, 'exec'))  

The rest of the addon is still very basic (something similiar to this: http://www.blender.org/api/blender_python_api_2_65_5/info_tutorial_addon.html#write-the-addon-simple)

My problem is that everytime I execute my load script, it adds a new entry to the export menu. It never removes the old one. I can’t seem to find any explenation on how I can remove this menu entry.

Any suggestions? Thanks

That’s by design, because the unregister() function which may contain code to remove the entry isn’t called on a re-run.

You could clear the internal draw function list, but that would remove all entries:

bpy.types.INFO_MT_file_export.draw._draw_funcs.clear()

Thus you might want to use the following, but only during development:

register():
    try:
        bpy.types.INFO_MT_file_export.remove(menu_func)
    except:
        pass
    bpy.types.INFO_MT_file_export.append(menu_func)
    ...

Of course, I’m only looking for something during development.
However, the trick didn’t work… It doesn’t remove the previous entry.

Hm okay, seems like the menu_func is re-defined and therefore different from the earlier registered one.
You could try

bpy.types.INFO_MT_file_export.draw._draw_funcs.pop()

which is not fully safe, and it will actually remove another entry on the first run…

Maybe it’s better if you just press F8.

F8 is indeed the best way to go, I see. I was wondering, since everything in blender has a python call, is there no python method to execute the ReloadScripts from code?

bpy.ops.wm.addon_refresh() should do the trick

That doesn’t work because the script is not loaded as an actual addon. As I mentioned in my first post, I use a script that loads it manually. Calling bpy.ops.wm.addon_refersh() doesn’t remove the menu item.

My bad, F8 is not refresh addons, but this operator:

bpy.ops.script.reload()

Perfect, that’s exactly what I needed. Thanks a lot.