应用模板
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目录布局 。
Hint
Troubleshooting Paths
When creating a application template, you may run into issues where paths are not being found. To investigate this you can log output of all of Blender’s path look-ups.
Example command line arguments that load Blender with a custom application template (replace my_app_template
with the name of your own template):
You can then check the paths where attemps to access are made.
使用 可以设置Blender启动器以指定的应用模板启动:
应用模板可以配置以下文件,不过这是可选的。
startup.blend
改模板的初始文件.
userpref.blend
(如前文所述,这仅仅是用户设置的子集).
splash.png
Splash screen to override Blender’s default artwork (not including header text). Note, this image must be a 1000x500
image.
__init__.py
Python脚本必须包含 register
与 unregister
方法。
Note
自带的blend文件 和 userpref.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.
与 恢复初始设置 一样,用户可以从文件菜单使用 加载模板初始设置 加载模板初始设置。
While app templates can use Python scripts, they simply have access to the same APIs available for add-ons and any other scripts.
正如上文所言,可以选择在应用模板中使用 __init__.py
。这样做有以下优势:
无需分发blend文件即可更改启动或首选项。
可以动态更改。
比如,可以配置模板为先检查处理器、操作系统和内存,然后基于此设置参数值。
可以启用与模板关联的插件。
激活时,将调用 register
函数,当选择另一个模板时,将调用 unregister
。
由于这些只运行一次,因此对默认值进行任何更改都必须通过处理程序。下面两个是你可能会用到的两个处理程序:
bpy.app.handlers.load_factory_startup_post
以上两者用于自定义用户可以更改的”初始设置”,就像 Blender 在首次启动时的默认值一样。
下面是一个 文件范例,定义了应用模板要使用的默认值。