Does anyone know if an addon for this exists?
I’ve searched high and low but I’m having no luck. I know how to copy and paste drivers for individual colour channels, but it is tedious and time consuming.
Does anyone know if an addon for this exists?
I’ve searched high and low but I’m having no luck. I know how to copy and paste drivers for individual colour channels, but it is tedious and time consuming.
Hmm… I haven’t seen one for it, and my search isn’t showing anything, but it should be simple to whip up. Do you have any Python experience?
I wouldn’t call what I know in Python experience, as I mainly reverse engineer things to figure them out. I’ve given this a stab but it’s way over my head.
Color as a custom property ?? Even downloaded 3.4 alpha… did i misss something??
I’m in 3.0.1. You just need to change these:
Ahhh… thanks… i learnt someting new today… (also in 3.3.1)…
So,… Type and Sub Type are something new?
I’m at 2.93 - don’t see it.
( BTW… I don’t know very much about drivers )
Hmm… playing with this… i can connect the driver per color (r,g,b) aka array index (0,1,2) as you already know… but naahh not as one color object (something like: casted from int array…) … but it’s only updating if i hit Update Dependencies … but’s that’s not your problem
Yes an addon (or an native procedure) would be helpful…
… hmm even using the Vieeport Display Color for this instead a Custom Property doesn’t help (because it’s looks much more like a color-object )
>>> print( bpy.data.objects["Object"].color) )
>>> <bpy_float[4], Object.color>
But where to insert in the driver… ? Seems to be not possible yet…
Over a year later, I tried again ! Success…
Who knows if this is the proper way to do it, but it works…
For 3.0:
import bpy
from bpy.types import Operator, Header, Menu, Panel
class WM_MT_button_context(Menu):
bl_label = ""
def draw(self, context):
pass
def draw_func_above(self, context):
layout = self.layout
try:
prop = context.button_prop
obj = context.button_pointer
if prop.subtype == 'COLOR':
if obj.type == 'MESH' or obj.type == 'EMPTY':
layout.operator("rgbdrivers.copy_customprop",text="Copy driver as RGB - Custom Prop",icon='COPYDOWN')
if obj.node != None and bpy.types.Scene.CopyRGB_copied == 1:
layout.operator("rgbdrivers.paste_nodegroup",text="Paste driver as RGB - Node Group",icon='PASTEDOWN')
except:pass
class Copy_CustomProp(Operator):
bl_idname = "rgbdrivers.copy_customprop"
bl_label = ""
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
def execute(self, context):
prop = context.button_prop
obj = context.button_pointer
bpy.types.Scene.CopyRGB_obj = obj.name
bpy.types.Scene.CopyRGB_prop = prop.name
bpy.types.Scene.CopyRGB_copied = 1
obj.update_tag()
return{'FINISHED'}
class Paste_NodeGroup(Operator):
bl_idname = "rgbdrivers.paste_nodegroup"
bl_label = ""
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
def execute(self, context):
prop = context.button_prop
obj = context.button_pointer
node = obj.node
def rgb_driver(index,color):
fcurve = node.outputs[0].driver_add("default_value",index)
d = fcurve.driver
d.type = 'AVERAGE'
v = d.variables.new()
v.name = color
t = v.targets[0]
t.id_type = 'OBJECT'
t.id = bpy.data.objects[bpy.types.Scene.CopyRGB_obj]
t.data_path = f'["{bpy.types.Scene.CopyRGB_prop}"]' + f'[{index}]'
rgb_driver(0,"red")
rgb_driver(1,"green")
rgb_driver(2,"blue")
return{'FINISHED'}
classes = (
WM_MT_button_context,
Copy_CustomProp,
Paste_NodeGroup
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.WM_MT_button_context.prepend(draw_func_above)
bpy.types.Scene.CopyRGB_obj = bpy.props.StringProperty()
bpy.types.Scene.CopyRGB_prop = bpy.props.StringProperty()
bpy.types.Scene.CopyRGB_copied = bpy.props.StringProperty()
def unregister():
bpy.types.WM_MT_button_context.remove(draw_func_above)
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.CopyRGB_obj
del bpy.types.Scene.CopyRGB_prop
del bpy.types.Scene.CopyRGB_copied
if __name__ == "__main__":
register()
Nice… to come back and show this
Well done that you managed to look into it and complete it.
Only one thing to correct is this:
import bpy
# create property
bpy.types.Scene.CopyRGB_obj = bpy.props.StringProperty()
# warning: this will set the value to the class itself
# as if it is a static value
bpy.types.Scene.CopyRGB_obj = 'OBJECT_NAME'
# >>> bpy.types.Scene.CopyRGB_obj
# 'OBJECT_NAME'
class Item:
value = 'HELLO' # this is static value
def __init__(self):
self.value = '' # this is instance value
i = Item()
print(Item.value)
print(i.value)
# if I go to a new scene I will get the static
# value of the class like this
# >>> C.scene.name +" "+ bpy.types.Scene.CopyRGB_obj
# 'Scene.001 OBJECT_NAME'
# so the real trick here is to access
# all of the properties from context objects
print(bpy.context.scene.CopyRGB_obj)