0
$\begingroup$

I have a Blender add-on working well to perform an export. I try to upgrade it to Blender 2.80. I fixed some problems (https://github.com/petitg1987/UrchinEngine/commit/a07e6390caa4b231a8c463fc6bb5661cd4f0e6a7#diff-54ba6c537268c77d122862a62df64238) but now I'm stuck on this error:

rna_uiItemO: operator missing srna 'export.urchin'
/home/greg/.config/blender/2.80/scripts/addons/io_export_urchin.py:741
Traceback (most recent call last):
  File "/usr/share/blender/scripts/modules/bpy_types.py", line 758, in draw_ls
    func(self, context)
  File "/home/greg/.config/blender/2.80/scripts/addons/io_export_urchin.py", line 741, in menuFunc
    self.layout.operator(ExportUrchin.bl_idname, text="Urchin Engine (.urchinMesh .urchinAnim)", icon='BLENDER').filepath = default_path
AttributeError: 'NoneType' object has no attribute 'filepath'

Here is the source code:

class ExportUrchin(bpy.types.Operator):
  """Export Urchin Engine (.urchinMesh .urchinAnim)"""
  bl_idname = "export.urchin"
  bl_label = 'Export Urchin Engine'

  exportModes = [("mesh & anim", "Mesh & Anim", "Export mesh and anim"),
                 ("anim only", "Anim only", "Export anim only"),
                 ("mesh only", "Mesh only", "Export mesh only")]

  filepath: bpy.props.StringProperty(subtype='FILE_PATH', name="File Path", description="File path for exporting", maxlen=1024, default="")
  exportMode: bpy.props.EnumProperty(name="Exports", items=exportModes, description="Choose export mode", default='mesh only')
  meshScale: bpy.props.FloatProperty(name="Scale", description="Scale all objects from world origin (0,0,0)", min=0.001, max=1000.0, default=1.0, precision=6)

  def execute(self, context):
    global scale
    scale = self.meshScale
    settings = urchinSettings(savePath=self.properties.filepath, exportMode=self.properties.exportMode)
    saveUrchin(settings)
    return {'FINISHED'}

  def invoke(self, context, event):
    context.window_manager.fileselect_add(self)
    return {"RUNNING_MODAL"}

def menuFunc(self, context):
  default_path = os.path.splitext(bpy.data.filepath)[0]
  self.layout.operator(ExportUrchin.bl_idname, text="Urchin Engine (.urchinMesh .urchinAnim)", icon='BLENDER').filepath = default_path #Line 741

Full source code: https://github.com/petitg1987/UrchinEngine/blob/master/3dEngine/io_export_urchin.py

Could you please help me to understand the error ?

$\endgroup$
0
$\begingroup$

The registration of the operator was broken. The bpy.utils.register_classes_factory() generates a register() and unregister() function for all supplied classes, but doesn't call them. There was also a , missing in the class tuple.

classes = (
    ExportUrchin,
)


def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.types.TOPBAR_MT_file_export.append(menuFunc)


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)
    bpy.types.TOPBAR_MT_file_export.remove(menuFunc)
$\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.