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.
"cp"
not"__main__"
so the register code in the if statement will not run. Either remove the if, or change toif __name__ == "cp":
and the register code will run. The example in my other answer has aregister()
method, yours doesn't. $\endgroup$