Renaming objects using custom name - maya python

718 views
Skip to first unread message

yogayas...@gmail.com

unread,
Jan 23, 2018, 12:28:38 PM1/23/18
to Python Programming for Autodesk Maya
Hi, thankyou for inviting me to this group. I've got helped for several problems. Thanks to my hero, Justin Israel who invited me.

I got a camera named something like this (different for each shot)
Shot_Cam

and i want to rename my camera to be same like my scene name. And add my start and end frame numbers to my camera name. So it will be something like this :
PRJ_SH001_SCN001_100_143_TK01

Is there anyway to do it using maya python? (because I only understand python module in maya right now)
Right now I only can get my scene name using cmds.file(query=True,sn=True). And cmds.rename('blablabla').

Any example or clue for it will be appreciated! :)
Please enlighten me.

Thanks.

Justin Israel

unread,
Jan 23, 2018, 3:15:09 PM1/23/18
to python_in...@googlegroups.com
If you know about cmds.file() and cmds.rename() then you are pretty much there already. The rest is just string formatting.

import os

cam = 'Shot_Cam'
start = 100
end = 143

sn = cmds.file(query=True, sn=True, shortName=True)
fname = os.path.basename(sn)
name = os.path.splitext(fname)[0]

new_name = '{}_{}_{}'.format(name, start, end)
cmds.rename(cam, new_name)

If you start with using the shortName option, you can avoid the extra step of needing to get the basename of the file. Then you use the os module to split off the extension. Format your extra criteria and then call rename()
 

Thanks.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/02190c7e-99f2-4edc-b260-d96d45524de5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages