def testGetTag(self): tagName = 'someGreatTag' tagAttr = nodeTag.getTagAttr(tagName) self.assertRaises(RuntimeError, nodeTag.getTag, self.xform, tagName) self.assertEqual(nodeTag.getTag(self.xform, tagName, noError=True), {}) val = {'test': 'x'} nodeTag.setTag(self.xform, tagName, val) self.assertEqual(nodeTag.getTag(self.xform, tagName), val)
def setStorableXformAttrs(xform, **kwargs): """ Set the tag on the node. Any kwargs passed will be set; others will be left at the current value if one exists, or set to the default value if non-existant @keyword categories: node categories @type categories: list of strings """ tagD = {'categories': [], 'worldSpace': False} if nodeTag.hasTag(xform, STORABLE_TAG_NAME): tagD = nodeTag.getTag(xform, STORABLE_TAG_NAME) categories = kwargs.get('categories', tagD['categories']) worldSpace = kwargs.get('worldSpace', tagD['worldSpace']) assert isinstance(categories, list) or isinstance(categories, tuple) d = {'worldSpace': bool(worldSpace), 'categories': list(categories)} nodeTag.setTag(xform, STORABLE_TAG_NAME, d)
def setLockTag(ctl, **kwargs): """ Add new lock information to the lock tag of a control. Create the tag if it does not exist @keyword unlockedUnkeyable: channels that are unlcoked but not keyable @keyword uu: unlockedUnkeyable alias @keyword unlockedKeyable: channels that are unlcoked but not keyable @keyword uk: unlockedKeyable alias @keyword lockedKeyable: channels that are unlcoked but not keyable @keyword lk: lockedKeyable alias update locking information on controls. This is used to toggle locking when rig nodes are locked """ if nodeTag.hasTag(ctl, LOCKS_TAG_NAME): current = nodeTag.getTag(ctl, LOCKS_TAG_NAME) else: current = copy.deepcopy(_defaultLocks) for long_, short in [('unlockedUnkeyable', 'uu'), ('unlockedKeyable', 'uk'), ('lockedKeyable', 'lk')]: val = set(kwargs.get(long_, kwargs.get(short, []))) current[long_] = list(val.union(current[long_])) nodeTag.setTag(ctl, LOCKS_TAG_NAME, current)
def getInfo(control, includeEdits=True): info = nodeTag.getTag(control, CONTROL_TAG_NAME) editor = getEditor(control) if includeEdits and editor: info['t'] = list(MC.getAttr('%s.t' % editor)[0]) info['r'] = list(MC.getAttr('%s.r' % editor)[0]) info['s'] = list(MC.getAttr('%s.s' % editor)[0]) return info
def addStorableXformCategory(xform, *categories): if not nodeTag.hasTag(xform, STORABLE_TAG_NAME): raise RuntimeError("%s is not a storable node" % xform) tagD = nodeTag.getTag(xform, STORABLE_TAG_NAME) tagD['categories'].extend(categories) tagD['categories'] = list(set(tagD['categories'])) nodeTag.setTag(xform, STORABLE_TAG_NAME, tagD) return xform
def setEditable(ctl, state): """ Add an intermediate xform node to a control. The control's editable state can be toggled, and transformation differences to the 'editor' node will be flushed down to the shape level and recorded in the control data @param ctl: the control to make editable @type ctl: str @param state: True or False @type state: bool @return: True if state was changed, else False """ editor = getEditor(ctl) if editor and state: return False elif not editor and not state: return False info = getInfo(ctl) if state: editor = MC.createNode('transform', name='%s_editor' % ctl, parent=None) if nodeTag.hasTag(ctl, '%s_editor' % LOCKS_TAG_NAME): tag = nodeTag.getTag(ctl, '%s_editor' % LOCKS_TAG_NAME) nodeTag.rmTag(ctl, '%s_editor' % LOCKS_TAG_NAME) nodeTag.setTag(editor, LOCKS_TAG_NAME, tag) MC.parent(editor, ctl) MC.setAttr('%s.t' % editor, *info['t'], type='double3') MC.setAttr('%s.r' % editor, *info['r'], type='double3') MC.setAttr('%s.s' % editor, *info['s'], type='double3') MC.setAttr("%s.shear" % editor, 0,0,0, type='double3') utils.parentShape(editor, ctl, deleteChildXform=False) else: if nodeTag.hasTag(editor, LOCKS_TAG_NAME): editorLocks = nodeTag.getTag(editor, LOCKS_TAG_NAME) nodeTag.setTag(ctl, '%s_editor' % LOCKS_TAG_NAME, editorLocks) setInfo(ctl, info) utils.parentShape(ctl, editor, deleteChildXform=True) return True
def getLockTag(node): """ Get the lock tag of a node. If the node is not tagged, the default empty lock tag is returned @param node: the node to query @type node: str @return: lock tag dictionary @rtype: dict """ if not nodeTag.hasTag(node, LOCKS_TAG_NAME): return copy.deepcopy(_defaultLocks) return nodeTag.getTag(node, LOCKS_TAG_NAME)
def getStorableXforms(inNodeList=None, categories=None): """Return all nodes in the scene from the category""" result = nodeTag.getNodesWithTag(STORABLE_TAG_NAME) if inNodeList is not None: result = list(set(inNodeList).intersection(result)) if categories: assert isinstance(categories, list) categories=set(categories) tmp = result result = [] for node in tmp: nodeCategories = nodeTag.getTag(node, STORABLE_TAG_NAME)['categories'] if set(nodeCategories).intersection(categories): result.append(node) return result
def testValidTags(self): tagName = 'someGreatTag' tagAttr = nodeTag.getTagAttr(tagName) validValues = {'string': 'aStr', 'int': 5, 'float': 5.5, 'list': ['x', 5, 5.5], 'dict': {'s': 'x', 'i': 5, 'f': 5.5}, 'tuple': ('x', 5, 5.5), 'set': set(['x', 5, 5.5])} nodeTag.setTag(self.xform, tagName, validValues) gottenTag = nodeTag.getTag(self.xform, tagName) for k, v in validValues.items(): self.assertEqual(v, gottenTag[k])
def getStorableXformInfo(xform): """ Get information needed to record the state of a transform node to rebuild it, duplicate it, etc """ if not nodeTag.hasTag(xform, STORABLE_TAG_NAME): raise RuntimeError("%s is not a storable node" % xform) recordableTag = nodeTag.getTag(xform, STORABLE_TAG_NAME) result = {} result.update(recordableTag) result['nodeType'] = MC.objectType(xform) worldSpace = result['worldSpace'] result['matrix'] = MC.xform(xform, q=1, m=1, ws=worldSpace) result['rotateOrder'] = MC.getAttr('%s.rotateOrder' % xform) if result['nodeType'] == 'joint': result['radius'] = MC.getAttr('%s.radius' % (xform)) result['jointOrient'] = MC.getAttr('%s.jointOrient' % xform)[0] result['rotation'] = MC.xform(xform, q=1, ro=1, ws=result['worldSpace']) par = MC.listRelatives(xform, parent=1, pa=1) if par: par = par[0] result['parent'] = par #get control info if isControl(xform): result['controlArgs'] = getInfo(xform) _logger.debug('controlArgsType: %s' % str(type(result['controlArgs']))) return result