Skip to content

Commit

Permalink
Add "no_collisions" setting to toggle namespacing Python code (#25)
Browse files Browse the repository at this point in the history
* Use named args in PY_CMD_TEMPLATE.

* Add "no_collisions" setting to toggle namespacing of the Python code in Maya.
  • Loading branch information
darkvertex authored and justinfx committed Jun 14, 2016
1 parent 8fb5ac4 commit 011a818
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 9 additions & 4 deletions MayaSublime.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ class send_to_mayaCommand(sublime_plugin.TextCommand):
namespace = __main__.__dict__.copy()
__main__.__dict__['_sublime_SendToMaya_plugin'] = namespace
namespace['__file__'] = {2!r}
try:
{0}({1!r}, namespace, namespace)
if {ns}:
namespace['__file__'] = {fp!r}
{xtype}({cmd!r}, namespace, namespace)
else:
{xtype}({cmd!r})
except:
traceback.print_exc()
''')
Expand Down Expand Up @@ -146,7 +148,9 @@ def run(self, edit):
if lang == 'python':
# We need to wrap our source string into a template
# so that it gets executed properly on the Maya side
mCmd = self.PY_CMD_TEMPLATE.format(execType, mCmd, file_path)
no_collide = _settings['no_collisions']
opts = dict(xtype=execType, cmd=mCmd, fp=file_path, ns=no_collide)
mCmd = self.PY_CMD_TEMPLATE.format(**opts)

c = None

Expand Down Expand Up @@ -182,6 +186,7 @@ def sync_settings():
_settings['py_port'] = so.get('python_command_port')
_settings['mel_port'] = so.get('mel_command_port')
_settings['strip_comments'] = so.get('strip_sending_comments')
_settings['no_collisions'] = so.get('no_collisions')



Expand Down
9 changes: 8 additions & 1 deletion MayaSublime.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@
//
// When sending whole files (nothing selected),
// comments are never stripped.
"strip_sending_comments": true
"strip_sending_comments": true,

// This wraps Python code in its own namespace
// to avoid collisions with the main Maya
// environment. (It is safer but if you are
// mixing this plugin with code from the
// Script Editor, set this to false.)
"no_collisions": true,
}

0 comments on commit 011a818

Please sign in to comment.