# How to access the operator instance members?

I'm testing Blender's scripting, with this simple operator from the documentation:

def main(context):
print("OPNAME"+":", len(context.scene.objects), "object(s) in the scene")
print(*[obj.name for obj in context.scene.objects])

class SimpleOperator(bpy.types.Operator):
def execute(self, context):
main(context)
return {'FINISHED'}


In the first print instruction, I'd like to replace "OPNAME" by the name of the operator (supposedly bpy.types.Operator.bl_label). However main is not an operator's class method, so I can't access the variable directly.

When execute is called by Blender, what's the executing context? how can I access the operator instance (excluding passing the value to main)?

• How about SimpleOperator.bl_label or pass the operator (self) to main, or make main an operator method. Note: the method main is only used by way of example is not mandatory. Could also look at context.active_operator. – batFINGER Aug 7 '18 at 16:53
• @batFINGER: SimpleOperator.bl_label will work if main is only called by this operator. context.active_operator is None. – mins Aug 7 '18 at 17:07
• Yes am aware of both counts. Needs to be a registered and invoked operator for context.active_operator. As mentioned would simply pass self to get the instance. ie def main(op, context): and call via main(self, context) – batFINGER Aug 7 '18 at 17:10
• @batFINGER: I agree the example with a standalone method not receiving a reference to the operator is not a good choice, it makes sense to have everything in execute or use a parameter. I'll keep this question just for learning purposes. – mins Aug 7 '18 at 17:16
• Disagree re choice. Can either call main from the operator. or import the main method from the module to use elsewhere. Listing the context objects is a pretty simplistic example... but that's the idea. – batFINGER Aug 7 '18 at 17:21