Confecção de scripts e segurança#

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.

When a blend-file tries to execute a script and is not allowed, a dialog will appear. In it, you can choose to Allow Execution or to Ignore the scripts.

../../_images/advanced_scripting_security_autorun-scripts-dialog.png

An Auto-run warning in the Info editor’s header.#

Scripts em arquivos Blender#

Execução automática#

Presentes aqui, há algumas opções de maneiras diferentes as quais os arquivos Blender podem executar os scripts automaticamente.

Blocos de textos registrados

A text data-block can have its Register option enabled which means it will load on start.

Controladores de animação

Expressões em Python podem ser usadas para Controlar valores e são muitas vezes usadas em arranjos mais avançados e animações.

Execução dos manuais#

Existem outras maneiras as quais um arquivo Blender pode executar scripts que requerem interação com o usuário (portanto irão ser executados mesmo que a execução automática esteja desabilitada), mas você deve estar ciente de que este é um dos casos onde isso não é necessariamente óbvio.

  • Executando um script no editor de textos.

  • Rendering with Freestyle, because Freestyle uses scripts to control line styles.

Controlando a execução de scripts#

O Blender provê determinadas maneiras de controlar se os scripts que estão dentro de um arquivo Blender podem ser executados automaticamente.

First, the File Browser has the option Trusted Source which you can use on a case-by-case basis to control auto execution. Since you may forget to set this, or may open a file without going through the File Browser, you can change the default (described next).

Definição de padrões#

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.

../../_images/animation_drivers_troubleshooting_autorun-user-preference.png

Executar automaticamente scripts Python.#

Linha de comando#

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:

  • Habilite usando o argumento -y ou --enable-autoexec

  • Desabilite com o argumento -Y ou --disable-autoexec

Exemplo#

To render an animation in background mode, allowing drivers and other scripts to run:

blender --background --enable-autoexec my_movie.blend --render-anim

Nota

These command-line arguments can be used to start a regular Blender instance and will still override the Preferences.