原创MAYA插件:uvset整理器2.0

之前发布的代码只有一个reset功能,这次加入了可自定义的列表编辑功能,功能更强大了。同时优化了之前版本的reset逻辑。非常值得更新。

视频教程在B站,搜索尼古拉斯大飞机长。

 软件界面

 

 代码如下

# coding=utf-8
# written by zhaofei
import maya.cmds as cmds
import random


def gen_random_str(randomlength=8):
    """
  生成一个指定长度的随机字符串
  """
    random_str = 'cu'
    base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'
    length = len(base_str) - 1
    for i in range(randomlength):
        random_str += base_str[random.randint(0, length)]
    return random_str


def resetUV():
    selectOBJs = cmds.ls(sl=True, dag=True, type="mesh")
    if len(selectOBJs) == 0:
        cmds.warning("请选择polygon模型")
        return
    for obj in selectOBJs:

        uvList = cmds.polyUVSet(obj, q=True, allUVSets=True)
        if "map1" not in uvList:
            cmds.polyUVSet(obj, rename=True, uvSet=uvList[0], newUVSet="map1")
        else:
            if uvList[0] != "map1":
                cmds.polyUVSet(obj, delete=True, uvSet="map1")
                cmds.polyUVSet(obj, rename=True, uvSet=uvList[0], newUVSet="map1")
        newUVList = cmds.polyUVSet(obj, q=True, allUVSets=True)
        for uvName in range(1, len(newUVList)):
            cmds.polyUVSet(obj, delete=True, uvSet=newUVList[uvName])
    cmds.warning("执行完毕")


def renameUV(newNameList):  # 重命名UVSET输入uv数量和新名字列表
    if len(cmds.ls(sl=True)) == 0:
        cmds.warning("请选择polygon模型")
        return
    for obj in cmds.ls(sl=True):
        uvList = cmds.polyUVSet(obj, q=True, allUVSets=True)
        for uvIndex in range(len(newNameList)):
            if uvIndex < len(uvList):
                cmds.polyUVSet(obj, rename=True, uvSet=uvList[uvIndex], newUVSet=newNameList[uvIndex])
            else:
                cmds.polyUVSet(obj, create=True, uvSet=newNameList[uvIndex])
        if len(newNameList) < len(uvList):
            for uvIndex in range(len(newNameList), len(uvList)):
                cmds.polyUVSet(obj, delete=True, uvSet=uvList[uvIndex])
    cmds.warning("执行完毕")


def checkOnCommand(selfNum):
    for cbInde in range(1, selfNum):
        cmds.checkBox('uvSetCB{}'.format(cbInde), e=True, v=True)
        cmds.textField("uvSetTF{}".format(cbInde + 1), en=True, e=True)


def checkOffCommand(selfNum):
    for cbInde in range(selfNum, 10):
        cmds.checkBox('uvSetCB{}'.format(cbInde), e=True, v=False)
        cmds.textField("uvSetTF{}".format(cbInde), en=False, e=True)


def createMultiUvs():
    for cbInde in range(1, 10)[::-1]:
        uvAvailStat = cmds.checkBox('uvSetCB{}'.format(cbInde), q=True, v=True)
        if uvAvailStat:
            break
    nameList = []
    for nameInde in range(1, cbInde + 1):
        name = cmds.textField("uvSetTF{}".format(nameInde), q=True, tx=True)
        if len(name):
            nameList.append(name)
        else:
            cmds.warning("文本框请输入uvSet  {}  命名".format(nameInde))
            return
    tempNameList = []
    for i in range(cbInde):
        tempNameList.append(gen_random_str())
    renameUV(tempNameList)
    renameUV(nameList)


def getCurrentUVset():
    selectOBJs = cmds.ls(sl=True, dag=True, type="mesh")
    if len(selectOBJs) == 0:
        cmds.warning("请选择模型再点击按钮,程序会读取第一个模型的uvSet信息")
        return
    uvList = cmds.polyUVSet(selectOBJs[0], q=True, allUVSets=True)
    for uvInde, uvName in enumerate(uvList):
        if uvInde <= 8:
            cmds.checkBox('uvSetCB{}'.format(uvInde + 1), e=True, v=True)
            cmds.textField("uvSetTF{}".format(uvInde + 1), e=True, en=True, tx=uvName)
        else:
            cmds.warning("当前模型uvSet数量超过9个")
            break


def showUvSetRanger():
    noteText_A = "注意!记得先保存文件!"
    if cmds.window("uvSetRanger", ex=1) == 1:
        cmds.deleteUI("uvSetRanger", window=True)
    cmds.window("uvSetRanger", t="uvSet整理器v0.1", w=500, h=550)
    cmds.columnLayout(columnAttach=('both', 25), rowSpacing=15, columnWidth=440, adj=1)
    cmds.separator(height=2, style='none')
    cmds.columnLayout(columnAttach=('both', 20), rowSpacing=15, columnWidth=400, adj=0, bgc=(0.29, 0.29, 0.29), h=90)
    # cmds.columnLayout(columnAttach=('both', 20), rowSpacing=15, columnWidth=400, adj=0, bgc=(0.29, 0.29, 0.29), h=4)
    # cmds.setParent("..")
    cmds.separator(height=4, style='none')
    cmds.button(l="复位至 单 uvSet", h=30, w=150, bgc=(0.16, 0.16, 0.16), c="resetUV()")
    cmds.text(noteText_A, fn="fixedWidthFont", al="left")
    cmds.setParent('..')
    cmds.columnLayout(columnAttach=('both', 20), rowSpacing=15, columnWidth=440, adj=0, bgc=(0.29, 0.29, 0.29), h=265)
    # cmds.columnLayout(columnAttach=('both', 20), rowSpacing=15, columnWidth=400, adj=0, bgc=(0.29, 0.29, 0.29), h=4)
    # cmds.setParent("..")
    cmds.separator(height=4, style='none')
    cmds.rowColumnLayout(numberOfColumns=2, columnAttach=(1, 'both', 4), columnWidth=[(1, 250), (2, 110)])
    cmds.button(l="创建 多 uvSet", h=30, bgc=(0.16, 0.16, 0.16), c="createMultiUvs()")
    cmds.button(l="读取当前uvSet", h=30, bgc=(0.16, 0.16, 0.16), c="getCurrentUVset()")
    cmds.setParent("..")
    cmds.rowColumnLayout(numberOfColumns=2, columnAttach=(1, 'both', 11), columnWidth=[(1, 160), (2, 180)])
    for i in range(1, 10):
        if i == 1:
            cmds.checkBox('uvSetCB{}'.format(i), label='uvSet{}'.format(i), v=True, en=False)
            cmds.textField("uvSetTF{}".format(i), tx="map{}".format(i), en=True)
        else:
            cmds.checkBox('uvSetCB{}'.format(i), label='uvSet{}'.format(i), v=False,
                          onc='checkOnCommand({})'.format(i),
                          ofc='checkOffCommand({})'.format(i))
            cmds.textField("uvSetTF{}".format(i), tx="map{}".format(i), en=False)

    cmds.showWindow()


if __name__ == "__main__":
    showUvSetRanger()

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值