2
$\begingroup$

I'm trying to run the LDR-Importer addon directly from a script but I don't know where to start.

I tried using the python command that was underlined in the addon bpy.ops.import_scene.ldraw() as seen in the image below.

python api text

I get the following error message:

[LDR Importer] (21:24:45.57) Standard-res primitives substitution selected
[LDR Importer] (21:24:45.57) Found LDraw installation at */ldraw/
[LDR Importer] (21:24:45.57) Preferences saved to
*/Blender/2.78/scripts/addons/io_scene_ldrimporter/prefs/LDR-Importer.json
[LDR Importer] (21:24:45.57) Attempting to import 
[LDR Importer] (21:24:45.57) ERROR: Reason: Invalid File Type
Must be a .ldr or .dat
Error: Error: Invalid File Type
Must be a .ldr or .dat
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "/Applications/Blender.app/Contents/MacOS/../Resources/2.78/scripts/modules/bpy/ops.py", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Error: Error: Invalid File Type
Must be a .ldr or .dat

I then tried my luck by puting directly the file I'm trying to open as an argument bpy.ops.import_scene.ldraw("model.ldr") and now I get the error message:

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "/Applications/Blender.app/Contents/MacOS/../Resources/2.78/scripts/modules/bpy/ops.py", line 187, in __call__
    ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
TypeError: Calling operator "bpy.ops.import_scene.ldraw" error, expected a string enum in ('INVOKE_DEFAULT', 'INVOKE_REGION_WIN', 'INVOKE_REGION_CHANNELS', 'INVOKE_REGION_PREVIEW', 'INVOKE_AREA', 'INVOKE_SCREEN', 'EXEC_DEFAULT', 'EXEC_REGION_WIN', 'EXEC_REGION_CHANNELS', 'EXEC_REGION_PREVIEW', 'EXEC_AREA', 'EXEC_SCREEN')

Any idea on what I'm doing wrong and what I should be doing instead?

$\endgroup$

1 Answer 1

0
$\begingroup$

Alright after some tinkering around I stumbled upon this page. Basically I had to pass the argument as a keyword:

bpy.ops.import_scene.ldraw(filepath="model.ldr")

And now everything works as expected.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .