0
$\begingroup$

How do I reference the bl_label inside operators? I want to know the name of the operator based on the bl_label to be precise.

$\endgroup$
  • $\begingroup$ Hi. I hope you don't mind my edit. If you meant something else please edit the question and correct it. $\endgroup$ – Martin Z Jan 3 at 8:37
  • $\begingroup$ @MartinZ it is a slippery slope to answer, and then edit question based on answer. Recommend asking, via comments, for clarification first. $\endgroup$ – batFINGER Jan 3 at 8:45
  • $\begingroup$ It wasn't formed clearly. I believe this was the intended question and encouraged yarun can to correct me if I am wrong. You might be right though. I will try to keep this in mind. $\endgroup$ – Martin Z Jan 3 at 8:55
1
$\begingroup$

You define bl_label inside the operator's code as a variable so after that you can reference it as any other variable inside the operator. It would be self.bl_label:

import bpy

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

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

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

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

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

if __name__ == "__main__": 
    register()

    # test call
    bpy.ops.object.simple_operator()
$\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.