Skip to content

Modification of maya 2022 completion that allows you to use proxy objects to mock maya's instructions to run your code outside of maya.

License

Notifications You must be signed in to change notification settings

mrbmp33/maya_mock_completion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MAYA MOCK COMPLETION

This project is a custom modification of Maya's commands/api stub libraries that allows you to execute python code that uses these libraries from a regular python interpreter, ideally the one from your venv.

Developing code for Maya can be a bit sluggish since it normally takes the following steps:

  • Opening Maya (maybe multiple times).
  • Setting up a way to send the code from your IDE to Maya.
  • Setting up the command completion to get Maya's libraries on your IDE.
  • Once code is sent, you need to refresh it to apply the changes unless you want to restart the app.

Also, if you are building your own packages you might have other dependencies that you might not want to install to your mayapy interpreter. Because of this you might have a separate virtual environment that contains these, but you cannot use a mayapy as a base interpreter for creating venvs.

What this package allows you is to separate your code from Maya to a certain degree. By installing this "mock" completion you can use Maya's libraries using a regular python interpreter.

This is different from using the application in standalone mode since you won't be initializing any maya at all.

Important: The code will run since it will find Maya's modules (cmds, pymel, api...), and they won't throw any errors due to Maya not being open. However, please notice that the objects generated by the api only return proxy objects and commands don't do anything real. They just "pass" or return other proxy objects.

The utility from this is that you can play with these proxy objects and commands in a way that mimics Maya's behavior. Then, when you want you can execute that same code inside Maya and it should behave the same way but providing a meaningful output.

This can also be useful for quick UI development, making unittests and running them from your IDE of choice or making your code just more abstract overall by removing the necessity to run the code inside Maya.

How to use

You can do one of the following:

  • Install this package via pip once it is available on pypi and just import the modules on your code as normal.
  • Save this package in your directory of choice and add the path to it to your interpreter's list of paths manually.

Then you should be able to run the code using the normal python interpreter.

# Imports won't crash
import maya.cmds as mc
import maya.api.OpenMaya as om

mc.polyCube()  # Should provide flags suggestions with correct typing inference, but it won't do anything

m_obj = om.MGlobal.getActiveSelectionList()  # Returns proxy object that doesn't do anything either but has the same methods as the real object

Disclaimers

  • PySide2's completion hasn't been added in case you might want to run UI code using the real library. If this is not what you want you can use the same principle to run the code in the same way.

  • This project is just a concept of a workflow. It might have its shortcomings, and it hasn't been tested in a real production, so I am not entirely sure how useful or reliable it actually is.

  • This is still being updated as not all methods of the API mock completion return proxy objects. That is to say these will get updated as they are required.

Cheers and have fun!

About

Modification of maya 2022 completion that allows you to use proxy objects to mock maya's instructions to run your code outside of maya.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages