0
$\begingroup$

I would like to add a custom colour picker for a custom material section. The colour picker should be below the red line in the image:

Color picker position

I found a code but this make the colour picker on the "tool panel" and not on the "material panel". This is the code:

import bpy


class POSE_PT_test(bpy.types.Panel):
    bl_label = "Test"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_category = "Testing"

    @classmethod
    def poll(self, context):
        return True

    def draw(self, context):
            self.layout.prop(context.scene, "test_color", text='Detail Color')

def register():
    bpy.utils.register_class(POSE_PT_test)
    bpy.types.Scene.test_color = bpy.props.FloatVectorProperty(
        name="myColor",
        subtype="COLOR",
        size=4,
        min=0.0,
        max=1.0,
        default=(1.0, 1.0, 1.0, 1.0)
    )

register()

Hope someone can help me to change this code so that it will be on material panel and below the red line. Thanks in advance.

$\endgroup$
3
  • 1
    $\begingroup$ To change your test code to be a panel in materials tab of properties space use bl_space_type = 'PROPERTIES' and bl_region_type = 'WINDOW' and bl_context = "material" . As for adding under red line in image above, (without an ugly hack) would need to edit into the draw code of that panel. $\endgroup$
    – batFINGER
    Jan 31, 2018 at 14:54
  • $\begingroup$ Related Rearranging elements of a panel $\endgroup$
    – batFINGER
    Jan 31, 2018 at 15:12
  • $\begingroup$ @batFINGER Can you guide me to make it under the red line in the image above? I have tried the code suggested by you but it gives error on line bpy.utils.register_class(POSE_PT_test) $\endgroup$ Jan 31, 2018 at 18:03

1 Answer 1

1
$\begingroup$

You need to change:

    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "material"

The panel will end up like this

class POSE_PT_test(Panel):
    bl_label = "The title in the materials section"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "material"
    bl_options = {'DEFAULT_CLOSED'}
    tag = 0
  
    @classmethod
    def poll(self, context):
        return True
    def draw(self, context):
        layout = self.layout
        col = layout.column(align=True)
        col.prop(context.scene, "test_color", text='Detail Color')

This is a little late but hope it can help anyone else that comes here

$\endgroup$

You must log in to answer this question.

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