Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def testHasTag(self):
        tagName = 'someGreatTag'
        tagAttr = nodeTag.getTagAttr(tagName)

        self.assertFalse(nodeTag.hasTag(self.xform,tagName))
        self.assertFalse(nodeTag.hasTag(self.xform,tagAttr))

        nodeTag.setTag(self.xform, tagName, {})

        self.assertTrue(nodeTag.hasTag(self.xform,tagName))
        self.assertTrue(nodeTag.hasTag(self.xform,tagAttr))
Ejemplo n.º 6
0
    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])
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
def setInfo(control, info):
    control = str(control)
    nodeTag.setTag(control, CONTROL_TAG_NAME, info)
Ejemplo n.º 9
0
    def testSetTag(self):
        tagName = 'someGreatTag'
        tagAttr = nodeTag.getTagAttr(tagName)

        nodeTag.setTag(self.xform, tagName, {})
        self.assertTrue(MC.attributeQuery(tagAttr, n=self.xform, ex=1))