Here is a pymel version of what you're trying to do. Maybe this can help
you.

import pymel.core as pm
def renameChain(items=None):
    """renames a joint chain based on asterisk as a wildCard """
    items = items or pm.selected()
    name = promptForName()
    if not name:
        return

    num = 1
    for item in items:
        newName = name.replace("*","%s"%num)
        pm.rename(item, newName)
        num += 1

On Tue, Aug 7, 2012 at 3:48 PM, j00ey <timbac...@gmail.com> wrote:

> Hi
>
> I'm learning some python, coming from a MEL background [though I'm no
> expert in that either] and I'm trying to write a simple script to rename a
> number of objects according to a user input name. I've got it to work but I
> want it to test if there is no user input and if not [and the user didn't
> press the cancel button] loop back and re-prompt for input.
>
> I was thinking something along the lines of this :
> 1 - declare a procedure to do the renaming
> 2 - prompt dialog
> 3 - if the input is valid run the procedure, if not pop up a message and
> ask whether to retry or cancel
> 4 - if retry, run the procedure again
>
> but I came unstuck and I can't find anything to do with declaring a
> procedure in pymel. Can anyone help? Here's what I've written so far.
> Thanks in advance
>
>
> ##############################################################################################################
>
> #get selection
>
> sel=ls(sl=1)
>
> #get user input
> input = promptDialog(t='New
> Name',b=['OK','Cancel'],db='OK',cb='Cancel',ds='no input')
>
> #set base number to 1
>
> x=1
>
> #test user input and if not empty string, rename selected objects
>
> if input=='OK':
> name=promptDialog(q=1, t=1)
>  if len(name) != 0:
> for s in sel:
> s.rename(name + str(x))
> x+=1
> else:
> #if user has not input a valid string prompt to retry
> message = confirmDialog(message ='Please enter a
> name',b=['Retry','Cancel'],db='Retry',cb='Cancel',ds='Cancel')
>
>
> ##############################################################################################################
>
>  --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to