Blender:AttributeError:''u RestrictContext'对象没有属性“scene”

2024-05-21 15:30:20 发布

您现在位置:Python中文网/ 问答频道 /正文

运行脚本时,出现以下错误:

AttributeError: '_RestrictContext' object has no attribute 'scene'

我正在尝试创建一个优化脚本:

bl_info = {
"name": "Empic Stone",
"author": "Null",
"version": (0, 0, 1),
"blender": (2, 79, 0),
"location": "VIEW3D > ADD > Mesh",
"description": "Empic Stone",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Add Mesh"}

# Imports
import bpy

# Mesh - Create Cubic
bpy.ops.mesh.primitive_cube_add(location=(0.00, 0.00, 1.00))

def draw_item(self, context):
     self.layout.operator_context = 'INVOKE_DEFAULT'
     self.layout.operator(EpicStone.bl_idname, text="Epic Stone", icon="PLUGIN")

def register():
    bpy.utils.register_module(__name__)
    bpy.types.INFO_MT_mesh_add.append(draw_item)

def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.INFO_MT_mesh_add.remove(draw_item)

if __name__ == '__main__':
     register()

Tags: nameself脚本registeradddeflocationitem
1条回答
网友
1楼 · 发布于 2024-05-21 15:30:20

为blender指定这个脚本可能会帮助人们。我用过它,这是我认识它的唯一原因。不管怎样,这种错误通常会发生,因为Blender限制访问bpy.上下文以及bpy.数据. 这是来自documentation

This is done because there is no assurance that the data loaded when the addon is registered will be active or even exist when the user accesses operators the addon defines. If you see an exception like this, then the addon needs to be updated to access the context during execution rather then on registration:

现在不要“重新发明轮子”,请遵循上面的链接并遵循他们的代码。在

相关问题 更多 >