应用模板

    Application templates can be selected from the splash screen or File ‣ New submenu. When there are no templates found the menu will not be displayed on the splash screen.

    可以在 安装新的应用模板。如果要在重新启动Blender时保留当前的应用模板,请保存偏好设置。

    有些时候,写一个简单的脚本或者插件可能还不足以解决问题,一些用户可能希望有人可以为其替换用户设置和启动文件、安装脚本并修改键位映射。

    应用模板的存在意在帮助用户快速切换到自定义配置,而无需破坏已有的设置和安装环境。这意味着人们可以在Blender基础上自行构建易于分发的 应用

    应用模板需要定义其自身以下内容:

    启动文件

    加载模板后的默认文件。

    用户设置

    应用模板中只有某些特定用户设置才会被用到:

    • 主题。

    • 插件。

    • 键位映射。

    • 视窗照明.

    启动画面

    模板可以使用自定义启动画面图像。

    Python脚本

    模板可以与其他脚本一样访问功能,典型的操作包括:

    • 修改和替换部分用户界面。

    • 定义新的菜单、键位映射和工具。

    模板也有自己的用户配置,所以使用模板时保存启动文件不会覆盖默认的启动文件。

    模板文件可以放在 目录下两个位置之一。

    模板位置:

    {BLENDER_USER_SCRIPTS}/startup/bl_app_templates_user

    {BLENDER_SYSTEM_SCRIPTS}/startup/bl_app_templates_system

    用户配置保存在其子目录:

    没有模板:

    ./config/startup.blend

    ./config/userpref.blend

    有模板:

    ./config/{APP_TEMPLATE_ID}/startup.blend

    ./config/{APP_TEMPLATE_ID}/userpref.blend

    更多关于脚本和配置位置的细节见 Blender目录布局

    使用 可以设置Blender启动器以指定的应用模板启动:

    应用模板可以配置以下文件,不过这是可选的。

    startup.blend

    改模板的初始文件.

    userpref.blend

    用于该模板的初始设置文件。当被忽略的设置是与默认Blender配置共用的。

    splash.png, splash_2x.png

    启动画面会覆盖Blender的默认作品(不包含标题栏文字)。必须是 501x2501002x500 (用于HiDPI显示器)。

    __init__.py

    Python脚本必须包含 registerunregister 方法。

    Note

    自带的blend文件 startup.blenduserpref.blend 视作 初始设置 ,且不会被覆盖。

    The user may save their own startup/preferences while using this template which will be stored in their user configuration, but only when the template includes its own userpref.blend file.

    恢复初始设置 一样,用户可以从文件菜单使用 加载模板初始设置 加载模板初始设置。

    虽然应用模板可以使用 Python 脚本,但它们只是可以访问用于插件和任何其他脚本的相同API。

    正如上文所言,可以选择在应用模板中使用 __init__.py。这样做有以下优势:

    • 无需分发blend文件即可更改启动或首选项。

    • 可以动态更改。

      比如,可以配置模板为先检查处理器、操作系统和内存,然后基于此设置参数值。

    • 可以启用与模板关联的插件。

    激活时,将调用 register 函数,当选择另一个模板时,将调用 unregister

    由于这些只运行一次,因此对默认值进行任何更改都必须通过处理程序。下面两个是你可能会用到的两个处理程序:

    • bpy.app.handlers.load_factory_preferences_post

    • bpy.app.handlers.load_factory_startup_post

    以上两者用于自定义用户可以更改的”初始设置”,就像 Blender 在首次启动时的默认值一样。

    1. import bpy
    2. from bpy.app.handlers import persistent
    3. def load_handler_for_preferences(_):
    4. print("Changing Preference Defaults!")
    5. from bpy import context
    6. prefs = context.preferences
    7. prefs.use_preferences_save = False
    8. kc = context.window_manager.keyconfigs["blender"]
    9. kc_prefs = kc.preferences
    10. if kc_prefs is not None:
    11. kc_prefs.select_mouse = 'RIGHT'
    12. kc_prefs.spacebar_action = 'SEARCH'
    13. kc_prefs.use_pie_click_drag = True
    14. view = prefs.view
    15. view.header_align = 'BOTTOM'
    16. @persistent
    17. print("Changing Startup Defaults!")
    18. for mesh in bpy.data.meshes:
    19. for poly in mesh.polygons:
    20. poly.use_smooth = True
    21. # Use material preview shading.
    22. for screen in bpy.data.screens:
    23. for area in screen.areas:
    24. for space in area.spaces:
    25. if space.type == 'VIEW_3D':
    26. space.shading.type = 'MATERIAL'
    27. space.shading.use_scene_lights = True
    28. def register():
    29. print("Registering to Change Defaults")
    30. bpy.app.handlers.load_factory_preferences_post.append(load_handler_for_preferences)
    31. bpy.app.handlers.load_factory_startup_post.append(load_handler_for_startup)
    32. def unregister():
    33. print("Unregistering to Change Defaults")
    34. bpy.app.handlers.load_factory_startup_post.remove(load_handler_for_startup)