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: None
Arguments:
  • objects(list) ; [default: []]
  • kwargs
Keyword Arguments:

addBlockClasIDToObj

Add a 'blkClassId' Attribute to the given input.

Constructor: addBlockClasIDToObj(objectA, kwargs)
Return: None
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: None
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: None
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: None
Arguments:
  • objB(str) ; [default: None]
  • kwargs
Keyword Arguments:

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: None
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: None
Arguments:
  • alpha(str) ; [default: "A"]
Keyword Arguments:

convertIntToAlpha

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

Constructor: convertIntToAlpha(intA = 0)
Return: None
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: None
Arguments:
  • kwargs
Keyword Arguments:

createFreeOffsetGroup

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

Constructor: createFreeOffsetGroup(transformObject)
Return: None
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: None
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.

Constructor: createNodeReturnNameStd(kwargs)
Return: None
Arguments:
  • kwargs
Keyword Arguments:

createOffsetGroup

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

Constructor: createOffsetGroup(transformObject, kwargs)
Return: None
Arguments:
  • transformObject
  • kwargs
Keyword Arguments:

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: None
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: None
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:

getMObjectFromObjName

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

getMansurPrefs

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: getMansurPrefs(kwargs)
Return: None
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: None
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: None
Arguments:
  • obj
Keyword Arguments:

getTopParentForSel

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

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

importModuleFromPath

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

Constructor: importModuleFromPath(path)
Return: None
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: None
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: None
Arguments:
  • node(str) ; [default: None]
  • kwargs
Keyword Arguments:

lockAndHideTransforms

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

Constructor: lockAndHideTransforms(node = None, kwargs)
Return: None
Arguments:
  • node(str) ; [default: None]
  • 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: None
Arguments:
  • kwargs
Keyword Arguments:

readJson

Read the input json path into formatted python variables.

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

readSetteingFromFile

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

Constructor: readSetteingFromFile(settingsPath)
Return: None
Arguments:
  • settingsPath
Keyword Arguments:

reloadLib

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

removeNamespaceFromString

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

returnIndexFromSideDict

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

Constructor: returnIndexFromSideDict(dict, searchElement)
Return: None
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: None
Arguments:
  • nameStd(str) ; [default: None]
  • kwargs
Keyword Arguments:

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: None
Arguments:
  • nameStdArray
Keyword Arguments:

sorted_alphanumeric

returns an alphanumeric ordered data from input given

Constructor: sorted_alphanumeric(data)
Return: None
Arguments:
  • data
Keyword Arguments:

splitDateTimeStringToList

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

Constructor: splitDateTimeStringToList(dateTime = "")
Return: None
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: None
Arguments:
  • enumAttrName
  • node
  • kwargs
Keyword Arguments:

splitEnumAttrToColorSchemeFloatTupleList

Constructor: splitEnumAttrToColorSchemeFloatTupleList(enumAttrName, node)
Return: None
Arguments:
  • enumAttrName
  • node
Keyword Arguments:

splitEnumToStringList

Split the given enum attribute is a formated python list.

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

splitNameStringToNameStd

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

Constructor: splitNameStringToNameStd(nameString = "")
Return: None
Arguments:
  • nameString(str) ; [default: ""]
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: None
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: None
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: None
Arguments:
  • transform(str) ; [default: ""]
Keyword Arguments: