0
$\begingroup$

I'm getting this error and I can't find a solution. Could someone help me?

Python: Traceback (most recent call last): File "\Text", line 13, in File "C:\Users\migue\Desktop\blender-3.4.1-windows-x64\blender-3.4.1-windows-x64\3.4\scripts\modules\bpy\ops.py", line 113, in call ret = _op_call(self.idname_py(), None, kw) TypeError: Converting py args to operator properties: : keyword "filepath" unrecognized

def execute(self, context):
    if context.scene.custom_properties.stl_directory:
        # Load the STL file
        bpy.ops.import_mesh.stl(filepath=context.scene.custom_properties.stl_directory)

Thanks,

Miguel

this is the full code

import bpy

bl_info = {
    "name": "STL Importer",
    "description": "Import an STL file and apply a Geometry Nodes modifier.",
    "author": "BRON",
    "version": (1, 0, 0),
    "blender": (3, 0, 0),
    "location": "View3D > Tools",
    "category": "Import-Export"
}

class CustomPanel(bpy.types.Panel):
    bl_label = "STL Importer"
    bl_idname = "OBJECT_PT_custom_panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = 'Tools'

    def draw(self, context):
        layout = self.layout

        box = layout.box()
        box.prop(context.scene.custom_properties, "stl_directory")
        row = box.row()
        row.prop(context.scene.custom_properties, "yaw_type", expand=True)
        row = box.row()
        row.prop(context.scene.custom_properties, "num_pieces", expand=True)
        row = box.row()
        row.operator("import_mesh.stl", text="Import")

class CustomProperties(bpy.types.PropertyGroup):
    stl_directory: bpy.props.StringProperty(name="STL Directory", subtype='FILE_PATH')
    yaw_type: bpy.props.EnumProperty(
        name="Yaw Type",
        items=[("MAXILLARY", "Maxillary", ""), ("MANDIBULAR", "Mandibular", "")],
        default="MAXILLARY"
    )
    num_pieces: bpy.props.EnumProperty(
        name="Number of Pieces",
        items=[("14", "14 Pieces", ""), ("16", "16 Pieces", "")],
        default="14"
    )

class ImportSTL(bpy.types.Operator):
    bl_idname = "import_mesh.stl"
    bl_label = "Import STL"

    def execute(self, context):
        if context.scene.custom_properties.stl_directory:
            # Load the STL file
            bpy.ops.import_mesh.stl(filepath=context.scene.custom_properties.stl_directory)

            # Apply the modifier based on the user selection
            if context.scene.custom_properties.yaw_type == "MAXILLARY":
                obj = context.view_layer.objects.active
                obj.modifiers.new(name="Maxillary", type="NODES")
                if context.scene.custom_properties.num_pieces == "14":
                    obj.modifiers["Maxillary"].node_group = bpy.data.node_groups["Maxillary (14 pieces)"]
                elif context.scene.custom_properties.num_pieces == "16":
                    obj.modifiers["Maxillary"].node_group = bpy.data.node_groups["Maxillary (16 pieces)"]

            elif context.scene.custom_properties.yaw_type == "MANDIBULAR":
                obj = context.view_layer.objects.active
                obj.modifiers.new(name="Mandibular", type="NODES")
                if context.scene.custom_properties.num_pieces == "14":
                    obj.modifiers["Mandibular"].node_group = bpy.data.node_groups["Mandibular (14 pieces)"]
                elif context.scene.custom_properties.num_pieces == "16":
                    obj.modifiers["Mandibular"].node_group = bpy.data.node_groups["Mandibular (16 pieces)"]

        else:
            self.report({"WARNING"}, "Please, select an .stl first")

        return {'FINISHED'}

def register():
    bpy.utils.register_class(CustomPanel)
    bpy.utils.register_class(CustomProperties)
    bpy.utils.register_class(ImportSTL)
    bpy.types.Scene.custom_properties = bpy.props.PointerProperty(type=CustomProperties)

def unregister():
    bpy.utils.unregister_class(CustomPanel)
    bpy.utils.unregister_class(CustomProperties)
    bpy.utils.unregister_class(ImportSTL)
    del bpy.types.Scene.custom_properties

if __name__ == "__main__":
    register()

```
$\endgroup$
2
  • 1
    $\begingroup$ I haven't tested, but most likely, you are overwriting the interal import_mesh with your own, which doesn't take any arguments. so change bl_idname = "import_mesh.stl" to "import_mesh.my_stl_importer" $\endgroup$ Feb 22, 2023 at 10:34
  • $\begingroup$ Thank you so much Frederik! It worked. I just also had to change the row.operator("import_mesh.stl", text="Import") to row.operator("import_mesh.my_stl_importer", text="Import") $\endgroup$
    – Miguel
    Feb 22, 2023 at 18:12

0

You must log in to answer this question.

Browse other questions tagged .