I implement a rigging workflow such that I frequently reuse a bunch of common shapes. I keep them all in a specific directory (a folder called “assets” in the my documents maya folder).
I have a python function that I use to import those shapes and here it is!:
- #Function to import an object from a local folder
- #Author: Seth Meshko, 3danimationartist.com
- def importShape(nameOfFile):
- scriptsUserDirectory = cmds.internalVar(usd=True) #getting this version of maya scripts directory which is in the same directory as the assets folder
- pathToFile = '%s/%s' % (scriptsUserDirectory.rsplit('/', 3), 'assets/' + nameOfFile + '.mb')#regroving that path to go to the assets folder
- cmds.file(pathToFile, i = True, groupReference = True, groupName = 'loadedObjectGroup')#importing the shape
- #note: Nothing is returned in an import. If you want the objects you have to bundle them in a group first, then work with the group.
- importedObjectList= cmds.listRelatives('loadedObjectGroup', allDescendents = True, type = 'shape')#getting the childern of the import group
- importedObject = importedObjectList#getting the first object in the list of imported objects. If you had more than one then you would have to deal with this differently
- cmds.parent(importedObject, world = True)#unparenting the object from the group
- cmds.delete('loadedObjectGroup')#deleting the group
- return footControlShape#returning the imported object to the function that called it.
- importShape('nameOfFile')#this is just the name of the file in the directory, the path is specified in the method. Also, don't include file type eg. ".ma"