userSetup Script

65 views
Skip to first unread message

Christopher.

unread,
Oct 4, 2015, 7:28:49 PM10/4/15
to Python Programming for Autodesk Maya
How do you add a script to the userSetup.py file.  Do you do it place after the - execfile('') ?

Then define it as such

def menuImport();
     
import <scriptName>





Justin Israel

unread,
Oct 4, 2015, 7:34:36 PM10/4/15
to python_in...@googlegroups.com
Which execfile() call are you referring to? userSetup.py is something that gets automatically run by Maya at startup. It is just a normal python script.
 

--
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/d229cd66-2267-46f1-b4e0-0c3a632f268f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher.

unread,
Oct 5, 2015, 12:51:06 AM10/5/15
to Python Programming for Autodesk Maya
The execfile() is located in my userSetup.py script, I was informed to put it there, another reason why I must learn Python soon, getting tired of the sloppy coding by some programmers, and when you don't know what is going on, you're led around by the nose. 

I want to add a script to automatically run when Maya starts ?


On Sunday, October 4, 2015 at 7:34:36 PM UTC-4, Justin Israel wrote:
On Mon, Oct 5, 2015 at 12:28 PM Christopher. <crestchr...@gmail.com> wrote:
How do you add a script to the userSetup.py file.  Do you do it place after the - execfile('') ?

Then define it as such

def menuImport();
     
import <scriptName>





Which execfile() call are you referring to? userSetup.py is something that gets automatically run by Maya at startup. It is just a normal python script.
 

--
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.

Arvid Schneider

unread,
Oct 5, 2015, 2:28:48 AM10/5/15
to python_in...@googlegroups.com
The userSetup.py is run each when maya is being started. You can have several userSetup.py files in your PYTHONPATH, but just one userSetup.mel. 

If you want to make the userSetup file clean you can call other .py files from within the userSetup using execfile(). 
But you can also run your code directly in it. 

I hope that gets you started,

Arvid Schneider
Look Develpopment | Lighting TD | Show TD
www.arvidschneider.com

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/a6c927bf-6638-4f6e-8a25-bae7b89773e8%40googlegroups.com.

Justin Israel

unread,
Oct 5, 2015, 2:38:56 AM10/5/15
to python_in...@googlegroups.com

Assuming your script that you want to run is in your PYTHONPATH, then you just import it and call whatever you want on that imported module (I.e a main() or some other function to run your action)
Using execfile is going to make an assumption about an absolute file location (which may or may not be ideal). Using the normal python import allows you to rely on the configured environment.


On Mon, 5 Oct 2015 7:28 PM Arvid Schneider <arvidsc...@gmail.com> wrote:
The userSetup.py is run each when maya is being started. You can have several userSetup.py files in your PYTHONPATH, but just one userSetup.mel. 

If you want to make the userSetup file clean you can call other .py files from within the userSetup using execfile(). 
But you can also run your code directly in it. 

I hope that gets you started,

Arvid Schneider
Look Develpopment | Lighting TD | Show TD
www.arvidschneider.com


On Oct 5, 2015, at 05:51, Christopher. <crestchr...@gmail.com> wrote:

The execfile() is located in my userSetup.py script, I was informed to put it there, another reason why I must learn Python soon, getting tired of the sloppy coding by some programmers, and when you don't know what is going on, you're led around by the nose. 

I want to add a script to automatically run when Maya starts ?

On Sunday, October 4, 2015 at 7:34:36 PM UTC-4, Justin Israel wrote:
On Mon, Oct 5, 2015 at 12:28 PM Christopher. <crestchr...@gmail.com> wrote:
How do you add a script to the userSetup.py file.  Do you do it place after the - execfile('') ?

Then define it as such

def menuImport();
     
import <scriptName>





Which execfile() call are you referring to? userSetup.py is something that gets automatically run by Maya at startup. It is just a normal python script.
 

--
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/d229cd66-2267-46f1-b4e0-0c3a632f268f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/a6c927bf-6638-4f6e-8a25-bae7b89773e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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.

haggi...@gmail.com

unread,
Oct 5, 2015, 6:26:04 AM10/5/15
to Python Programming for Autodesk Maya
I saw your function name: menuImport.
We had to realize that the userSetup.py is exectured before any UI elements are loaded what can lead to maya crashes during startup. To avoid these problems we used a evalDeferred() to execute UI scripts after maya is ready.

Crest Christopher

unread,
Oct 5, 2015, 2:45:23 PM10/5/15
to python_in...@googlegroups.com
I'm not exactly following probably due to my lack of Python knowledge; what must be done, will more in-depth code post be more helpful ?
Reply all
Reply to author
Forward
0 new messages