AttributeError: Calling operator “bpy.ops.import_scene.obj” error, could not be found
问题描述
源代码:
import bpy
# Specify the path to your OBJ file
obj_path = 'C:/path/to/your/model.obj' # Replace with the path to your OBJ file
# Import the OBJ file
bpy.ops.import_scene.obj(filepath=obj_path)
报错:
ASDF\figures\materials\untitled.blend\render.py", line 19, in
File “C:\Program Files\Blender Foundation\Blender 4.0\4.0\scripts\modules\bpy\ops.py”, line 109, in call
ret = _op_call(self.idname_py(), kw)
AttributeError: Calling operator “bpy.ops.import_scene.obj” error, could not be found
问题分析
blender更新后没有了以前的Import-Export Wavefront
add-on,并将其写进了自身的库中,可以更改为:
bpy.ops.wm.obj_import(filepath=obj_path)
即可。
保存obj则改为:
bpy.ops.wm.obj_export(filepath=obj_path)
详细信息可以参考新版的blender python API document。