When you typed:
import maya.cmds as cmds
cmds.Jedi only saw __doc__, __file__, __name__, __package__ because it wasn't actually importing maya.cmds - it was just seeing cmds as an abstract module object.
Now we actually execute the code before the cursor position:
# Execute all lines before the current line
exec(code_before, namespace)This means when you have:
import maya.cmds as cmds
cmds. # <- cursor hereWe execute import maya.cmds as cmds, so namespace['cmds'] becomes the real maya.cmds module with all 2000+ functions.
lines_before = context_lines[:line-1]
code_before = '\n'.join(lines_before)namespace = {}
exec(code_before, namespace)Now namespace contains all your imports and variables!
combined_namespace = {**__main__.__dict__, **namespace}This gives Jedi access to:
- Stuff you imported in the editor
- Stuff already in Maya's main namespace
interpreter = Interpreter(source, namespaces=[combined_namespace], project=project)Reload the editor and try:
import maya.cmds as cmds
cmds.polyYou should now see:
[Jedi] Executing 1 lines to build namespace...
[Jedi] Namespace has: ['cmds']
[Jedi] Using Interpreter mode with executed namespace
[Jedi] Jedi returned 150+ completions
[Jedi] - polyCube (type: function)
[Jedi] - polySphere (type: function)
[Jedi] - polyPlane (type: function)
[Jedi] - polyPipe (type: function)
[Jedi] - polyTorus (type: function)
[Jedi] Returned 150+ completions: ['polyCube', 'polySphere', ...]...
✅ Real imports - Executes your import statements
✅ Real objects - Jedi sees actual module contents
✅ Works with aliases - cmds, om, om2, etc.
✅ Works with from imports - from maya.cmds import polyCube
✅ Local variables - Variables you define work too
importstatements- Variable assignments
- Function definitions
- Class definitions
If execution fails (syntax error, runtime error), we catch it and continue with an empty namespace. Jedi falls back to static analysis.
Execution happens in an isolated namespace, not Maya's main namespace, so it won't affect your scene.
import maya.cmds as cmds
cmds. # Shows: polyCube, select, ls, etc.from maya import OpenMaya
OpenMaya. # Shows: MVector, MMatrix, MObject, etc.from maya.api import OpenMaya as om2
om2. # Shows: MVector, MFnMesh, MDagPath, etc.my_list = [1, 2, 3]
my_list. # Shows: append, extend, pop, etc.class MyClass:
def my_method(self):
pass
obj = MyClass()
obj. # Shows: my_method- Lines after the cursor
- Lines with side effects (creating geometry, etc.) - but they execute in isolation so it's safe
- Long-running operations (but you wouldn't put those in imports anyway)
If your code has errors before the cursor, execution fails and you get limited completions. But this is expected - you should fix the errors!
- First completion: Executes imports (~100ms for maya.cmds)
- Subsequent: Cached, fast
- Each new import: Executes that import
- Typing in same scope: Uses cached execution
Watch for:
[Jedi] Executing 3 lines to build namespace...
[Jedi] Namespace has: ['cmds', 'os', 'my_var']
This shows what's in the namespace after execution.
If you see:
[Jedi] Error executing code: <error message>
Then there's a syntax or runtime error in your code before the cursor.