Shapelib

This module holds utility methods for dealing with nurbscurves

exception MissingShapeFromLibrary

Bases: Exception

clearShapeCache()
iterShapeRootPaths()

Generator function which iterates the root location based on the environment variable “ZOO_LIB_PATH”

Returns

Each absolute path to each shape root directory.

Return type

generator(str)

iterShapePaths()

Iterator function which loops all the *.shape paths.

Returns

Generator with each element == absolute path.shape

Return type

generator(str)

iterAvailableShapesNames()

Generator function for looping over all available shape names

Shapes are sourced from all the set root locations specified by the “ZOO_LIB_PATH” environment variable

Returns

An Iterate which returns each shape Name

Return type

Generator(str)

shapeNames()

List all the curve shapes (design/patterns) available.

Shapes are sourced from all the set root locations specified by the “ZOO_LIB_PATH” environment variable

Return shapeNames

a list of curve designs (strings) available

Rtype shapeNames

list(str)

findShapePathByName(shapeName)

Find’s the absolute shape path based on the shape name

..code-block: python

shapePath = findShapePathByName(“cube”) # result: rootFolderzoolibsshapelib__init__.py

Parameters

shapeName (str) – The shape name to find. eg. “cube”

Returns

The absolute shape path

Return type

str

loadFromLib(shapeName)

Loads the data for the given shape Name

Parameters

shapeName (str) – The shape name from the library, excluding the extension, see shapeNames()

Returns

A 2 tuple the first element is the MObject of the parent and the second is a list of mobjects represents the shapes created.

Return type

tuple[om2.MObject, list(:class:`om2.MObject))

Raises

ValueError

loadAndCreateFromLib(shapeName, parent=None, mod=None)

Load’s and create’s the nurbscurve from the shapelib. If parent will shape node parent to the given object

TODO: should combine zoo_preferences and zoo internal directories

Parameters
  • shapeName (str) – the shape library name.

  • parent (maya.api.OpenMaya.MObject) – the parent for the nurbscurve default is None.

Returns

A 2 tuple the first element is the MObject of the parent and the second is a list of mobjects represents the shapes created

Return type

tuple(MObject, list(MObject))

loadShape(shapeName, folderPath)

Loads the shape with the provided shapeName and folderPath.

Note

This doesn’t update the mem-cache.

Parameters
  • shapeName (str) – The name of the shape ie. “circle”

  • folderPath (str) – The fully qualified folder path.

Returns

The raw shape data.

Return type

dict

loadAndCreateFromPath(shapeName, folderPath, parent=None)

Load’s and creates the nurbs curve from the design name and specific folder path. If parent will shape node parent to the given object

TODO: should combine zoo_preferences and zoo internal directories

Parameters
  • shapeName (str) – The shape name.

  • folderPath (str) – The folder path of the .shape file

  • parent (maya.api.OpenMaya.MObject) – the parent for the nurbs curve default is None.

Returns

A 2 tuple the first element is the MObject of the parent and the second is a list of mobjects represents the shapes created

Return type

tuple(MObject, list(MObject))

saveToLib(node, name, override=True, saveMatrix=False)

Save’s the current transform node shapes to the zoo library Uses the default first SHAPE_LIB_ENV location as the directory:

Parameters
  • node (MObject) – The MObject to the transform that you want to save

  • name (str) – The name of the file to create, if not specified the node name will be used, usually the design name

  • override (bool) – Whether to force override the library shape file if it exists.

  • saveMatrix (bool) – If True save the matrix information. On import can override matching, usually matrix not wanted.

Returns

The file path to the newly created shape file

Return type

str

saveToDirectory(node, name, directory, override=True, saveMatrix=False)

Saves the current transform node shapes to a directory path

Parameters
  • node (MObject) – The MObject to the transform that you want to save

  • name (str) – The name of the file to create, if not specified the node name will be used, usually the design name

  • directory (str) – The directory folder to save into

  • saveMatrix (bool) – If True save the matrix information. On import can override matching, usually matrix not wanted.

Returns

The file path to the newly created shape file

Return type

str

nurbsCurve = cmds.circle()[0]
# requires an MObject of the shape node
data, path = saveToDirectory(api.asMObject(nurbsCurve))
deleteShapeFromLib(shapeName, message=True)

Deletes a shape from the internal zoo library. Deletes the file on disk.

TODO: replace maya displayMessages with logging and create a maya log handler

Parameters
  • shapeName (str) – The name of the shape without the extension. Eg “circle” deletes “path/circle.shape”

  • message (bool) – Report the message to the user?

Return fileDeleted

If the file was deleted return True

Rtype fileDeleted

bool

renameLibraryShape(shapeName, newName, message=True)

Renames a shape from the internal zoo library. Renames the file on disk.

TODO: replace messages with a maya log handler

Parameters
  • shapeName (str) – The name of the shape without the extension. Eg “circle” deletes “path/circle.shape”

  • newName (str) – The new name of the shape. Should not have the file extension. eg. “star_05”

  • message (bool) – Report the message to the user?

Return newPath

the full path of the file now renamed. Empty string if could not be renamed

Rtype newPath

str