You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Blender Python自定义工具报错'module'无'operator'属性求助

Blender批量导出FBX插件报错修复方案

错误根因

报错核心为类继承时的基类名拼写错误:Blender API 中的运算符基类为大驼峰命名的Operator,你代码中使用了全小写的operator,bpy.types模块下不存在该小写属性,因此触发AttributeError。

修复步骤

仅需修改类定义行的基类名称即可:

  • 原代码第9行:class EXP_fbxbatchexport(bpy.types.operator):
  • 修改为:class EXP_fbxbatchexport(bpy.types.Operator):

修正后完整代码

# exports each selected object into its own file
import bpy
import os
class EXP_fbxbatchexport(bpy.types.Operator):
   """Tooltip here"""
   bl_idname = "mesh.fbxbatchexport"
   bl_label = "FBX Batch Exporter"

   def execute(self, context):
    
       # export to blend file location
       basedir = os.path.dirname(bpy.data.filepath)

       if not basedir:
           raise Exception("Blend file is not saved")

       view_layer = bpy.context.view_layer

       obj_active = view_layer.objects.active
       selection = bpy.context.selected_objects

       bpy.ops.object.select_all(action='DESELECT')

       for obj in selection:

           obj.select_set(True)

           # some exporters only use the active object
           view_layer.objects.active = obj

           name = bpy.path.clean_name(obj.name)
           fn = os.path.join(basedir, name)

           bpy.ops.export_scene.fbx(filepath=fn + ".fbx", use_selection=True)

           # Can be used for multiple formats
           # bpy.ops.export_scene.x3d(filepath=fn + ".x3d", use_selection=True)

           obj.select_set(False)

           print("written:", fn)

       view_layer.objects.active = obj_active

       for obj in selection:
           obj.select_set(True)
    
       return {'FINISHED'}    
def register():
   bpy.utils.register_class(EXP_fbxbatchexport)
def unregister():
   bpy.utils.unregister_class(EXP_fbxbatchexport)
#this function only calls to register the function when the code is actually run
if __name__ == '__main__':
   register()

可选优化建议

将bl_idname调整为export.fbx_batch_export,更符合Blender官方运算符命名规范,不影响功能仅提升代码可读性。

内容的提问来源于stack exchange,提问作者Simon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 03:06:01