gpt4 book ai didi

python - 无法在 F3 运算符搜索中找到自定义 Blender 运算符 (Blender 2.9)

转载 作者:行者123 更新时间:2023-12-03 16:12:50 26 4
gpt4 key购买 nike

我正在完成本教程:
https://docs.blender.org/manual/en/latest/advanced/scripting/addon_tutorial.html
我从教程中复制了下面的脚本,当我运行脚本时,它编译没有任何错误。我应该能够在运算符搜索菜单 ( F3 ) 中搜索“将 X 移动一个”来执行运算符,但它没有显示在运算符搜索菜单中。如何让运算符(operator)显示在搜索菜单中? Blender 2.9 有什么变化吗?

bl_info = {
"name": "Move X Axis",
"category": "Object"
}

import bpy

class ObjectMoveX(bpy.types.Operator):
bl_idname = "object.move_x"
bl_label = "Move X by One"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
scene = context.scene
for obj in scene.objects:
obj.location.x += 1.0

return {'FINISHED'}

def register():
bpy.utils.register_class(ObjectMoveX)

def unregister():
bpy.utils.unregister_class(ObjectMoveX)

if __name__ == "__main__":
register()

最佳答案

blender 2.90.1
正如其他用户所指出的,API 已经更新。您可以在此处查看发行说明:
Blender 2.90: Python API它说:

...add-ons that expose operators only through search need to be updated.


这是由于新增了仅搜索菜单的运算符搜索(由 F3 访问)。因此,您需要将运算符添加到菜单中。
添加 menu_func功能:
def menu_func(self, context):
self.layout.operator(ObjectMoveX.bl_idname)
并更新 register功能:
def register():
bpy.utils.register_class(ObjectMoveX)
bpy.types.VIEW3D_MT_object.append(menu_func)
您现在可以通过运营商搜索 ( F3 ) 或通过菜单访问您的运营商,即 Object>YourOperatorName如果您不希望通过这些菜单访问这些内容,发行说明中还会提到:

For more obscure operators that are for example intended mainly for developers, we recommend adding them in the TOPBAR_MT_app_system menu. This is accessible through the System menu under the Blender icon in the top bar.

关于python - 无法在 F3 运算符搜索中找到自定义 Blender 运算符 (Blender 2.9),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63863764/

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