Process/Addons/Rigify/ScriptGenerator

= UI Script Generator =

Every generated rig comes with a Python script that implements a set of rig-specific UI panels. The generation of this script is managed by the ScriptGenerator generator plugin.

The script consists of a set of utility functions and operators, followed by the panels themselves.

ScriptGenerator
An instance of this class implements the generation of the script, and is accessible as `generator.script` or `rig.script`.

Utility Code
These methods are used to add utility code to the script, and register it when necessary.

All string lists added by these methods are concatenated together and filtered for duplicates before adding to the script. This allows easily sharing code between rigs without duplication by sharing code strings.


 * `script.add_imports(str_list)`
 * Adds module import lines to the script.


 * `script.add_utilities(str_list)`
 * Add utility code to the script.


 * `script.register_classes(name_list)`
 * Add class names to be registered in the module register function.


 * `script.register_driver_functions(name_list)`
 * Add function names to be added to the driver function namespace.


 * `script.register_property(name, definition)`
 * Add a custom property to be registered.

Examples:

It is recommended to store the string lists used in calls to these functions in module global variables, in order to allow other modules to easily share the code later by using the same globals.

UI Panel Code
The script provides a UI panel that shows properties and operators relevant for the currently selected bones of the rig. These methods are used to generate the code for it.


 * `script.add_panel_code(str_list)`
 * Directly adds code to the panel. This method is deprecated and provided only for compatibility with legacy code.


 * `script.panel_with_selected_check(rig, control_names)`
 * Returns a PanelLayout object for generating a section of the panel belonging to the specified rig, and shown when the specified controls are selected. Repeated calls with the same parameters return the same panel object.
 * The sub-panels are ordered based on the sequence of the calls to this method, with panels belonging to the same rig always placed adjacent to each other.

PanelLayout
Objects of this class are used to generate the panel code in a structured way, resembling the standard UILayout code.

The methods of the class accept arbitrary keyword parameters, denoted with '`...`', which are converted to strings and added verbatim to the generated UILayout calls.


 * `panel.script`
 * Property referencing the ScriptGenerator that owns the panel.


 * `panel.use_bake_settings`
 * Request the Bake settings panel to be generated.


 * `panel.custom_prop(bone_name, prop_name, ...)`
 * Generates a `layout.prop` call for the specified custom property of the specified bone.


 * `panel.operator(operator_name, properties=None, ...)`
 * Generates a `layout.operator` call, invoking the specified operator. The `properties` dictionary may be provided to assign input values to the properties of the operator itself.
 * The operator name may contain `'{rig_id}'` to automatically include the unique ID string of the rig.


 * `panel.row(...)`
 * Generates a `layout.row` call, and returns a PanelLayout object representing the sub-panel.


 * `panel.column(...)`
 * Generates a `layout.column` call, and returns a PanelLayout object representing the sub-panel.


 * `panel.split(...)`
 * Generates a `layout.split` call, and returns a PanelLayout object representing the sub-panel.