Back to Overview

cmd Wrapper

Tools & Techart Topics

first things first the repo can be found here

This is simple wrapper for the Maya cmds module created together with Trevor van Hoof.

The idea is that it can replace the maya.cmds completely without being invasive, if its loaded you can use its benefits, if the benefits are not used it can easily be replaced with the original without any overhead. The idea is that this module will return smart objects instead of just strings.

originally you can create objects with cmds, connect them, do lots of things, but it is always passing string data from one module to the next:

from maya import cmds

loc = cmds.spaceLocator()[0]
sphere = cmds.polySphere()[0]
cmds.connectAttr("{0}.translate".format(loc), "{0}.translate".format(sphere))
trsValue = cmds.getAttr("{0}.translate".format(loc))

in these couple of lines of code you can see the extra hassle that is necessary just to make objects and simple connections. loc and sphere are both string objects. so they need to be formatted correctly for the next command to understand propperly.

the next snippet of code does the exact same:

from cmdWrapper import cmds

loc = cmds.spaceLocator()[0]
sphere = cmds.polySphere()[0]
loc.translate.connect(sphere.translate)
trsValue = loc.getT() #< specific command for transforms to get translation value (local or worlspace) 
print(type(trsValue))

In here the loc and sphere variables hold the wrapped data. but can be represented as a string. If you access the data necessary you can circomvent the need of string formatting. In this case we access the translate attribute directly. This attribute has a function to connect to other attributes, in this case to the attribute of sphere.

There is a lot more included, feel free to check it out!