脚本与安全¶
The ability to include Python scripts within blend-files is valuable for advanced tasks such as rigging and automation. However, it poses a security risk since Python does not restrict what a script can do. Therefore, you should only run scripts from sources you know and trust. Automatic execution is disabled by default, however, some blend-files need this to function properly.
当blend文件试图运行脚本并且未被允许,标题栏将显示信息,并提供 允许执行 或者 忽略 该脚本的选项。
Blend文件中的脚本¶
自动运行¶
下面是一些blend文件可能自动运行脚本的方式。
- 注册的文本块
文本数据块可以启用 注册 选项,这意味会在启动时自动加载。
- 动画驱动
Python表达式可以用于 驱动 值,并且经常在进阶的绑定和动画中使用。
手动运行¶
还有一些情况下,blend文件需要用户交互才能运行脚本(因此禁用自动运行也会运行),但你需要清楚这种情形,因为它不是那么显而易见。
在文本编辑器中运行脚本。
使用FreeStyle 渲染,由于 FreeStyle 使用脚本控制线条样式。
控制脚本运行¶
Blender提供了一些用于控制是否允许blend文件中脚本自动运行的方法。
First of all, the File Browser has the option Trusted Source which you can use on a case-by-case basis to control auto execution. However, you may forget to set this, or open a file without going through the File Browser -- so you can change the default (described next).
设置默认值¶
In the Preferences, there is the toggle to Auto Run Python Scripts. This means the Trusted Source option in the File Browser will be enabled by default, and scripts can run when blend-files are loaded without using the File Browser. Once enabled you have the option to exclude certain directories, a typical configuration would be to trust all paths except for the download directory.
命令行¶
You may want to perform batch rendering or some other task from the command line -- running Blender without an interface. In this case, the Preferences are still used but you may want to override them:
使用
-y
or--enable-autoexec
启用使用
-Y
or--disable-autoexec
禁用
例子¶
Rendering an animation in background mode, allowing drivers and other scripts to run:
blender --background --enable-autoexec my_movie.blend --render-anim
Note
命令行参数也可以用来正常启动Blender,并且覆盖用户设置。