1
$\begingroup$

If you ever used BlenRig, you may have noticed that it pops up a text file in your text editor called "generate_customprops.py". This is a python script that the rig uses for various purposes such as automatically disabling drivers and hiding bones. When you append a BlenRig rig to another file, this text file comes with it.

I also need to execute some python script in my own custom rig, and I also have a text file. The functions in the script can be called from any Driver. All of this works fine and opens a lot of new possibilities for what a rig can do. However, if I try to append my rig to another blend file, the text file will not come with it, and has to be appended separately. Since I'm trying to create public rigs for other people to use, this is not ideal. Any help would be appreciated!

$\endgroup$
1
$\begingroup$

PointerProperty

Another method would be to associate the text with the armature object or armature itself using a bpy.props.PointerProperty(type=bpy.types.Text)

import bpy
from bpy.props import PointerProperty

bpy.types.Armature.script_file = PointerProperty(type=bpy.types.Text)

As shown in this answer can poll the property. Another test script with a sample UI panel and the text associated to an armature object.

import bpy    

class OBJECT_PT_HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    #poll for armature object
    @classmethod
    def poll(cls, context):
        return context.object and context.object.type == 'ARMATURE'

    def draw(self, context):
        layout = self.layout
        arm_ob = context.object
        layout.prop(arm_ob, "rig_script")

def is_armature_object(self, object):
    return self.type == 'ARMATURE'


def register():
    bpy.utils.register_class(OBJECT_PT_HelloWorldPanel)
    bpy.types.Object.rig_script = bpy.props.PointerProperty(
        type=bpy.types.Text,
        poll=is_armature_object,
    )


def unregister():
    bpy.utils.unregister_class(OBJECT_PT_HelloWorldPanel)
    del bpy.types.Object.rig_script


if __name__ == "__main__":
    register()
$\endgroup$
0
$\begingroup$

I have found not one but two solutions. Credits to Juan Pablo Bouza and Daniel Salazar.

Solution 1: Logic Editor(being removed in 2.8) You can simply reference the text file in the logic editor.

Logic Editor

I won't detail this much because I believe the second solution to be superior.

Solution 2: Driver variables can actually reference text files.

In your driver(any driver that is part of your rig) add a new variable with Single Property type. Then by clicking on the object icon, you can select (almost?) any data type that exists in Blender. Including text files! Driver variable

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.