justinfx / MayaSublime

Send selected Python and MEL code snippets from SublimeText to Maya via commandPort
MIT License
149 stars 38 forks source link

Passing on __file__ with execfile() and some ignores #12

Closed fredrikaverpil closed 11 years ago

fredrikaverpil commented 11 years ago

It would be awesome if you wanted to pull these amendments to your code.

Cheers!

justinfx commented 11 years ago

There is a problem with this change. I am not exactly sure if it's really a "problem" but rather that it changes the previous behavior of the plugin...

Before this change, when you make changes to variables, they are being made in the main of Maya. That is, if you send foo = 'bar', then Maya's main retains that variable and value.

With this change applied, because you are making a copy of the __dict__ and passing that to exec, while it works fine for you to send your custom __file__ value, it is now using a temporary environment. I would be hesitant to introduce a patch that suddenly changes this behavior on those users that may be expecting their code to be able to modify the Maya python environment. It might be a feature that would have to be introduced with a configuration option to enable it, or providing alternative command mappings?

fredrikaverpil commented 11 years ago

I think an option to enable it would be good. Or any other way that you see fit to make __file__ callable from the script.

justinfx commented 11 years ago

I cherry picked some of the code and used a modified version of yours for passing the file It seems like a good balance by not modifying the main namespace of Maya, while still providing a persistant namespace for each successful sending of code from Sublime to Maya.

fredrikaverpil commented 11 years ago

That's great news. I no longer need to fork this project :) Update: I just tested the feature out and it works perfectly!