How to make an operator execute twice

Hi! For a script I need that when the user calls an operator by pressing its button, it is executed twice. I need it is executed again once the return{‘FINISHED’} instruction is executed. How do I obtain this?
Is it possible?

Thanks!

It is also good if you can tell me how to execute a different operator after the first finished. Thanks.

Have a look at Macros:

I tried to call the operator twice using an counter variable but it did not work. It looks like when the operator is executed the whole module (where it is written) is reset.

So the solution is to use a wrapped function to be called n times while the operator runs only once.


import bpy


exec_counter = 0
exec_counter_max = 2


def operator_execute_function(context):
	global exec_counter
	global exec_counter_max


	# Increase the counter
	exec_counter += 1
	print("Code executed %i times." % exec_counter)


	# Run the counter again if allowed
	if exec_counter < exec_counter_max:
		operator_execute_function(context)
	else:
		print("Code finished execution.")


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


	def execute(self, context):
		# Reset the counter at the very first time
		global exec_counter
		exec_counter = 0


		# And now perform nested execution with a helper function		
		operator_execute_function(context)


		return {"FINISHED"}


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


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


try:
	unregister()
except:
	pass


register()

P.S. Now I got an idea, an operator that will run another operator twice. I need to test it though, I don’t know if it works. The real question is if it is really important to call the operator twice.

Thanks for all your suggestions! I solved the problem in a different way, so I don’t need this no more. But thankyou anyway!