python类listAttr()的实例源码

zbw_attributes.py 文件源码 项目:zTools 作者: zethwillie 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def shift_attr(mode, *args):
    """
    shifts the selected attr up or down
    """

    obj = cmds.channelBox('mainChannelBox', q=True, mainObjectList=True)
    if obj:
        attr = cmds.channelBox('mainChannelBox', q=True, selectedMainAttributes=True)
        if attr:
            for eachObj in obj:
                udAttr = cmds.listAttr(eachObj, ud=True)
                if not attr[0] in udAttr:
                    sys.exit('selected attribute is static and cannot be shifted')
                # temp unlock all user defined attributes
                attrLock = cmds.listAttr(eachObj, ud=True, l=True)
                if attrLock:
                    for alck in attrLock:
                        cmds.setAttr(eachObj + '.' + alck, lock=0)
                # shift down
                if mode == 0:
                    if len(attr) > 1:
                        attr.reverse()
                        sort = attr
                    if len(attr) == 1:
                        sort = attr
                    for i in sort:
                        attrLs = cmds.listAttr(eachObj, ud=True)
                        attrSize = len(attrLs)
                        attrPos = attrLs.index(i)
                        cmds.deleteAttr(eachObj, at=attrLs[attrPos])
                        cmds.undo()
                        for x in range(attrPos + 2, attrSize, 1):
                            cmds.deleteAttr(eachObj, at=attrLs[x])
                            cmds.undo()
                # shift up
                if mode == 1:
                    for i in attr:
                        attrLs = cmds.listAttr(eachObj, ud=True)
                        attrSize = len(attrLs)
                        attrPos = attrLs.index(i)
                        if attrLs[attrPos - 1]:
                            cmds.deleteAttr(eachObj, at=attrLs[attrPos - 1])
                            cmds.undo()
                        for x in range(attrPos + 1, attrSize, 1):
                            cmds.deleteAttr(eachObj, at=attrLs[x])
                            cmds.undo()
                # relock all user defined attributes
                if attrLock:
                    for alck in attrLock:
                        cmds.setAttr(eachObj + '.' + alck, lock=1)
ml_puppet.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def swapAnimation(fromNode, toNode):

    if not mc.keyframe(fromNode, query=True, name=True):
        mc.cutKey(toNode, clear=True)
        return

    attrs = mc.listAttr(fromNode, keyable=True)
    if not attrs:
        return

    for attr in attrs:
        if not mc.attributeQuery(attr, node=toNode, exists=True):
            mc.cutKey(fromNode, attribute=attr, clear=True)
            continue

        fromPlug = '{}.{}'.format(fromNode, attr)
        toPlug = '{}.{}'.format(toNode, attr)

        srcCurve = mc.listConnections(fromPlug, source=True, destination=False, type='animCurve')
        dstCurve = mc.listConnections(toPlug, source=True, destination=False, type='animCurve')

        copySrc=None
        copyDst=None

        if srcCurve:
            copySrc = mc.duplicate(srcCurve[0])[0]

        if dstCurve:
            copyDst = mc.duplicate(dstCurve[0])[0]

        if copySrc:
            try:
                mc.cutKey(copySrc)
                mc.pasteKey(toNode, attribute=attr, option='replaceCompletely')
            except:pass
        if copyDst:
            try:
                mc.cutKey(copyDst)
                mc.pasteKey(fromNode, attribute=attr, option='replaceCompletely')
            except:pass

    for axis in getMirrorAxis(toNode):
        mc.scaleKey(toNode, attribute=axis, valueScale=-1)
        mc.scaleKey(fromNode, attribute=axis, valueScale=-1)
ml_graphEditorMask.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def isolate(option):

    sel = mc.ls(sl=True)
    if not sel:
        return

    graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True)

    channels = list()
    wildCard = str()
    alreadyIsolated = True

    if graphVis:
        for c in graphVis:
            if not '.' in c and mc.objExists(c):
                attrs = mc.listAttr(c, keyable=True, unlocked=True)
                if attrs:
                    channels.extend([c+'.'+a for a in attrs])
            else:
                attr = c.split('.')[-1]
                if attr.startswith(option):
                    channels.append(c)
                    if not wildCard:
                        wildCard = option+'*'
                elif attr.endswith(option):
                    channels.append(c)
                    if not wildCard:
                        wildCard = '*'+option
                elif attr == option:
                    channels.append(c)
                    if not wildCard:
                        wildCard = option
                else:
                    #found a curve that is outside our search parameters
                    alreadyIsolated = False

    if channels and alreadyIsolated:

        #if the option is already the only thing being displayed, then show everything that matches the option

        for obj in sel:
            attrs = mc.listAttr(obj, keyable=True, unlocked=True, string=wildCard)
            if attrs:
                channels.extend([obj+'.'+a for a in attrs])

    if not channels:
        for obj in sel:
            attrs = mc.listAttr(obj, keyable=True, unlocked=True)

            for a in attrs:
                if a==option or a.startswith(option) or a.endswith(option):
                    channels.append(obj+'.'+a)

    clear()
    for c in channels:
        mc.selectionConnection('graphEditor1FromOutliner', edit=True, select=c)


问题


面经


文章

微信
公众号

扫码关注公众号