0
$\begingroup$

I unfortunatly to stupid to make it work. I need to change a diffuse color of active material by selecting it by COLOR_GAMMA popup - color picker.

I did this:

import bpy
class MaterialColorPanel(bpy.types.Panel):
    bl_label = "3dView Material Color"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "material"    
    bpy.types.Scene.color_Material = bpy.props.FloatVectorProperty(name="color_Material",subtype = "COLOR_GAMMA", default = [1.0,0.0,0.0])
    bpy.context.object.active_material.diffuse_color=(1,1,0)

    def draw(self, context): 
        self.layout.prop(context.scene,"color_Material")

def register():
    bpy.utils.register_class(MaterialColorPanel)

def unregister():
    bpy.utils.unregister_class(MaterialColorPanel)

bpy.utils.register_module(__name__)

But I do not know how to make that picked color value by bpy.types.Scene.color_Material will be copied to bpy.context.object.active_material.diffuse_color and will change it.

Could somobody show me how to do it ? Thank you!

$\endgroup$

1 Answer 1

1
$\begingroup$

Ok...at last I have figured it out! Probably I am not so stupid as I thought. I made this that works perfectly:

import bpy

class MaterialColorPanel(bpy.types.Panel):
    bl_label = "3dView Material Color"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "material"

    def color_update(self, context):
        col_R=self.color_Material[0]
        col_G=self.color_Material[1]
        col_B=self.color_Material[2]
        bpy.context.object.active_material.diffuse_color=(col_R,col_G,col_B)
        print(">UPDATE:", col_R, col_G, col_B)


    bpy.types.Scene.color_Material=bpy.props.FloatVectorProperty(   
                                        name="Material Color", 
                                        subtype = "COLOR_GAMMA", 
                                        default = [1.0,0.0,0.0],
                                        update=color_update)

    def draw(self, context): 
        self.layout.prop(context.scene,"color_Material")

    def invoke(self, context, event):
        print(self.colMat)
        return{"FINISHED"}


def register():
        bpy.utils.register_class(MaterialColorPanel)

def unregister():
        bpy.utils.unregister_class(MaterialColorPanel)

bpy.utils.register_module(__name__)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .