zbw_attributes.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:zTools 作者: zethwillie 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号