blender AttributeError: Calling operator “bpy.ops.import_scene.obj“ error, could not be found

blender AttributeError: Calling operator “bpy.ops.import_scene.obj“ error, could not be found

渲染时报错:

import bpy

for obj in bpy.context.scene.objects:
    if obj.name in ['Light', 'Camera']:
        continue
    print('del', obj.name)
    bpy.context.view_layer.objects.active = obj
    bpy.ops.object.delete()

# 导入 OBJ 文件

bpy.ops.wm.obj_import(filepath=r"F:\project\qijun\yolov5_55681_dao\xuanran\3dmodel\logo3d.obj")
# bpy.ops.import_scene.obj(filepath=r"F:\project\qijun\yolov5_55681_dao\xuanran\3dmodel\logo3d.obj")

# 获取导入的对象
# obj = bpy.data.objects[0]
obj = bpy.context.selected_objects[0]

# 在时间轴的第 0 帧设置起始位置和旋转角度
obj.location = (0, 0, 0)
obj.rotation_euler = (0, 0, 0)

# 在时间轴的第 60 帧设置旋转角度
bpy.context.scene.frame_set(60)
obj.rotation_euler = (0, 0, 2 * 3.14)

# 在时间轴的第 120 帧设置旋转角度
bpy.context.scene.frame_set(120)
obj.rotation_euler = (0, 0, 4 * 3.14)

bpy.context.scene.render.resolution_x = 1920
bpy.context.scene.render.resolution_y = 1080
bpy.context.scene.render.fps = 30
bpy.context.scene.render.image_settings.file_format = 'FFMPEG'
bpy.context.scene.render.ffmpeg.format = 'MPEG4'
bpy.context.scene.render.ffmpeg.codec = 'H264'

# 设置输出路径和文件名
bpy.context.scene.render.filepath = r'E:\project\3d\blender\output.mp4'

bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 100

# 开始渲染并保存视频
bpy.ops.render.render(animation=True)

# 渲染完成后停止渲染
bpy.ops.wm.cancel_render()
# bpy.ops.render.cancel_render()

错误原因是该API在blender 4.x已经不存在了,改为bpy.ops.wm.obj_import(filepath=obj_path) 了。

解决方法


将导入函数改为

import bpy
bpy.ops.wm.obj_import(filepath="D:\3dfile\car.obj")



                        
原文链接:https://blog.youkuaiyun.com/qq_38463737/article/details/144018563

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值