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