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:
-
Object to add attr to was found non-existing or invalid. Abort.
-
The 'replace' flag wasn't set, and the attribute already exists. Abort.
-
Attr name wasn't passed in. Abort.
-
The attribute type passed doesn't match the attribute value passed. Abort.
-
min/max values were passed in, although the attr type is not an Int or a Float. Skip min/max values.
-
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.
-
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: |
|
Keyword Arguments: |
|
addBlockClasIDToObj
Add a 'blkClassId' Attribute to the given input.
Constructor: | addBlockClasIDToObj(objectA, **kwargs) |
Return: | PyAttribute ('blkClassID') |
Arguments: |
|
Keyword Arguments: |
applyChennelControlAttributesToTransform
This method applies a 'channelControl' dict attributes into the given transform.
Constructor: | applyChennelControlAttributesToTransform(transform = None, ccDict = {}) |
Return: | None |
Arguments: |
|
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: |
|
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: |
|
Keyword Arguments: |
checkIfObjExistsAndSet
For the object passed in-
three main cases:
-
If it is a 'PyNode' object, set it as the object to check.
-
If it is an MnsNameStd object,set it's .node property as the object to check.
-
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: |
|
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: | dict (pairingDict - {"x", "y","z"}) |
Arguments: |
|
Keyword Arguments: |
connectShapeColorRGB
Constructor: | connectShapeColorRGB(source = None, target = None) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
convertAlphaToInt
Recursive. Convert an Alpha input into an Int ID. Infinite.
Constructor: | convertAlphaToInt(alpha = "A") |
Return: | int |
Arguments: |
|
Keyword Arguments: |
convertIntToAlpha
Recursive. Convert an Int input into an Alpha ID. Infinite.
Constructor: | convertIntToAlpha(intA = 0) |
Return: | string |
Arguments: |
|
Keyword Arguments: |
convertNodeToNameStd
Attempt to convert a given node into a MnsNameStd object.
Constructor: | convertNodeToNameStd(node) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
createAxisLamberts
An axes colored lambert shaders creation function.
Constructor: | createAxisLamberts(**kwargs) |
Return: | dict ('X': xAxisLambert, 'Y': yAixsLambert, 'Z': zAxisLambert) |
Arguments: |
|
Keyword Arguments: |
|
createFreeOffsetGroup
For the given transform, create a free offset group transform parent.
Constructor: | createFreeOffsetGroup(transformObject) |
Return: | MnsNameStd (offsetGrp) |
Arguments: |
|
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: |
|
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: |
|
Keyword Arguments: |
|
createOffsetGroup
For the given transform, create a predefined offset group transform parent.
Constructor: | createOffsetGroup(transformObject, **kwargs) |
Return: | MnsNameStd (offsetGrp) |
Arguments: |
|
Keyword Arguments: |
|
deleteFile
A delete file global function that includes a pre-defined log write.
Constructor: | deleteFile(file) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
deleteUnusedShapeNodes
Constructor: | deleteUnusedShapeNodes(obj = None) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
distBetween
Measure the distance between to maya transforms.
Constructor: | distBetween(transformA = None, transformB = None) |
Return: | float (distance) |
Arguments: |
|
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: |
|
Keyword Arguments: |
extractHeaderFromPath
Constructor: | extractHeaderFromPath(fullPath) |
Return: | None |
Arguments: |
|
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: |
|
Keyword Arguments: |
fixShapesName
Simple shape name fix function based on parent's name.
Constructor: | fixShapesName(objects = []) |
Return: | None |
Arguments: |
|
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: |
|
Keyword Arguments: |
getMObjectFromNode
Constructor: | getMObjectFromNode(node) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
getMObjectFromObjName
Constructor: | getMObjectFromObjName(name) |
Return: | None |
Arguments: |
|
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: |
|
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: |
|
Keyword Arguments: |
getNumLinesForDir
Constructor: | getNumLinesForDir(directory = "D/mansurProject/mansurRig/scripts/mansur") |
Return: | None |
Arguments: |
|
Keyword Arguments: |
getSideFromNode
Attempt to collect the given input's side.
Constructor: | getSideFromNode(node) |
Return: | string (side) |
Arguments: |
|
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: |
|
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: |
|
Keyword Arguments: |
isPluginLoaded
Constructor: | isPluginLoaded(pluginName = None) |
Return: | None |
Arguments: |
|
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: |
|
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: |
|
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: |
|
Keyword Arguments: |
|
lockAndHideTransforms
Based on the given flags, lock/unlock, hide/unhide attributes for the given node.
Constructor: | lockAndHideTransforms(node = None, **kwargs) |
Return: | bool |
Arguments: |
|
Keyword Arguments: |
|
mirrorPose
Constructor: | mirrorPose(targetTransform, mirrorTransform) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
mirrorPose2
Constructor: | mirrorPose2(targetTransform, mirrorTransform, **kwargs) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
mnsLicStatusCheck
modes:
0 = Available for all
1 = Available for edit only
Constructor: | mnsLicStatusCheck(mode = 0) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
objectArrayValidExistsCheckReturn
MNS core object array validity check.
Two main Cases for the mode parameter:
-
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.
-
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: |
|
Keyword Arguments: |
|
readJson
Read the input json path into formatted python variables.
Constructor: | readJson(fullPath) |
Return: | FormattedPythonJson |
Arguments: |
|
Keyword Arguments: |
readSetteingFromFile
Read mns setting from a given file and collect into a dict.
Constructor: | readSetteingFromFile(settingsPath) |
Return: | dict (arguments) |
Arguments: |
|
Keyword Arguments: |
reloadLib
Constructor: | reloadLib() |
Return: | None |
Arguments: | |
Keyword Arguments: |
removeNamespaceFromString
Constructor: | removeNamespaceFromString(value) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
resetMeshHistory
Constructor: | resetMeshHistory(mesh, mode = 0) |
Return: | None |
Arguments: |
|
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: |
|
Keyword Arguments: |
returnKeyFromElementTypeDict
Constructor: | returnKeyFromElementTypeDict(dict, searchElement) |
Return: | None |
Arguments: |
|
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: |
|
Keyword Arguments: |
|
setAttr
mns set attr.
Simple method to set attributes.
two cases:
-
attribute isn't locked - set the value
-
attribute is locked - unlock the attribute, set it's value, and re-lock the attribute.
Constructor: | setAttr(attr, value) |
Return: | None |
Arguments: |
|
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: |
|
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: |
|
Keyword Arguments: |
sortNameStdArrayByID
Attempt to sort the given array based on it's content ID's.
Constructor: | sortNameStdArrayByID(nameStdArray) |
Return: | list (sorted list) |
Arguments: |
|
Keyword Arguments: |
sorted_alphanumeric
returns an alphanumeric ordered data from input given
Constructor: | sorted_alphanumeric(data) |
Return: | list (sorted data) |
Arguments: |
|
Keyword Arguments: |
splitDateTimeStringToList
Split a 'dateTime' string to a major/minor/patch/timestemp list
Constructor: | splitDateTimeStringToList(dateTime = "") |
Return: | list |
Arguments: |
|
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: |
|
Keyword Arguments: |
splitEnumAttrToColorSchemeFloatTupleList
Constructor: | splitEnumAttrToColorSchemeFloatTupleList(enumAttrName, node) |
Return: | list (formatted list of tuples) |
Arguments: |
|
Keyword Arguments: |
splitEnumToStringList
Split the given enum attribute is a formated python list.
Constructor: | splitEnumToStringList(enumAttrName, node) |
Return: | list (formated list) |
Arguments: |
|
Keyword Arguments: |
splitNameStringToNameStd
Split a given string object and return a MnsNameStd based on it's structure.
Constructor: | splitNameStringToNameStd(nameString = "") |
Return: | MnsNameStd |
Arguments: |
|
Keyword Arguments: |
updateMansurPrefs
Constructor: | updateMansurPrefs(prefs = None, **kwargs) |
Return: | None |
Arguments: |
|
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: |
|
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: |
|
Keyword Arguments: |
writeJson
Write the input data into the input json file path.
Constructor: | writeJson(directory, fileName, data = {}, **kwargs) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
writeJsonFullPath
Write the input data into the input json file path.
Constructor: | writeJsonFullPath(fullPath, data) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
writeJsonPath
Write the input data into the input json file path.
Constructor: | writeJsonPath(path = None, data = {}) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
zeroJointOrient
Zero all jointOrient attributes for the jnt hirerchy to rotations.
Constructor: | zeroJointOrient(topNode = None) |
Return: | None |
Arguments: |
|
Keyword Arguments: |
zeroTransforms
Zero all available transforms for the given object passed in.
Constructor: | zeroTransforms(transform = "") |
Return: | bool |
Arguments: |
|
Keyword Arguments: |