import maya.cmds as cmds
# 定义窗口名称
window = "renameWindow"
# 如果窗口已经存在则删除
if cmds.window(window, exists=True):
cmds.deleteUI(window)
# 创建窗口
cmds.window(window, title="重命名(Rename)-by 喵喵动画屋-miaodonghua.com")
# 创建主布局
cmds.columnLayout(adjustableColumn=True)
# 创建输入框用于输入通用名称
cmds.text(label="通用名称(Common Name):")
textField = cmds.textField()
# 创建单选框用于选择左侧或右侧
cmds.text(label="命名规则(Naming rules):")
sideRadio = cmds.radioButtonGrp(label="", numberOfRadioButtons=3, labelArray3=["左 (L)", "右 (R)", "无(none)"])
# 创建按钮用于执行重命名操作
def renameObjects(*args):
# 获取输入的通用名称
prefix = cmds.textField(textField, query=True, text=True)
# 获取选择的侧
side = cmds.radioButtonGrp(sideRadio, query=True, select=True)
# 检查选择的侧
sideString = ""
if side == 1:
sideString = "L"
elif side == 2:
sideString = "R"
# 获取当前选择的对象
selectedObjects = cmds.ls(selection=True)
# 循环重命名对象
count = 1
for obj in selectedObjects:
newName = prefix
if sideString:
newName += "_" + sideString
# 添加序号
newName += str(count)
cmds.rename(obj, newName)
count += 1
cmds.button(label="执行重命名(Apply naming)", command=renameObjects)
# 显示窗口
cmds.showWindow(window)
Maya脚本:重命名脚本
未经允许不得转载:喵喵动画屋 » Maya脚本:重命名脚本