I hope this one wasn't ask before (can't find anything here though). With a script, I'd like to draw a panel ("My panel" for example) in the UI region but I just want the panel to appear for a designated object : for example the active object when I generate the panel/run the script. Is this possible ?


1 Answer 1


You would do this with the poll() method. It's a function within the operator class which returns true or false whether the operator can run within the given context. I can't remember for certain if the UI becomes visible/hidden or just active/inactive as a result... Could be either or.

The 'operator_mesh_uv.py' template has a pretty straightforward example for how it's used. It tests if the user is in edit mode, but it could just as well check if the active object is the correct one.

class UvOperator(bpy.types.Operator):
    """UV Operator description"""
        bl_idname = "uv.simple_operator"
        bl_label = "Simple UV Operator"

    def poll(cls, context):
        return (context.mode == 'EDIT_MESH')

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

You could store the active object in a variable when the operator is registered and poll against that. Or you could manually add a custom property to the designated object. That way the information is stored within the blend file across sessions.

    def poll(cls, context):
        return ("mycustomproperty" in context.object)

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.