How to execute a Python Script through a Python script within Maya

35 views
Skip to first unread message

AMAL ARJUN

unread,
Jun 27, 2018, 1:18:42 AM6/27/18
to Python Programming for Autodesk Maya
Suppose I'm having a Python script in a folder (/Desktop/test.py) and I want to load that through Python. How can I do that.?

Panupat Chongstitwattana

unread,
Jun 27, 2018, 1:46:33 AM6/27/18
to Python Programming for Autodesk Maya
The path needs to be recognized by Maya, there's a few ways. The simplest is to add the path to sys.path.

If you have your script at C:/some/path/yourscript.py you would do

import sys
sys.path.append('C:/some/path')
import yourscript

I highly recommend you check out the Python videos in Justin's channel.

Justin Israel

unread,
Jun 27, 2018, 1:51:25 AM6/27/18
to python_in...@googlegroups.com


On Wed, Jun 27, 2018, 5:18 PM AMAL ARJUN <amala...@gmail.com> wrote:
Suppose I'm having a Python script in a folder (/Desktop/test.py) and I want to load that through Python. How can I do that.?


Your topic line says 'execute' and your question says 'load'. Can you clarify if you are trying to run test.py as an executable subprocess of your script in Maya, or if you want to import it as a module to make Python calls into it as a library? 

Justin 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/32bf2dba-82f3-4803-8da5-33bcfca22210%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

AMAL ARJUN

unread,
Jun 27, 2018, 1:53:28 AM6/27/18
to Python Programming for Autodesk Maya
Thanks all. Worked on this script

pythonscript ='Desktop/test.py'
execfile(pythonscript)


Thanks Justin and Panupat. :)

On Wednesday, June 27, 2018 at 11:21:25 AM UTC+5:30, Justin Israel wrote:


On Wed, Jun 27, 2018, 5:18 PM AMAL ARJUN <amala...@gmail.com> wrote:
Suppose I'm having a Python script in a folder (/Desktop/test.py) and I want to load that through Python. How can I do that.?


Your topic line says 'execute' and your question says 'load'. Can you clarify if you are trying to run test.py as an executable subprocess of your script in Maya, or if you want to import it as a module to make Python calls into it as a library? 

Justin 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages