Defer command line in python maya 2.7

I am a 3D animator.
Currently I want to create a script python 2.7 for maya as follows:
-Select any object.
-Create 2 locators at that object location.
-Switch to move tool /rotate tool of each locator.
-When there are no more 2 locators selected, perform an aim constraint with the second locator, World up object.

I’m stuck at the last step, not knowing how to make the script run when I no longer have 2 locators selected.

Sorry if it causes confusion, English is not my specialized language. tks u

I don’t think you can make it into a single script. You should think of a script as a command that gets executed from start to finish and you can’t do anything while it’s getting processed. There’s a thing called ScriptJob, it’s basically a way to trigger scripts when certain things happen in Maya. There’s a trigger for “selection changed”. So it would be a separate script tracking when nothing is selected and firing.

However how do you expect to move and rotate 2 locators while keeping both or one of them selected? It can be tricky, there’s a high chance you’ll end up deselecting both while doing it, and triggering the second part of the script.

So realistically I think there’s only one option - make it 2 scripts. Run the first script to create 2 locators. Then reposition them. Then run the second script to perform the aim constraint.

1 Like

hmm, seems like two scripts are required. Thank you for your answer.

Anyway, I still hope to be able to combine the scripts together, for convenience