Calling operator "bpy.ops.export_scene.gltf" error

I can’t get the GTLF export to work with Python scripting.

repo steps:

Open Blender (I tried 2.8 and 3.3)
Select “General” template
click on “scripting” tab
click new (to create a new script)
paste this code:

import bpy

bpy.ops.export_scene.gltf("test.gltf")

click run
click Window → toggle system console
see this error:

Error: Python: Traceback (most recent call last):
File “\Text”, line 3, in
File “C:\Program Files\Blender Foundation\Blender 3.3\3.3\scripts\modules\bpy\ops.py”, line 111, in call
ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
TypeError: Calling operator “bpy.ops.export_scene.gltf” 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’)

You’re missing a parameter for your operator.
https://blender.stackexchange.com/questions/151006/expected-a-string-enum-error-when-attempting-to-add-text-strip

Great! What do I need to add to the code above to make it work?

the parameters?
https://docs.blender.org/api/current/bpy.ops.export_scene.html

I’ve read the documentation. The only required parameter is the filepath. Can you please either answer the question or stop replying?

What do I need to add to the code above to make it work?

No need to get huffy, I have answered your question, it’s linked in the StackExchange post. To quote:

You are passing a string into the function instead of the actual arguments.

In your case, I would assume you need

…(filename=“test.gltf”)

Looks like that doesn’t work.

The first parameter of bpy.ops.export_scene.gltf is the filepath, so specifying the parameter name isn’t necessary in Python (as is the case with most computer languages) also, “filename” is not a parameter of bpy.ops.export_scene.gltf. filepath is a parameter, and I tried that, but I still have the same error.

Have you tried reproducing the failure?

It looks like there were a couple of problems.

  1. Even though the first parameter of bpy.ops.export_scene.gltf is filepath, it seems that it needs to be specified. (Which is not the way Python normally works) It looks like there is a wrapper that requires parameters to be specified in bpy.ops.

  2. the default working directory doesn’t seem to allow write access. To fix this I specified an absolute path.

import bpy

bpy.ops.export_scene.gltf(filepath="C:\\xxx\\xxx\\xxx\\test.gltf")

Had you read the link that was first posted you’d find an explanation of why it is necessary to specify the argument as a keyword argument.

1 Like

Absolutely incorrect. The first unique parameter of this operator is filepath, however all operators implement the bpy.types.Operator class, which specifies three parameters that come before everything else: undo, execution context, and context override. Thus, the parameter filepath is required.

I would recommend reading the API documentation.

let write this command in your python console and you will teach the function:

>>> bpy.ops.export_scene.gltf
bpy.ops.export_scene.gltf(filepath="", check_existing=True, export_format='GLB', ui_tab='GENERAL', export_copyright="", export_image_format='AUTO', export_texture_dir="", export_keep_originals=False, export_texcoords=True, export_normals=True, export_draco_mesh_compression_enable=False, export_draco_mesh_compression_level=6, export_draco_position_quantization=14, export_draco_normal_quantization=10, export_draco_texcoord_quantization=12, export_draco_color_quantization=10, export_draco_generic_quantization=12, export_tangents=False, export_materials='EXPORT', export_colors=True, use_mesh_edges=False, use_mesh_vertices=False, export_cameras=False, use_selection=False, use_visible=False, use_renderable=False, use_active_collection=False, use_active_scene=False, export_extras=False, export_yup=True, export_apply=False, export_animations=True, export_frame_range=True, export_frame_step=1, export_force_sampling=True, export_nla_strips=True, export_def_bones=False, optimize_animation_size=False, export_current_frame=False, export_skins=True, export_all_influences=False, export_morph=True, export_morph_normal=True, export_morph_tangent=False, export_lights=False, export_displacement=False, will_save_settings=False, filter_glob="*.glb;*.gltf")

Here are the options of this function!