I had made a project manager for maya in python with Qtdesingner,
in the UI, a QLineEdit authorize the user to fill a path of a script to run (the variable is: BatchRunScript
)
but it seems to not be possible to import a module if it's a variable (str
):
import maya.utils
BatchRunScript = 'X:\PathOfTheScript\NameOfScriptToRun.ScriptToRun()'
BatchRunScriptName = BatchRunScript.replace('\\', '/').split('/')[-1]
BatchRunScriptPath = BatchRunScript.replace('\\', '/').split(BatchRunScriptName)[0]
BatchRunModuleName = BatchRunScriptName.split('.')[0]
print 'BatchRunScriptPath: ', BatchRunScriptPath # X:/PathOfTheScript/
print 'BatchRunScriptName: ', BatchRunScriptName # NameOfScriptToRun.ScriptToRun()
print 'BatchRunModuleName: ', BatchRunModuleName # NameOfScriptToRun
sys.path.append(BatchRunScriptPath)
import BatchRunModuleName
maya.utils.executeDeferred(BatchRunScriptName)
It gives me this error:
Error: ImportError: file <maya console> line 13: No module named BatchRunModuleName
Is there another way to do run a python script from inside another?