Problem happening with bpy.ops.import_scene.fbx(filepath=

bl_info = {
“name”: “Custum addon”,
“author”: “Yuan”,
“version”: (1,0),
“blender”: (4,0,1),
“location”: “View3D”,
“description”: “import things”,
“warning”: “”,
“doc_url”: “”,
“category”: “Import”,
}

import bpy
import os

def importFbx(meshesPath, context):

if not meshesPath:
    self.report({'ERROR'}, "No directory selected.")
    return {'CANCELLED'}
    
for fileName in os.listdir(meshesPath):  # Iterate through files in the directory
     if fileName.lower().endswith('.fbx'):
        full_path = os.path.join(meshesPath, fileName)
        bpy.ops.import_scene.fbx(filepath=full_path)
    
return {'FINISHED'}

class IMPORT_OT_import_fbx(bpy.types.Operator):
bl_idname = “import_scene.fbx”
bl_label = “Importer des objets”

def execute(self, context):
    meshesPath = bpy.context.scene.fbx_directory  # Get the directory path
    return importFbx(meshesPath, context)

class VIEW3D_PT_my_Panel(bpy.types.Panel):
bl_idname = “VIEW3D_PT_my_panel”
bl_label = “Import Objects”
bl_space_type = “VIEW_3D”
bl_region_type = “UI”
bl_category = “Import-Export”

def draw(self, context):
    layout = self.layout
    
    row = layout.row()
    row.prop(context.scene, "fbx_directory", text="FBX Directory")
    row.operator("import_scene.fbx", text="Import", icon='IMPORT')
    
    row = layout.row()
    row.operator("wm.redraw_all", text="Refresh", icon='FILE_REFRESH')

def register():
bpy.utils.register_class(IMPORT_OT_import_fbx)
bpy.utils.register_class(VIEW3D_PT_my_Panel)
bpy.types.Scene.fbx_directory = bpy.props.StringProperty(subtype=“DIR_PATH”) Property to store the directory

def unregister():
bpy.utils.unregister_class(IMPORT_OT_import_fbx)
bpy.utils.unregister_class(VIEW3D_PT_my_Panel)
del bpy.types.Scene.fbx_directory

if name == “main”:
register()

Here is the script for an add-on to import fbx… and blender says :

Python: Traceback (most recent call last):
File “\addon_import.py”, line 37, in execute

File “\addon_import.py”, line 25, in importFbx
if fileName.lower().endswith(‘.fbx’):
File “D:\blender_4.0\4.0\scripts\modules\bpy\ops.py”, line 109, in call
ret = _op_call(self.idname_py(), kw)
TypeError: Converting py args to operator properties: : keyword “filepath” unrecognized

witch is weird because it’s the first argument for bpy.ops.import_scene.fbx, can someone help me ?

Hey,
I did not go through every line of your code as it is really hard to read (use the “Preformated text” option next time please). But maybe you can check the answers here:

Looks very similar to what happens on your side. I guess you have to rename your operator?

class IMPORT_OT_import_fbx(bpy.types.Operator):
bl_idname = “import_scene.fbx”
bl_info = { 
    "name": "Custum addon",
    "author": "Yuan",
    "version": (1,0),
    "blender": (4,0,1),
    "location": "View3D",
    "description": "import things",
    "warning": "",
    "doc_url": "",
    "category": "Import",
}

import bpy
import os

def importFbx(meshesPath, context):
        
    if not meshesPath:
        self.report({'ERROR'}, "No directory selected.")
        return {'CANCELLED'}
        
    for fileName in os.listdir(meshesPath):  # Iterate through files in the directory
         if fileName.lower().endswith('.fbx'):
            full_path = os.path.join(meshesPath, fileName)
            bpy.ops.import_scene.fbx(filepath=full_path)
        
    return {'FINISHED'}


class IMPORT_OT_import_fbx(bpy.types.Operator):
    bl_idname = "Import_mesh.my_fbx_importer"
    bl_label = "Importer des objets"
    
    
    def execute(self, context):
        meshesPath = bpy.context.scene.fbx_directory  # Get the directory path
        return importFbx(meshesPath, context)


class VIEW3D_PT_my_Panel(bpy.types.Panel):
    bl_idname = "VIEW3D_PT_my_panel"
    bl_label = "Import Objects"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Import-Export"
    
    def draw(self, context):
        layout = self.layout
        
        row = layout.row()
        row.prop(context.scene, "fbx_directory", text="FBX Directory")
        row.operator("Import_mesh.my_fbx_importer", text="Import", icon='IMPORT')
        
#        row = layout.row()
#        row.operator("wm.redraw_all", text="Refresh", icon='FILE_REFRESH')

def register():
    bpy.utils.register_class(IMPORT_OT_import_fbx)
    bpy.utils.register_class(VIEW3D_PT_my_Panel)
#    bpy.types.Scene.fbx_directory = bpy.props.StringProperty(subtype="DIR_PATH")  # Property to store the directory

def unregister():
    bpy.utils.unregister_class(IMPORT_OT_import_fbx)
    bpy.utils.unregister_class(VIEW3D_PT_my_Panel)
#    del bpy.types.Scene.fbx_directory

if __name__ == "__main__":
    register()

I changed the bl_idname but still it doesn’t work, is there any nameing rules ?

Python: Traceback (most recent call last):
  File "\addon_import.py", line 68, in <module>
  File "\addon_import.py", line 58, in register
    bpy.types.Scene.fbx_directory = bpy.props.StringProperty(subtype="DIR_PATH")  # Property to store the directory
RuntimeError: Error: Registering operator class: 'IMPORT_OT_import_fbx', invalid bl_idname 'Import_mesh.my_fbx_importer', at position 0

seems like Import_mesh.my_fbx_importe is not okay

Okey never mind it worked, I had to open a new Blender, thank you !

Good to hear that it works for you. Still I was curious and tested your code on my side. Of course I got exactly the same error. But I checked a bit more and just changing the bl_idname into a lower case version makes the code run without any problems.

bl_idname = "import_mesh.my_fbx_importer"

I never fully understood the bl_idname rules and the only “documentation” I found is here:
https://developer.blender.org/docs/release_notes/2.80/python_api/addons/#naming

But after some bad experiences I try to stick to the lower case version as above. At least then I was save of the problems you ran into. If anyone has a better documentation for the topic it would be nice to share things.

EDIT:
Just found a bit more detailed discussion on the topic: