Hello there,
I am trying to run the userScript.py file placed in Documents\maya\2020\prefs\scripts , but there are functions and variables which are not declared when Maya is open…
I basically did it:
Sometimes it runs, and sometimes do not.
The userScript.mel runs always, so I think I could put at the end of the mel code, a line to call the python code.
Any suggestion? thanks!
I’m bad with python but shouldn’t you have to initialize it first as it’s being called as a startup script or perhaps set it to wait till Maya has loaded all the way? I’m not sure at all, just a suggestion and or query.
Jason
--
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/b3b1bf17-c520-4ef0-b7cd-d26afe63220cn%40googlegroups.com.
Try this.
from maya import cmds
def functionA():
varA = False
def delayMe():
cmds.scriptJob(event = ["SceneOpened", functionA])
cmds.evalDeferred(delayMe)
By “evaling” something “deferred” you delay having something called until Maya is loaded up, UI and all. Also don’t forget to actually import maya.cmds
as cmds
won’t be available until someone does. So odds are there were other scripts also called on startup that at some point imported it ahead of your userSetup.py
, which would explain why it worked those times. Which is also the reason why - for the diligent - you should either rename that import, or import within a function so the name doesn’t spill over into other scripts.
def functionA():
varA = False
def delayMe():
cmds.scriptJob(event = ["SceneOpened", functionA])
def setup():
from maya import cmds
cmds.evalDeferred(delayMe)
setup()
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/002c01d793de%249210b430%24b6321c90%24%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCzBQWSaJkZLFWmsAhNpg2tSeo9PhUJ-aOCrEuzovfQJw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCzBQWSaJkZLFWmsAhNpg2tSeo9PhUJ-aOCrEuzovfQJw%40mail.gmail.com.
What are you trying to accomplish?
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJZGTKWUxktR6P6zW_nGjZxTZ%3D-zGcPJ4tV2C7RvCwkDrFcZRw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/001c01d79458%24b18f4b30%2414ade190%24%40gmail.com.
I was simply suggesting what Marcus laid out properly that you need to invoke python earlier
e.g. import maya.cmds as cmds
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJZGTKU6Li0njJMHCEUPbfPq4xXGn%2BohgUihnQJpTb27ChNZ4A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/000401d79540%2490708de0%24b151a9a0%24%40gmail.com.