Auto Run Python Script from Text window I have a blend file that contains the following scenes:

• Clothing
• Compositing
• Paper
• Social Media
• Van

The idea is that guys in my office who aren't 3d literate can save a logo design as a texture file, then open this Blend file, hit render and it spits out a bunch of images showing off the logo in different scenarios.

The only sticking point is that they may need to change the colour of parts of the files so I have put together the following python script which when run allows them to just use colour pickers to change the colours. 

import bpy
from bpy.types import Panel

class ExamplePanel(Panel):
bl_label = "Background Colours"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'


def draw(self, context):
    layout = self.layout


     #Paper Scene Inputs

    obj = bpy.data.objects["OfficePaper"]

    mat = obj.active_material
    if not mat:
        layout.label("Create a material")
        return

    nodes = mat.node_tree.nodes

    # Define the Specific Node
    paper_colour = nodes["Principled BSDF.001"]
    mix = nodes["Mix Shader"]

    layout.label("Office Paper Scene")
    layout.prop(paper_colour.inputs["Base Color"], "default_value", text="Paper Colour")


     #Clothing Scene Inputs           

    obj = bpy.data.objects["Embroidered_Cloth"]

    mat = obj.active_material
    if not mat:
        layout.label("Create a material")
        return

    nodes = mat.node_tree.nodes

    # Define the specific node
    clothing_colour = nodes["Principled BSDF"]
    mix = nodes["Mix Shader"]

    layout.label("Printed Clothing Scene")
    layout.prop(clothing_colour.inputs["Base Color"], "default_value", text="Clothing Colour")





     #Social Media Scene Inputs           

    obj = bpy.data.objects["iPhone"]

    mat = obj.active_material
    if not mat:
        layout.label("Create a material")
        return

    nodes = mat.node_tree.nodes

    # Define the specific node
    postbg_colour = nodes["MixBGColour"]


    layout.label("Social Media Scene")
    layout.prop(postbg_colour.inputs["Color1"], "default_value", text="Background Colour")




     #Vehicle Graphics Scene Inputs           

    obj = bpy.data.objects["Van"]

    mat = obj.active_material
    if not mat:
        layout.label("Create a material")
        return

    nodes = mat.node_tree.nodes

    # Define the specific node
    vanpaint_colour = nodes["VanColour"]


    layout.label("Social Media Scene")
    layout.prop(vanpaint_colour.inputs["Base Color"], "default_value", text="Van Colour")        




if __name__ == "__main__":  # only for live edit.
from bpy.utils import register_class
register_class(ExamplePanel)


This script, micraculously given my limited scripting experience, works fine.

The final hurdle though is that I want this script to be loaded ready for them so that they don't even have to worry themselves with clicking the Run Script button and hence having to leave the code open to the risk of accidental editing.

I have the the Register Check box checked and I have the name of the text datablock as cp.py  I have also set the preferences to Auto Execute but so far nothing works at all.
Requirements for auto running a script.

Press CTRL+ALT+U
to open user prefernces.

In the File tab ensure Auto Execution is checked.

Save User settings.

In Text editor:
Create new text block.

Copy script into new text block (ensure the script has an explicit register function note bottom lines).

Save text block as cp.py. Unlink text block. Open cp.py.

Click Register checkbox.

Save Blend file
Close Blend file
re-Open Blend file ... panel should auto run.

import bpy
from bpy.types import Panel


class ExamplePanel(Panel):
    bl_label = "Background Colours"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'

    def draw(self, context):
        layout = self.layout
        obj_types = ['MESH', ]  # add types as needed
        objs = [obj for obj in bpy.data.objects if
                obj.type in obj_types and obj.select]
        col_types = ['RGBA', ]  # add types as needed
        for obj in objs:
            box = layout.box()
            box.label(obj.name)
            # for viewport or non node colors
            if obj.active_material:
                my_mat = [mat for mat in bpy.data.materials if
                          mat.name == obj.active_material.name]
                box.label("Viewport Color")
                box.prop(my_mat[0], "diffuse_color", text="")
            else:
                box.label("Requires active material")
            # for materials using shader nodes
            if my_mat[0].use_nodes:
                my_nodes = [nd for nd in my_mat[0].node_tree.nodes]
                box = box.box()
                box.label("Render color")
                for node in my_nodes:
                    for ip in node.inputs:
                        if ip.type in col_types:
                            box.prop(ip, "default_value", text=("%s: %s" % (node.type, ip.name)))

classes = [ExamplePanel, ]


def register():
    for cls in classes:
        bpy.utils.register_class(cls)


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)


#if __name__ == "__main__":  # only for live edit.
#    register()

register()  # required for autorun