Question

I'm afraid this will a question for a very particular case. At university we have been told to generate documentation by using pydoc. The problem is that we need to create it for a Maya script, and pydoc yells when it finds import maya.cmds as cmds

So, I tried to comment this line but I keep getting errors:

python C:\Python27\Lib\pydoc.py Script.py    
problem in Script - <type 'exceptions.NameError'>: global name 'cmds' is not defined

I also tried Script, without the extension .py but it's silly doing that, we still running around the same issue.

Does anybody know how to generate documentation for Maya scripts, where import maya only works in the maya interpreter?

Was it helpful?

Solution

maya.commands is an stub module until it's run inside a working maya environment; if you just import it and inspect it outside of Maya you'll see that it's basically a placeholder.

If you want to inspect the contents, you can import the maya.standalone module and initialize it before running other commands (in this case it means you won't be able to run pydoc standalone.

You can get the documentation using the write command:

 import maya.standalone
 maya.standalone.initialize()
 import pydoc
 import mymodule
 pydoc.write(mymodule) # writes the mymodule.html to current directory

Be warned, however, that the documentation for all maya built in functions will be unhelful:

 'built-in function ls'

however you can at least document your own stuff without the maya parts crashing.

Pydoc, ironically, does not have a lot of external documentation. However you can see the code here:http://hg.python.org/cpython/file/2.7/Lib/pydoc.py (i'm not sure about the delta between this and the 2.6 version for maya pre-2014 but it works as above in maya 2011)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top