Skip to content

utility


=== Author: Assaf Ben Zur ===

Global Core MNS utility module.

This module holds any 'global' function used within MNS.

A 'misc' style module.


Defenitions


addAttrToObj

A global conditioned wrapper for adding attributes to object/objects


Exceptions:

  1. Object to add attr to was found non-existing or invalid. Abort.

  2. The 'replace' flag wasn't set, and the attribute already exists. Abort.

  3. Attr name wasn't passed in. Abort.

  4. The attribute type passed doesn't match the attribute value passed. Abort.

  5. min/max values were passed in, although the attr type is not an Int or a Float. Skip min/max values.

  6. min/max values were passed, and the attr type is Int or Float, although the min/max values passed arn't matching the data type. Skip min/max.

  7. The replace flag was set to True, but the attribute doesn't exist. Ignore replace flag.



Constructor: addAttrToObj(objects = [], **kwargs)
Return: list (added attributes 'attr' objects list)
Arguments:
  • objects(list) ; [default: []]
  • **kwargs
Keyword Arguments:
  • name(str) - Added attribute name
  • replace(bool) - If attr exists and this flag is set to True- delete the existing attribute then recreate according to parameters
  • type(str) ; [default: string] - Added attribute type
  • value(str) ; [default: None] - Added attribute value
  • max(str) ; [default: None] - Added attribute max (only if float or int)
  • min(str) ; [default: None] - Added attribute min (only if float or int)
  • locked(bool) - Added attribute lock state
  • cb(bool) ; [default: True] - Added attribute channelBox/Displayed state
  • keyable(bool) ; [default: True] - Added attribute keyable state
  • enumDefault(int) - If added attr is enum, set its default to this value


addBlockClasIDToObj

Add a 'blkClassId' Attribute to the given input.


Constructor: addBlockClasIDToObj(objectA, **kwargs)
Return: PyAttribute ('blkClassID')
Arguments:
  • objectA
  • **kwargs
Keyword Arguments:


applyChennelControlAttributesToTransform

This method applies a 'channelControl' dict attributes into the given transform.


Constructor: applyChennelControlAttributesToTransform(transform = None, ccDict = {})
Return: None
Arguments:
  • transform(str) ; [default: None]
  • ccDict(dict) ; [default: {}]
Keyword Arguments:


autoLoadMnsPlugins

Constructor: autoLoadMnsPlugins()
Return: None
Arguments:
Keyword Arguments:


checkForInternetConnection

check for a valid internet connection.


Constructor: checkForInternetConnection(host="8.8.8.8", port=53, timeout=3)
Return: bool
Arguments:
  • host(str) ; [default: "8.8.8.8"]
  • port(int) ; [default: 53]
  • timeout(int) ; [default: 3]
Keyword Arguments:


checkForVersionUpdates

This method will compare the current mns version against the latest available.

Return False if the current version is the latest version

Return True if the current version isn't the latest version


Constructor: checkForVersionUpdates()
Return: bool (isNewVesrionAvailable)
Arguments:
Keyword Arguments:


checkFunctionRedundencyForPackage

Constructor: checkFunctionRedundencyForPackage(package, printRedundentOnly = True)
Return: None
Arguments:
  • package
  • printRedundentOnly(bool) ; [default: True]
Keyword Arguments:


checkIfObjExistsAndSet

For the object passed in-

three main cases:

  1. If it is a 'PyNode' object, set it as the object to check.

  2. If it is an MnsNameStd object,set it's .node property as the object to check.

  3. If it is a string, assign it into a 'PyNode' obhect and set it as the object to check.

Check whether the object exists in the current scene and valid.

If so, return it. Else return None.


Constructor: checkIfObjExistsAndSet(objB = None, **kwargs)
Return: PyNode if valid, None if not.
Arguments:
  • objB(str) ; [default: None]
  • **kwargs
Keyword Arguments:
  • obj(str) ; [default: objB] - object to act on and return
  • namespace(str)


checkLocalAxisPairing

This method will check and return local axis pairing.

Main use is for pre-connection check for pocNode and curveVarNode tweakers (inputs),

in order to link local axes correctly, avoiding the need to check aim and up axes, as well as the offset axes.


Constructor: checkLocalAxisPairing(origin = None, target = None)
Return: dict (pairingDict - {"x", "y","z"})
Arguments:
  • origin(str) ; [default: None]
  • target(str) ; [default: None]
Keyword Arguments:


connectShapeColorRGB

Constructor: connectShapeColorRGB(source = None, target = None)
Return: None
Arguments:
  • source(str) ; [default: None]
  • target(str) ; [default: None]
Keyword Arguments:


