Plantillas de aplicación#

Utilización#

Las plantillas de aplicación son una característica que permite definir una configuración reutilizable que puede ser seleccionada para reemplazar la configuración predefinida, sin necesitar tener una instalación separada de Blender o sobrescribir la configuración personal en uso.

Las plantillas de aplicación podrán ser seleccionadas desde la Imagen de bienvenida o el submenú Archivo ‣ Nueva. Cuando no se encontraran plantillas, el menú no será mostrado en la Imagen de bienvenida.

Será posible instalar nuevas plantillas de aplicación desde el Menú de Blender. Si se deseara mantener activa a la plantilla de aplicación actual cuando se reinicie Blender, deberán guardarse las preferencias.

Motivación#

En algunos casos no alcanzará con escribir un script o complemento individual y esperar que los usuarios reemplacen sus preferencias y sus archivo de inicio, instalen scripts y cambien su mapa de teclado.

El objetivo de las plantillas de aplicación es soportar el cambio a una configuración personalizada sin distorsionar la configuración e instalación existente del programa. Esto significará que los usuarios podrán crear sus propias aplicaciones sobre Blender, que podrán ser fácilmente distribuidas.

Detalles#

Una plantilla de aplicación podrá definir su propias opciones, tales como:

Archivo de inicio

El archivo predefinido a ser cargado junto con esta plantilla.

Preferencias

Sólo ciertas preferencias de una plantilla serán usadas:

  • Temas.

  • Complementos.

  • Mapas de teclado.

  • Iluminación de las vistas 3D.

Imagen de bienvenida

Las plantillas podrán proporcionar sus propias imágenes de bienvenida.

Scripts de Python

Si bien en las plantillas de aplicación se tendrá acceso a la misma funcionalidad que en cualquier otro script, algunas operaciones usuales incluirán:

  • Modificar y reemplazar partes de la interfaz de usuario.

  • Definir nuevos menús, mapas de teclado y herramientas.

  • Definir una ruta personalizada de complementos, para complementos específicos de la plantilla.

Las plantillas también contendrán su propia configuración de usuario, por lo que al guardar un archivo de inicio mientras se utiliza una plantilla no se sobrescribirá el archivo de inicio predefinido.

Estructura de directorios#

Las plantillas podrán estar ubicadas en un de dos lugares posibles, dentro del directorio scripts.

Ubicaciones de plantillas:
{SCRIPTS_DEL_USUARIO_DE_BLENDER}/startup/bl_app_templates_user
{SCRIPTS_DEL_SISTEMA_DE_BLENDER}/startup/bl_app_templates_system

La configuración será almacenada dentro de un subdirectorio:

Sin una plantilla:
./config/startup.blend
./config/userpref.blend
Con una plantilla:
./config/{ID_DE_PLANTILLA}/startup.blend
./config/{ID_DE_PLANTILLA}/userpref.blend

Ver Estructura de directorios de Blender para más detalles acerca de las ubicaciones de scripts y configuraciones.

Consejo

Resolución de problemas con rutas de archivo

When creating an 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):

blender --log "bke.appdir.*" --log-level -1 --app-template my_app_template

You can then check the paths where attempts to access my_app_template are made.

Acceso mediante línea de comandos#

Using the command-line arguments you can setup a launcher that opens Blender with a specific app template:

blender --app-template my_template

Contenido de las plantillas#

Each of the following files can be used for application templates but are optional.

startup.blend

Factory startup file to use for this template.

userpref.blend

Factory preferences file to use for this template. When omitted preferences are shared with the default Blender configuration.

(As noted previously, this is only used for a subset of preferences).

splash.png

Splash screen to override Blender’s default artwork (not including header text). Note, this image must be a 1000x500 image.

__init__.py

A Python script which must contain register and unregister functions.

Nota

Bundled blend-files startup.blend and userpref.blend are considered Factory Settings and are never overwritten.

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.

The original template settings can be loaded using: Load Template Factory Settings from the file menu in much the same way Load Factory Settings works.

Scripts de plantillas#

While app templates can use Python scripts, they simply have access to the same APIs 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 are 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)