please unsubscribe me by this group thnx
On Tue, Sep 18, 2012 at 8:57 PM, Justin Israel <[email protected]>wrote: > For the print statement, I believe the script editor is not yet connected > to stdout at the time you call print in userSetup.py > If, for instance, you check the Console app on OSX you will see those > print statements when you start Maya. If you were to print deferred until > the next idle moment, then you would see them in the Script Editor: > > import maya.utils > maya.utils.executeDeferred('print "FOO"') > > You are correct in your second question that it is a matter of scope. > Python modules each have their own scope. You must explicitly import other > modules to bring them into scope. They will only import once per app, as > subsequent imports will just lookup the name. > userSetup.py is not imported into Maya. It is executed into Maya's global > app namespace, which is the same namespace as the script editor. If you > include import statements in userSetup.py, they will be available from the > Script Editor. But your other scripts always need to import them. This is > more of a general python matter as opposed to being Maya-specific. > I add the import statements to my userSetup for convenience when > developing, so that I don't have to constantly import them to the script > editor each time. > > > > On Sep 18, 2012, at 1:59 AM, ben cowell-thomas wrote: > > Hello, > > A basic question that has me stumped. I'm using userSetup.py and I'm > confused about scope. I've probably overcomplicated a simple task .. but > I'm trying to understand how userSetup.py works so I've put part of my > setup into a module. > > userSetup.py contains the following: > > import maya.cmds as cmds > print "--- Executing C:\Users\ben.c\Documents\maya\scripts\userSetup.py > ---" > import eclipseConnection > eclipseConnection.startUpFunc() > > eclipseConnection.py contains: > > import maya.utils as utils > > def startUpFunc(): > print "--- Executing > C:\Users\ben.c\Documents\maya\scripts\eclipseConnection.py ---" > if cmds.commandPort(':7720', q=True) !=1: > cmds.commandPort(n=':7720', eo = False, nr = True) > > Firstly I don't ever see the result of the print commands on startup. Is > this normal ? > > Secondly and more importantly I find that when troubleshooting, if I > manually execute eclipseConnection.startUpFunc() after startup, Maya > reports: > > # Error: NameError: global name 'cmds' is not defined # > > Now I would expect cmds to work fine within eclipseConnection as if I type > 'cmds' manually I see: > > # Result: <module 'maya.cmds' from 'C:\Program > Files\Autodesk\Maya2011\Python\lib\site-packages\maya\cmds\__init__.py'> # > > > My questions are .. why don't I see the result of the print commands on > startup (even though I know userSetup.py is running as cmds exists), and > secondly why can't my module access maya.cmds even though I believe it be > defined globablly ? > > thank you > ben > > -- > view archives: http://groups.google.com/group/python_inside_maya > change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe > > > -- > view archives: http://groups.google.com/group/python_inside_maya > change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe > -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe
