Hey , everybody!
I am trying to learn Python already for one week and decided to make my first tool. Very simple rename tool for maya.
I got almost everything working in UI , but I can't get rename tool it self work.
It gives me error when I am trying to rename staff , mostly it's because I don't know how query name from my
"cmds.textField" . So my question what should I put in my "cmds.rename" command , so instead of my "blablabla" it would get name from textField and rename my object?
Sorry for my english , hopefully I got my question correct. I am really new to it , so if you have some advice please make it easy as possible
Thank you
import maya.cmds as cmds
def UI():
# Check to see if our window exists
if cmds.window("FirstVladRenameToolUI", exists = True):
cmds.deleteUI("FirstVladRenameToolUI")
# Create our window
window = cmds.window("FirstVladRenameToolUI", title = "Vlad Rename Tool", sizeable = False, w = 500, h = 150, mnb = False, mxb = False)
# Create a main layout
mainLayout = cmds.columnLayout(w = 500, h = 150)
# Create our own column layout
cmds.separator(h=15)
rowColumnLayout = cmds.rowColumnLayout(nc = 1, cw = [(1,460),(2,40)], columnOffset = [(1, "both", 5), (2, "both", 5 )])
# Instructions for use
cmds.text(l="Instructions: select object(s) to rename", align = "left" )
# Input field
inputField = cmds.textField("inputField", w = 500 , parent = mainLayout)
# Make button
cmds.separator(h=20, style = "none")
cmds.button(l = "Rename Me!", w = 500, h = 50, align = "center",c = RenameTool, parent = mainLayout)
# Show window
cmds.showWindow(window)
def RenameTool(*args):
selectObject = cmds.ls(sl = True)
sizeObject = len(selectObject)
for sel in range(0, sizeObject, 1):
cmds.rename(selectObject[sel], "blablabla")