convertAlphaToInt

Recursive. Convert an Alpha input into an Int ID. Infinite.


Constructor: convertAlphaToInt(alpha = "A")
Return: int
Arguments:
  • alpha(str) ; [default: "A"]
Keyword Arguments:


convertIntToAlpha

Recursive. Convert an Int input into an Alpha ID. Infinite.


Constructor: convertIntToAlpha(intA = 0)
Return: string
Arguments:
  • intA(int) ; [default: 0]
Keyword Arguments:


convertNodeToNameStd

Attempt to convert a given node into a MnsNameStd object.


Constructor: convertNodeToNameStd(node)
Return: None
Arguments:
  • node
Keyword Arguments:


createAxisLamberts

An axes colored lambert shaders creation function.


Constructor: createAxisLamberts(**kwargs)
Return: dict ('X': xAxisLambert, 'Y': yAixsLambert, 'Z': zAxisLambert)
Arguments:
  • **kwargs
Keyword Arguments:
  • doX(bool) ; [default: True]
  • doY(bool) ; [default: True]
  • doZ(bool) ; [default: True]
  • deleteAll(bool) - If true, do not attempt to create any objects- instead look for any existing objects and delete them


createFreeOffsetGroup

For the given transform, create a free offset group transform parent.


Constructor: createFreeOffsetGroup(transformObject)
Return: MnsNameStd (offsetGrp)
Arguments:
  • transformObject
Keyword Arguments:


createMnsDefaultPrefs

This method is called whenever a pref read is being called.

In case this method fails to locate local prefs for the current user, it creates it from the defualt prefs file.

Also, this method contains the "restore" flag, which will create a new prefs local file from the default file regardless of any other choice.

This is used as a "restore factory defaults" option.


Constructor: createMnsDefaultPrefs(**kwargs)
Return: string (prefs file path)
Arguments:
  • **kwargs
Keyword Arguments:


createNodeReturnNameStd

A core major MNS function.

This function creates a new node, based on it's type passed in, and it's name parameters passed in, and returns it as a MnsNameStd object.

This function also contains the 'search for next valid name' functionallity:

In case the given parameter set returns an object name that already exists within the current scene a 'Handle' functionallity will be triggered:

  • In case the 'IncrementAlpha' argument is Flase, recursivly increment the ID value until a new name slot is available within the scene.

  • In case it's Flase, do the same while incrementing the Alpha value instead.

Unlike Maya's core behavior- This function tests whether an object name exists whithin the entire scene- not only whether it exists whithin the current hirarchy level.

In a sequence manner creation- the Alpha/ID should be incremented within the caller function loop- meaning while bulding an item sequence the 'search' functionallity should not be used.

Another funtionallity of this function is the 'Fix Shape Name' functionallity:

A simple shpe children name test of an object (after creation) and a renaming them.


Constructor: createNodeReturnNameStd(**kwargs)
Return: MnsNameStd
Arguments:
  • **kwargs
Keyword Arguments:
  • side(str) ; [default: center] - side flag
  • body(str) ; [default: pointsOnCurve] - Node's name body.
  • alpha(str) ; [default: A] - Node's Alpha id
  • id(int) ; [default: 1] - Node's ID
  • incrementAlpha(bool) - Search new node name incrementing Alpha instead of the id if True
  • buildType(int)
  • createBlkClassID(bool)
  • createBlkCtrlTypeID(bool)
  • blkCtrlTypeID(int)
  • parentNode(str) ; [default: None]
  • segmentScaleCompensate(bool)


createOffsetGroup

For the given transform, create a predefined offset group transform parent.


Constructor: createOffsetGroup(transformObject, **kwargs)
Return: MnsNameStd (offsetGrp)
Arguments:
  • transformObject
  • **kwargs
Keyword Arguments:
  • type(str) ; [default: offsetGrp]
  • bodySuffix(str)


deleteFile

A delete file global function that includes a pre-defined log write.


Constructor: deleteFile(file)
Return: None
Arguments:
  • file
Keyword Arguments:


deleteUnusedShapeNodes

Constructor: deleteUnusedShapeNodes(obj = None)
Return: None
Arguments:
  • obj(str) ; [default: None]
Keyword Arguments:


distBetween

Measure the distance between to maya transforms.


Constructor: distBetween(transformA = None, transformB = None)
Return: float (distance)
Arguments:
  • transformA(str) ; [default: None]
  • transformB(str) ; [default: None]
Keyword Arguments:


duplicateNameStd

Simple method to duplicate a node embedded within a NameStd object.

This method will duuplicate the node, and rename it by the nameStd rules.


