# How to make a Text File dependent of an Armature object so that it appends with it to other projects?

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!

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()


There is now a third and even better solution for this that does not involve misusing a driver.

Custom Properties can now store datablock references. This can only be done via Python, but it's just a one-liner in the console. With your object selected, put this in the console:
bpy.context.object['my_script'] = bpy.data.texts['my_script.py']

This will create a custom property in your object called "my_script" which will reference the text datablock called "my_script.py" - you should change the latter to match your filename.

The textfile is now a dependency of the object, and will be appended when the object is appended.

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.

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!