diff --git a/MayaSublime.py b/MayaSublime.py index 2e9b735..6a2e535 100644 --- a/MayaSublime.py +++ b/MayaSublime.py @@ -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() ''') @@ -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 @@ -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') diff --git a/MayaSublime.sublime-settings b/MayaSublime.sublime-settings index 4181a21..1e0bbb2 100644 --- a/MayaSublime.sublime-settings +++ b/MayaSublime.sublime-settings @@ -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, } \ No newline at end of file