Constructor: duplicateNameStd(nameStd = None, **kwargs)
Return: None
Arguments:
  • nameStd(str) ; [default: None]
  • **kwargs
Keyword Arguments:


extractHeaderFromPath

Constructor: extractHeaderFromPath(fullPath)
Return: None
Arguments:
  • fullPath
Keyword Arguments:


findAndReplaceInFile

This is a simple method to replace the pattern given with a substitute string within a file,

Then overriting the original file with new lines.


Constructor: findAndReplaceInFile(file_path, pattern, subst)
Return: None
Arguments:
  • file_path
  • pattern
  • subst
Keyword Arguments:


fixShapesName

Simple shape name fix function based on parent's name.


Constructor: fixShapesName(objects = [])
Return: None
Arguments:
  • objects(list) ; [default: []]
Keyword Arguments:


getCurrentVersion

Get the current mansur product version based on this file directory


Constructor: getCurrentVersion()
Return: string (version)
Arguments:
Keyword Arguments:


getFirstLevelParentForObject

Get the top level parent for a given object.


Constructor: getFirstLevelParentForObject(obj)
Return: pyNode (top level parent)
Arguments:
  • obj
Keyword Arguments:


getMObjectFromNode

Constructor: getMObjectFromNode(node)
Return: None
Arguments:
  • node
Keyword Arguments:


getMObjectFromObjName

Constructor: getMObjectFromObjName(name)
Return: None
Arguments:
  • name
Keyword Arguments:


getMansurPrefs

This method retrives the prefs static dict from globals


Constructor: getMansurPrefs()
Return: dict (prefrences)
Arguments:
Keyword Arguments:


getMansurPrefsDefaults

Constructor: getMansurPrefsDefaults(**kwargs)
Return: None
Arguments:
  • **kwargs
Keyword Arguments:


getMansurPrefsFromFile

This method retrives all of the current prefrences.

In case the 'returnFileDirectory' flag is set to true, this will return the path of the prefs file, instead of the preferences as a dict.


Constructor: getMansurPrefsFromFile(**kwargs)
Return: dict (prefrences)
Arguments:
  • **kwargs
Keyword Arguments:


getNumLinesForDir

Constructor: getNumLinesForDir(directory = "D/mansurProject/mansurRig/scripts/mansur")
Return: None
Arguments:
  • directory(str) ; [default: "D:/mansurProject/mansurRig/scripts/mansur"]
Keyword Arguments:


getSideFromNode

Attempt to collect the given input's side.


Constructor: getSideFromNode(node)
Return: string (side)
Arguments:
  • node
Keyword Arguments:


getTopParentForObj

Recursively attempt to fet the top node of the maya heirarchy, from the given input upwards.


Constructor: getTopParentForObj(obj)
Return: MnsNameStd (Top Parent)
Arguments:
  • obj
Keyword Arguments:


getTopParentForSel

get the top node of the current selected object's maya heirarchy.


Constructor: getTopParentForSel()
Return: MnsNameStd (Top Parent)
Arguments:
Keyword Arguments:


importModuleFromPath

Attempt to import the given path as a python package into the global scope.


Constructor: importModuleFromPath(path)
Return: pythonPkg
Arguments:
  • path
Keyword Arguments:


isPluginLoaded

Constructor: isPluginLoaded(pluginName = None)
Return: None
Arguments:
  • pluginName(str) ; [default: None]
Keyword Arguments:


jointOrientToRotation

Transfer all jointOrient attributes for the jnt hirerchy to rotations.

Essentially bake the joint orient attributes for the joints.


Constructor: jointOrientToRotation(topNode = None)
Return: None
Arguments:
  • topNode(str) ; [default: None]
Keyword Arguments:


jointRotationToOrient

Transfer all jointOrient attributes for the jnt hirerchy to rotations.

Essentially bake the joint orient attributes for the joints.


Constructor: jointRotationToOrient(topNode = None)
Return: None
Arguments:
  • topNode(str) ; [default: None]
Keyword Arguments:


locatePreferencesDirectory

This method is used across to locate the prefs directory for the current user.


Constructor: locatePreferencesDirectory()
Return: string (preferences directory path)
Arguments:
Keyword Arguments:


lockAndHideAllTransforms

Lock and hide all of the given node's attributes.

Override flags can be inserted to skip requested channels.


Constructor: lockAndHideAllTransforms(node = None, **kwargs)
Return: bool
Arguments:
  • node(str) ; [default: None]
  • **kwargs
Keyword Arguments:
  • lock(bool)
  • keyable(bool)
  • cb(bool)
  • t(bool) ; [default: True]
  • r(bool) ; [default: True]
  • s(bool) ; [default: True]
  • x(bool) ; [default: True]
  • y(bool) ; [default: True]
  • z(bool) ; [default: True]


