在Blender GUI中导入平面图像非常好用,但当我尝试在Python模块中使用它时,出现了以下错误:
RuntimeError: Operator bpy.ops.mesh.primitive_plane_add.poll() Missing 'window' in context
我的代码如下:
import bpy
import addon_utils
# enable plugins
addon_utils.enable("io_import_images_as_planes")
# remove Cube object
bpy.data.objects['Cube'].select = True
bpy.ops.object.delete()
file = "test.jpg"
bpy.ops.import_image.to_plane(files=[{'name':file}], directory='.')