// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // // // // // // callPython (string $module, string $function, string $args[]) // // // void // // // Call a python function from MEL with string arguments. // Does not return a value. Use the python() function if you want // to evaluate an expression. // // // string $module Python module // string $function function name // string $args[] list of string arguments to pass // // // callPython "sys" "stderr.write" {"hello\n"} // global proc callPython (string $module, string $function, string $args[]) { string $cmd = ""; if ("" != $module) { $cmd = ("import " + $module + " as __mod\ntry:\n\t__mod."); } $cmd = ($cmd + $function + "("); int $i; int $n = size($args); for($i = 0; $i < $n; $i++) { string $encodedArg = `encodeString $args[$i]`; $cmd = ($cmd + "\"" + $encodedArg + "\""); if (($i + 1) < $n) { $cmd = ($cmd + ","); } } $cmd = ($cmd + ")\n"); if ("" != $module) { $cmd = ($cmd + "finally:\n\tdel __mod\n"); } // do it python($cmd); }