Code Monkey home page Code Monkey logo

maya_mock_completion's Introduction

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!

maya_mock_completion's People

Contributors

mrbmp33 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.