mgear.core.utils module

Utility functions

mgear.core.utils.as_pynode(obj)

Check and convert a given string to Pynode

If the object is not str or unicode or PyNode will raise type error

Parameters:

obj (str, unicode, PyNode) – Object to check and/or convert to PyNode

Returns:

the pynode object

Return type:

PyNode

mgear.core.utils.ensure_pynode(func)

Decorator to convert string args to PyNodes for Maya dag nodes.

Parameters:

func (callable) – Function that accepts Maya node args.

Returns:

Wrapped function where string args become PyNodes.

Return type:

callable

mgear.core.utils.filter_nurbs_curve_selection(func)
mgear.core.utils.gatherCustomModuleDirectories(envvarkey, defaultModulePath, component=False)

returns component directory

Parameters:
  • envvarkey – The environment variable key name, that is searched

  • defaultModulePath – The default module path for search in.

Returns:

[]string}

Return type:

Dict{string

mgear.core.utils.getModuleBasePath(directories, moduleName)

search component path

mgear.core.utils.get_dag_path(name)

Gets the dag path for the specified object name.

Parameters:

name (str) – Name of the object in the Maya Scene.

Returns:

The dag path to the specified name, else None.

Return type:

OpenMaya.MDagPath

mgear.core.utils.get_frame_rate()

Returns the current scene’s fps.

Returns:

The fps for the current scene’s timeline.

Return type:

int

mgear.core.utils.get_maya_path()

Gets the path to the folder where Maya binary lives

Note: Only works from inside Maya, as Maya adds the path on startup.

Returns:

Absolute path to the binary folder that contains maya executable

Return type:

str

mgear.core.utils.get_os()

Gets the OS that Maya is running in.

Returns:

Current OS

Return type:

str

mgear.core.utils.get_user_metadata()

Get current user metadata.

Returns:

Username, date, Maya version, and mGear version.

Return type:

dict

mgear.core.utils.importFromStandardOrCustomDirectories(directories, defaultFormatter, customFormatter, moduleName)

Return imported module

Parameters:
  • directories – the directories for search in. this is got by gatherCustomModuleDirectories

  • defaultFormatter – this represents module structure for default module. for example “mgear.core.shifter.component.{}”

  • customFormatter – this represents module structure for custom module. for example “{0}.{1}”

Returns:

imported module

Return type:

module

mgear.core.utils.is_odd(num)

Check if the number is odd.

Arguments: num (int): the number

Returns:

True or False

Return type:

bool

mgear.core.utils.one_undo(func)

Decorator - guarantee close chunk.

type: (function) -> function

mgear.core.utils.reveal_in_file_browser(path)

Open the OS file browser with the given path selected.

Falls back to opening the containing folder when the exact path can not be selected (or does not exist). Works on Windows, macOS and Linux.

Parameters:

path (str) – File or folder path to reveal.

Returns:

True if a file browser was launched, False otherwise.

Return type:

bool

mgear.core.utils.set_frame_rate(fps)

Set Maya Scene’s frame rate(fps).

Parameters:

fps (int) – frames per a second for playback.

mgear.core.utils.timeFunc(func)

Use as a property to time any desired function

mgear.core.utils.undo_off(func)

Decorator - Turn off Maya undo while func is running.

Disables the undo queue before executing the wrapped function and re-enables it afterwards. If the function fails, undo is still safely restored before the exception is raised.

type: (function) -> function

mgear.core.utils.viewport_off(func)

Decorator - Turn off Maya display while func is running.

if func will fail, the error will be raised after.

type: (function) -> function