gpt4 book ai didi

python - blender : AttributeError: '_RestrictContext' object has no attribute 'scene'

转载 作者:太空宇宙 更新时间:2023-11-03 15:50:35 44 4
gpt4 key购买 nike

当运行我的脚本时,我得到这个错误:

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()

最佳答案

指定此脚本适用于 blender 可能会对人们有所帮助。我使用过它,这是我认可它的唯一原因。不管怎样,通常这种错误会发生,因为 Blender 限制了对 bpy.context 和 bpy.data 的访问。这是来自 documentation :

This is done because there is no assurance that the data loaded whenthe addon is registered will be active or even exist when the useraccesses 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:

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

关于python - blender : AttributeError: '_RestrictContext' object has no attribute 'scene' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47064223/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com