尝试创建一个函数,增加在我的Gui中输入的数字的值。功能是
def autoIncrement(self):
myNumber = int(self.windowObj.myInt.value()) #This is my QSpinBox and it's value.
selection = cmds.ls(sl=True) #List selected
global myNumber #Setting the global
start = myNumber #Setting the value to be QSpinBox's value.
interval = 1 # Adding 1 interval
for object in selection:
if (myNumber==0):
myNumber= start
else:
myNumber = myNumber + interval #Needs to get the value in my spin box and add +1 to it for the next object selected.
cmds.rename(object, myNumber)
我做错了什么?请记住,我的号码是在命名约定的中间添加的,并且希望避免Maya最后添加一个。目前的命名惯例是 NAME_NUMBER_POSITION_LEVEL 例如= MF_100_L_HI
Currently it renames but adds number at the end to:
MF_100_L_HI
MF_100_L_HI1
MF_100_L_HI2
When it should be like:
MF_100_L_HI
MF_101_L_HI
MF_102_L_HI
This is my renaming script:
def renamer(self):
myNames = str(self.windowObj.myName.text()) # First field of text (e.g MF)
myLevels= self.windowObj.myLevel.currentText() #Third feild of text (e.g HI)
myPositions= self.windowObj.myPosition.currentText() #Fourth field text (e.g L)
myNumbers= int(self.windowObj.myInt.value()) #Second field of text (The number goes here) (e.g 100)
renamedName = (myNames + "_" + myNumbers + "_" + myPositions + "_" + myLevels)
selection = cmds.ls(sl = True)
for object in selection:
cmds.rename(object, renamedName)
print renamedName