0
$\begingroup$

I am trying to invoke the GreasePencilPaletteColorPanel block as a custom menu with the popup function.It didn't compile and on running it in the console didn't give any error. What am I missing?

import bpy


class DialogOperator(bpy.types.Operator):
    bl_idname = "object.dialog_operator"
    bl_label = "GP Colors"

    @classmethod
    def poll(cls, context):
        if context.gpencil_data is None:
            return False

        gpd = context.gpencil_data
        return bool(gpd.layers.active)

    @staticmethod  
    def draw(self, context):
        layout = self.layout
        palette = context.active_gpencil_palette

        if palette:
            row = layout.row(align=True)
            row.operator_context = 'EXEC_REGION_WIN'
            row.operator_menu_enum("gpencil.palette_change", "palette", text="", icon='COLOR')
            row.prop(palette, "name", text="")
            row.operator("gpencil.palette_add", icon='ZOOMIN', text="")
            row.operator("gpencil.palette_remove", icon='X', text="")

            row = layout.row()
            col = row.column()
            if len(palette.colors) >= 2:
                color_rows = 5
            else:
                color_rows = 2
            col.template_list("GPENCIL_UL_palettecolor", "", palette, "colors", palette.colors, "active_index",
                              rows=color_rows)

            col = row.column()

            sub = col.column(align=True)
            sub.operator("gpencil.palettecolor_add", icon='ZOOMIN', text="")
            sub.operator("gpencil.palettecolor_remove", icon='ZOOMOUT', text="")

            palcol = context.active_gpencil_palettecolor
            if palcol:
                sub.menu("GPENCIL_MT_palettecolor_specials", icon='DOWNARROW_HLT', text="")

            if len(palette.colors) > 1:
                col.separator()

                sub = col.column(align=True)
                sub.operator("gpencil.palettecolor_move", icon='TRIA_UP', text="").direction = 'UP'
                sub.operator("gpencil.palettecolor_move", icon='TRIA_DOWN', text="").direction = 'DOWN'

            pcolor = palette.colors.active
            if pcolor:
                self.draw_palettecolors(layout, pcolor)


    def draw_palettecolors(self, layout, pcolor):
        split = layout.split(percentage=0.5)
        split.active = not pcolor.lock

        col = split.column(align=True)
        col.enabled = not pcolor.lock
        col.label(text="Stroke:")
        col.prop(pcolor, "color", text="")
        col.prop(pcolor, "alpha", slider=True)

        col = split.column(align=True)
        col.enabled = not pcolor.lock
        col.label(text="Fill:")
        col.prop(pcolor, "fill_color", text="")
        col.prop(pcolor, "fill_alpha", text="Opacity", slider=True)

        split = layout.split(percentage=0.5)
        split.active = not pcolor.lock

        col = split.column(align=True)
        col.active = not pcolor.lock
        col.prop(pcolor, "use_volumetric_strokes")
        col = split.column(align=True)
        col.active = not pcolor.lock
        col.prop(pcolor, "use_hq_fill")


    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_popup(self, width=450, height=450)


    def execute(self, context):
        return {'FINISHED'}


    def check(self, context):
        return True


bpy.utils.register_class(DialogOperator)

# test call
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
$\endgroup$
  • $\begingroup$ Which space has a context member context.gpencil_data ? $\endgroup$ – batFINGER Nov 3 '18 at 14:01
0
$\begingroup$

@batFINGER updated the space/region type (script below) but still no output/no error.BTW, I could access the Greasepencil color's individual properties like name,fill_color etc by using the invoke_props_dialog operator without specifying the space /region.

import bpy

class DialogOperator(bpy.types.Operator): bl_idname = "gpencil.GPcolor_menu" bl_label = "GP Colors" bl_space_type = 'VIEW_3D' bl_region_type = 'UI'

@classmethod
def poll(cls, context):
    if context.gpencil_data is None:
        return False

    gpd = context.gpencil_data
    return bool(gpd.layers.active)

@staticmethod  
def draw(self, context):
    layout = self.layout
    palette = context.active_gpencil_palette

    if palette:
        row = layout.row(align=True)
        row.operator_context = 'EXEC_REGION_WIN'
        row.operator_menu_enum("gpencil.palette_change", "palette", text="", icon='COLOR')
        row.prop(palette, "name", text="")
        row.operator("gpencil.palette_add", icon='ZOOMIN', text="")
        row.operator("gpencil.palette_remove", icon='X', text="")

        row = layout.row()
        col = row.column()
        if len(palette.colors) >= 2:
            color_rows = 5
        else:
            color_rows = 2
        col.template_list("GPENCIL_UL_palettecolor", "", palette, "colors", palette.colors, "active_index",
                          rows=color_rows)

        col = row.column()

        sub = col.column(align=True)
        sub.operator("gpencil.palettecolor_add", icon='ZOOMIN', text="")
        sub.operator("gpencil.palettecolor_remove", icon='ZOOMOUT', text="")

        palcol = context.active_gpencil_palettecolor
        if palcol:
            sub.menu("GPENCIL_MT_palettecolor_specials", icon='DOWNARROW_HLT', text="")

        if len(palette.colors) > 1:
            col.separator()

            sub = col.column(align=True)
            sub.operator("gpencil.palettecolor_move", icon='TRIA_UP', text="").direction = 'UP'
            sub.operator("gpencil.palettecolor_move", icon='TRIA_DOWN', text="").direction = 'DOWN'

        pcolor = palette.colors.active
        if pcolor:
            self.draw_palettecolors(layout, pcolor)


def draw_palettecolors(self, layout, pcolor):
    split = layout.split(percentage=0.5)
    split.active = not pcolor.lock

    col = split.column(align=True)
    col.enabled = not pcolor.lock
    col.label(text="Stroke:")
    col.prop(pcolor, "color", text="")
    col.prop(pcolor, "alpha", slider=True)

    col = split.column(align=True)
    col.enabled = not pcolor.lock
    col.label(text="Fill:")
    col.prop(pcolor, "fill_color", text="")
    col.prop(pcolor, "fill_alpha", text="Opacity", slider=True)

    split = layout.split(percentage=0.5)
    split.active = not pcolor.lock

    col = split.column(align=True)
    col.active = not pcolor.lock
    col.prop(pcolor, "use_volumetric_strokes")
    col = split.column(align=True)
    col.active = not pcolor.lock
    col.prop(pcolor, "use_hq_fill")


def invoke(self, context, event):
    wm = context.window_manager
    return wm.invoke_popup(self, width=225, height=350)


def execute(self, context):
    return {'FINISHED'}

def check(self, context):
    return True

bpy.utils.register_class(DialogOperator)

test call

bpy.ops.object.dialog_operator('INVOKE_DEFAULT')

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.