lockAndHideTransforms

Based on the given flags, lock/unlock, hide/unhide attributes for the given node.


Constructor: lockAndHideTransforms(node = None, **kwargs)
Return: bool
Arguments:
  • node(str) ; [default: None]
  • **kwargs
Keyword Arguments:
  • lock(bool)
  • keyable(bool)
  • cb(bool)
  • negateOperation(bool)
  • t(bool) ; [default: True]
  • tx(str) ; [default: t]
  • ty(str) ; [default: t]
  • tz(str) ; [default: t]
  • r(bool) ; [default: True]
  • rx(str) ; [default: r]
  • ry(str) ; [default: r]
  • rz(str) ; [default: r]
  • s(bool) ; [default: True]
  • sx(str) ; [default: s]
  • sy(str) ; [default: s]
  • sz(str) ; [default: s]


mirrorPose

Constructor: mirrorPose(targetTransform, mirrorTransform)
Return: None
Arguments:
  • targetTransform
  • mirrorTransform
Keyword Arguments:


mirrorPose2

Constructor: mirrorPose2(targetTransform, mirrorTransform, **kwargs)
Return: None
Arguments:
  • targetTransform
  • mirrorTransform
  • **kwargs
Keyword Arguments:


mnsLicStatusCheck

modes:

0 = Available for all

1 = Available for edit only


Constructor: mnsLicStatusCheck(mode = 0)
Return: None
Arguments:
  • mode(int) ; [default: 0]
Keyword Arguments:


objectArrayValidExistsCheckReturn

MNS core object array validity check.

Two main Cases for the mode parameter:

  1. trueOnlyIfAllValid - Run through the objects and only if ALL of them are found existing and valid, return the array back to the caller. If a single item failed- Return None.

  2. trueIfSomeValid - Check all the objects and return any or all of them based on validity.


Constructor: objectArrayValidExistsCheckReturn(**kwargs)
Return: List (Valid object list), None (If found invalid)
Arguments:
  • **kwargs
Keyword Arguments:
  • objectArray(list) ; [default: [' ']] - Objects input list
  • mode(int) - Validity return mode


readJson

Read the input json path into formatted python variables.


Constructor: readJson(fullPath)
Return: FormattedPythonJson
Arguments:
  • fullPath
Keyword Arguments:


readSetteingFromFile

Read mns setting from a given file and collect into a dict.


Constructor: readSetteingFromFile(settingsPath)
Return: dict (arguments)
Arguments:
  • settingsPath
Keyword Arguments:


reloadLib

Constructor: reloadLib()
Return: None
Arguments:
Keyword Arguments:


removeNamespaceFromString

Constructor: removeNamespaceFromString(value)
Return: None
Arguments:
  • value
Keyword Arguments:


resetMeshHistory

Constructor: resetMeshHistory(mesh, mode = 0)
Return: None
Arguments:
  • mesh
  • mode(int) ; [default: 0]
Keyword Arguments:


returnIndexFromSideDict

Return the corresponding index from the pre-defined input dictionary, for the given input elenment.


Constructor: returnIndexFromSideDict(dict, searchElement)
Return: int (index)
Arguments:
  • dict
  • searchElement
Keyword Arguments:


returnKeyFromElementTypeDict

Constructor: returnKeyFromElementTypeDict(dict, searchElement)
Return: None
Arguments:
  • dict
  • searchElement
Keyword Arguments:


returnNameStdChangeElement

global MnsNameStd utility-

Use this function to change any elemnt within a given MnsNameStd object based on keyword args given


Constructor: returnNameStdChangeElement(nameStd = None, **kwargs)
Return: MnsNameStd
Arguments:
  • nameStd(str) ; [default: None]
  • **kwargs
Keyword Arguments:
  • autoRename(bool) ; [default: True]
  • bodyPattern(str) ; [default: None]
  • node(str) ; [default: nameStd.node] - change node parameter
  • side(str) ; [default: nameStd.side] - change side parameter
  • body(str) ; [default: nameStd.body] - change body parameter
  • type(str) ; [default: nameStd.type] - change type parameter
  • id(str) ; [default: nameStd.id] - change id parameter
  • alpha(str) ; [default: nameStd.alpha] - change alpha parameter
  • suffix(str) ; [default: nameStd.suffix] - change suffix
  • comment(str) ; [default: nameStd.comment] - change comment parameter


setAttr

mns set attr.

Simple method to set attributes.

two cases:

  1. attribute isn't locked - set the value

  2. attribute is locked - unlock the attribute, set it's value, and re-lock the attribute.


