How to execute Maya python scripts in PyCharm

1.1k Views Asked by At

I'm writing some simple pipeline scripts for my company. I did lots of houdini work in pycham and it works as expected: When you work in houdini python interpreter it is like working in houdini without UI. BUT, with Maya I cant get anything working inside PyCharm, I have to execute everything in Maya using MayaCharm plug in. Completition works, imports work, but whatever I do, whatever function, methods, .. I call I'm always getting 'None' as results. Not errors, just 'None' as result. I tried solution from: How do I execute Maya script without lauching Maya? but it also don't work. Result of "my_cube = cmds.polyCube()" is "None". Even if I just call cmds.ls() I'm getting "None" Any help or ideas?

2

There are 2 best solutions below

2
On

If you launching your script with mayapy, you might wanna initialize maya first: https://help.autodesk.com/cloudhelp/2016/CHS/Maya-Tech-Docs/PyMel/standalone.html

import maya.standalone
maya.standalone.initialize(name='python')
import maya.cmds as cmds

If you trying to launch something from PyCharm right in the live Maya session, then MayaCharm is they way to go I believe.

0
On

If you want to execute in Maya but use Pycharm as an editor, you should probably just use MayaCharm, which is designed precisely for that purpose.