Modelos de aplicação¶
Utilização¶
Os «Modelos de aplicação» é um recurso que permite ao usuário definir configurações reutilizáveis que poderão ser selecionadas para substituir as configurações padrão, sem que seja requerida uma instalação separada do Blender ou sobrescrita das suas configurações pessoais.
Application templates can be selected from the splash screen or
sub-menu.Caso nenhum modelo seja encontrado, o menu não será exibido na tela de abertura.
New application templates can be installed from the App Menu.
If you would like to keep the current application template active on restarting Blender, save your preferences.
Objetividade¶
In some cases it’s not enough to write a single script or add-on, and expect someone to replace their preferences and startup file, install scripts and change their keymap.
The goal of application templates is to support switching to a customized configuration without disrupting your existing settings and installation.
Isso significa que as pessoas podem construir suas próprias aplicações ou funcionalidades específicas, tendo o aplicativo Blender como base, de maneira que possam ser facilmente distribuídas.
Detalhes¶
An application template may define its own:
- Arquivo de inicialização
O arquivo padrão para carregar com este modelo.
- Preferences
Only certain preferences from a template are used:
Temas.
Complementos.
Mapas de teclas.
Iluminação da porta de visão
- Tela de abertura
Os modelos podem também prover alternativamente a sua imagem de tela de abertura.
- Scripts Python
Embora os modelos tenham acesso à mesmas funcionalidades acessíveis por quaisquer outros scripts, as operações típicas incluem também:
Modificando e substituindo partes da interface do usuário.
Defining new menus, keymaps and tools.
Definição de um novo diretório para modelos de complementos específicos.
Templates also have their own user configuration, so saving a startup file while using a template won’t overwrite your default startup file.
Esquemas de diretório¶
Os modelos podem estar localizados em uma das duas localizações contidas no diretório de scripts
.
- Localização dos modelos:
{BLENDER_USER_SCRIPTS}/startup/bl_app_templates_user
{BLENDER_SYSTEM_SCRIPTS}/startup/bl_app_templates_system
Configurações do usuário são armazenadas em um subdiretório:
- Sem um modelo:
./config/startup.blend
./config/userpref.blend
- Com um modelo:
./config/{APP_TEMPLATE_ID}/startup.blend
./config/{APP_TEMPLATE_ID}/userpref.blend
See Blender’s Directory Layout for details on script and configuration locations.
Command Line Access¶
Using the command-line arguments you can setup a launcher that opens Blender with a specific app template:
blender --app-template my_template
Conteúdos dos modelos¶
Cada um dos seguintes arquivos pode ser usado para modelos de aplicação, mas são opcionais:
startup.blend
Arquivo de inicialização de fábrica a ser usado para este modelo.
userpref.blend
Factory preferences file to use for this template.
When omitted preferences are shared with the default Blender configuration.
(Como mencionado anteriormente, isso só é usado para um subconjunto de preferências).
splash.png
,splash_2x.png
Splash screen to override Blender’s default artwork (not including header text).
Must be
501x250
and1002x500
(used for HiDPI monitors).__init__.py
Um script Python que contém as funções
register
(registrar) e ``unregister``(remover o registro).
Nota
Os arquivos Blender startup.blend
e userpref.blend
empacotados são considerados Configurações de Fábrica e nunca são sobrescritos.
The user may save their own startup/preferences while using this template which will be stored in their user configuration.
As configurações originais do modelo podem ser carregadas usando a opção: Carregar modelo de configurações de fábrica a partir do menu Arquivo, da mesma maneira como a opção Carregar as configurações de fábrica funciona.
Template Scripts¶
While app templates can use Python scripts, they simply have access to the same API’s available for add-ons and any other scripts.
As noted above, you may optionally have an __init__.py
in your app template.
This has the following advantages:
Changes can be made to the startup or preferences, without having to distribute a blend-file.
Changes can be made dynamically.
You could for example – configure the template to check the number of processors, operating system and memory, then set values based on this.
You may enable add-ons associated with your template.
On activation a register
function is called, unregister
is called when another template is selected.
As these only run once, any changes to defaults must be made via handler.
Two handlers you’re likely to use are:
bpy.app.handlers.load_factory_preferences_post
bpy.app.handlers.load_factory_startup_post
These allow you to define your own «factory settings», which the user may change, just as Blender has it’s own defaults when first launched.
This is an example __init__.py
file which defines defaults for an app template to use.
import bpy
from bpy.app.handlers import persistent
@persistent
def load_handler_for_preferences(_):
print("Changing Preference Defaults!")
from bpy import context
prefs = context.preferences
prefs.use_preferences_save = False
kc = context.window_manager.keyconfigs["blender"]
kc_prefs = kc.preferences
if kc_prefs is not None:
kc_prefs.select_mouse = 'RIGHT'
kc_prefs.spacebar_action = 'SEARCH'
kc_prefs.use_pie_click_drag = True
view = prefs.view
view.header_align = 'BOTTOM'
@persistent
def load_handler_for_startup(_):
print("Changing Startup Defaults!")
# Use smooth faces.
for mesh in bpy.data.meshes:
for poly in mesh.polygons:
poly.use_smooth = True
# Use material preview shading.
for screen in bpy.data.screens:
for area in screen.areas:
for space in area.spaces:
if space.type == 'VIEW_3D':
space.shading.type = 'MATERIAL'
space.shading.use_scene_lights = True
def register():
print("Registering to Change Defaults")
bpy.app.handlers.load_factory_preferences_post.append(load_handler_for_preferences)
bpy.app.handlers.load_factory_startup_post.append(load_handler_for_startup)
def unregister():
print("Unregistering to Change Defaults")
bpy.app.handlers.load_factory_preferences_post.remove(load_handler_for_preferences)
bpy.app.handlers.load_factory_startup_post.remove(load_handler_for_startup)