How to make a panel show up when a rig or duplicate of rig is selected

I want to script a rig and I want to make a panel for it. Is there a way for this panel to only show up when this rig or duplicates of this rig are selected?

Thanks in advance

Yes! The best resource you have is the rigify rig. Generate the rigify rig and look at the rig_ui.py file it creates.

Look at the section below…
###################

Rig UI Panels

###################

And look at how it appends the armatures rig_id custom property to the id names of the panel classes and tests for the the rig_id in the @classmethod poll.

I’m assuming rig is == armature? Not sure if this is what you trying to do ,but you could try this sample code.

import bpy


class MyArmaturePanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "My Armature Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        act_obj = bpy.context.active_object


        #If object selected type is == armature and the name is correct, display panel
        if act_obj.type == 'ARMATURE' and act_obj.name.startswith('My_Armature_Name'):
            row = layout.row()
            row.label(text="Hello, My Armature is Selected!", icon='ARMATURE_DATA')

            row = layout.row()
            row.label(text="Active object is: " + act_obj.name)
            row = layout.row()
            row.prop(act_obj, "name")



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


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


if __name__ == "__main__":
    register()