0
$\begingroup$

I want to fully automatize some of my blender processes, an i run into a lot of problems not finding the correct commands, not using the correct args...

Can i just "see" in a log somewhere what were the commands blender ran ?

To be very precise, i want to load a gltf file, and export it to stl.

No problem through the gui, but i'm stuck with that bit of code :

import bpy
import sys
import os

file = open(r"C:\Users\theo1\Documents\GitHub\Hackathon2020\map&mapdata\mini.gltf")

bpy.ops.import_scene.gltf(file)
bpy.ops.export_mesh.stl(filePath=r"C:\Users\theo1\Documents\GitHub\Hackathon2020\map&mapdata\mini.stl")

Which gives me this :

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\theo1\Desktop\impExp.py", line 7, in <module>
    bpy.ops.import_scene.gltf(file)
  File "C:\Program Files\Blender Foundation\Blender 2.81\2.81\scripts\modules\bpy\ops.py", line 198, in __call__
    C_dict, C_exec, C_undo = BPyOpsSubModOp._parse_args(args)
  File "C:\Program Files\Blender Foundation\Blender 2.81\2.81\scripts\modules\bpy\ops.py", line 151, in _parse_args
    raise ValueError("1-3 args execution context is supported")
ValueError: 1-3 args execution context is supported

thanks.

$\endgroup$
1
$\begingroup$

The API documentation should be your primary reference when implementing Python scripts for Blender.

Additionally you can enable the Python Tooltips and Developer Extras in the preferences (Edit > Preferences > Interface > Display).

Preferences

The Python Tooltips will be displayed when hovering over a UI element with your mouse and show what Python command would be executed when interacting with it. The Developer Extras add helpful options such as Edit Source or Online Python Reference to the context menu (RMB).

Python Tooltip

Online Python Reference


Using the references provided above it's fairly easy to see why your script doesn't work properly.

bpy.ops.import_scene.gltf() expects a file path as argument, not a file object. Therefore you shouldn't use open() at all. Instead pass the file path as named argument:

bpy.ops.import_scene.gltf(filepath="/path/to/your/file")
| improve this answer | |
$\endgroup$
  • $\begingroup$ This os exactly what I wanted. Thank you very much $\endgroup$ – Orsu Jan 16 at 20:29

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.