Constructor: setAttr(attr, value)
Return: None
Arguments:
  • attr
  • value
Keyword Arguments:


setCtrlColorIdx

Global utility function:

Change the shape color override to index type, and set to the input value index


Constructor: setCtrlColorIdx(objects = [], colorIdx = 0)
Return: None
Arguments:
  • objects(list) ; [default: []]
  • colorIdx(int) ; [default: 0]
Keyword Arguments:


setCtrlColorRGB

Global utility function:

Change the shape color override to RGB type, and set to the input value RGB


Constructor: setCtrlColorRGB(objects = [], color = (1,1,1))
Return: None
Arguments:
  • objects(list) ; [default: []]
  • color(str) ; [default: (1]
  • 1
  • 1)
Keyword Arguments:


sortNameStdArrayByID

Attempt to sort the given array based on it's content ID's.


Constructor: sortNameStdArrayByID(nameStdArray)
Return: list (sorted list)
Arguments:
  • nameStdArray
Keyword Arguments:


sorted_alphanumeric

returns an alphanumeric ordered data from input given


Constructor: sorted_alphanumeric(data)
Return: list (sorted data)
Arguments:
  • data
Keyword Arguments:


splitDateTimeStringToList

Split a 'dateTime' string to a major/minor/patch/timestemp list


Constructor: splitDateTimeStringToList(dateTime = "")
Return: list
Arguments:
  • dateTime(str) ; [default: ""]
Keyword Arguments:


splitEnumAttrToChannelControlList

Split a pre-defined 'channel-control' enum attribute into a formatted python dict.


Constructor: splitEnumAttrToChannelControlList(enumAttrName, node, **kwargs)
Return: dict (formatted dictionary)
Arguments:
  • enumAttrName
  • node
  • **kwargs
Keyword Arguments:


splitEnumAttrToColorSchemeFloatTupleList

Constructor: splitEnumAttrToColorSchemeFloatTupleList(enumAttrName, node)
Return: list (formatted list of tuples)
Arguments:
  • enumAttrName
  • node
Keyword Arguments:


splitEnumToStringList

Split the given enum attribute is a formated python list.


Constructor: splitEnumToStringList(enumAttrName, node)
Return: list (formated list)
Arguments:
  • enumAttrName
  • node
Keyword Arguments:


splitNameStringToNameStd

Split a given string object and return a MnsNameStd based on it's structure.


Constructor: splitNameStringToNameStd(nameString = "")
Return: MnsNameStd
Arguments:
  • nameString(str) ; [default: ""]
Keyword Arguments:


updateMansurPrefs

Constructor: updateMansurPrefs(prefs = None, **kwargs)
Return: None
Arguments:
  • prefs(str) ; [default: None]
  • **kwargs
Keyword Arguments:


validateAttrAndGet

For the given transform (or nameStd)- check whether the given attr exists.

If the attr exist, get it and return it.


Constructor: validateAttrAndGet(transform = None, attrName = "", default = None, **kwargs)
Return: bool (return status), unknownType (value)
Arguments:
  • transform(str) ; [default: None]
  • attrName(str) ; [default: ""]
  • default(str) ; [default: None]
  • **kwargs
Keyword Arguments:


validateNameStd

For any input - string/PyNode/MnsNameStd - Validate it and attempt to convert it into a MnsNameStd Object.


Constructor: validateNameStd(objectA)
Return: MnsNameStd
Arguments:
  • objectA
Keyword Arguments:


writeJson

Write the input data into the input json file path.


Constructor: writeJson(directory, fileName, data = {}, **kwargs)
Return: None
Arguments:
  • directory
  • fileName
  • data(dict) ; [default: {}]
  • **kwargs
Keyword Arguments:


writeJsonFullPath

Write the input data into the input json file path.


Constructor: writeJsonFullPath(fullPath, data)
Return: None
Arguments:
  • fullPath
  • data
Keyword Arguments:


writeJsonPath

Write the input data into the input json file path.


Constructor: writeJsonPath(path = None, data = {})
Return: None
Arguments:
  • path(str) ; [default: None]
  • data(dict) ; [default: {}]
Keyword Arguments:


zeroJointOrient

Zero all jointOrient attributes for the jnt hirerchy to rotations.


Constructor: zeroJointOrient(topNode = None)
Return: None
Arguments:
  • topNode(str) ; [default: None]
Keyword Arguments:


zeroTransforms

Zero all available transforms for the given object passed in.


Constructor: zeroTransforms(transform = "")
Return: bool
Arguments:
  • transform(str) ; [default: ""]
Keyword Arguments: