Hi again
I've remade your code slightly differently - just trying different things
out - and there's just one bit that's baffling me and I wonder if you can
give me another pointer :
num = 1
for item in items:
newName = name.replace("*","%s"%num)
You're setting num initially to 1 but when I run the script the first
object just gets called 'name' and the second gets 'name1'. So is this
line incorrect somehow? I've read around that string formatting operator
and to be honest it's not quite clear yet but I'm sure it will become so
gradually!
Thanks again for your time
On Wednesday, August 8, 2012 1:20:38 AM UTC-5, Geordie Martinez wrote:
>
> whoops change this line of code:
>
> FROM:
> name = promptForName()
> TO:
> name = pm.promptBox('Enter Naming Scheme', "Enter:", "Okay" , "Cancel")
>
> On Tue, Aug 7, 2012 at 11:18 PM, Geordie Martinez
> <[email protected]<javascript:>
> > wrote:
>
>> 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 <[email protected] <javascript:>>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