https://pastebin.com/V6aqyAy5 This little ditty is for assigning to a hotkey to toggle full/half/off for edge creasing. Seemed like a handy thing to have for quick one offs compared to a full-on crease set workflow or remembering to pre-convert a face selection for the crease tool.
It took me a bit to understand that I needed to source this little script, but I don't quite understand why it needs to be sourced. I was going up and down trying to figure out why it insta-crashed, thinking I was doing something noobishly wrong. Is there some rule of thumb or style I should follow for something relatively simple like this?
Replies
Just a guess.
EDIT: This doc explains it in more details.
@Klaudio2U I could do that too, I like to keep my hotkeys "clean" for portability or a quick recovery if my prefs ever die.
Not really a huge deal in this case, I'm just trying to understand so I can avoid something like this in the future. Also noob scripting + a long few days into an insomnia swing are probably a bad mix to begin with
On Maya startup and initialization, Maya will parse all scripts located in the environment variable script paths (located via default internal vars and supplemented in your Maya.env file if you ever wish to append it). As it parses through those files, it is essentially storing the global proc names within your script files as callable procedures. Local proc names don't get stored. So, when you make a call to tkCreaseToggle(), it finds it because it's a global proc, but when you call to the local proc tkPerformCrease(), Maya has no idea what you are talking about. That is why you must source the script.
My recommendation is to take a more Pythonic approach, and make the vast majority of your procs global so they can be accessed by any other proc at anytime you might need it. It's a more modular approach to programming. You'll find python code often times will have a lot of defs (equivalent to global procs) which it leverages as bite sized operations that can be used interchangeably.
I also agree with your assessment regarding copy/pasting direct code into a hotkey. It's messy and doesn't leave you in good shape for portability or future improvement. If you've written it as global procs, you can always reference that code later for other ventures, and you don't have to go digging for it in the shelf editor command UI.