SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


Go Back   Simply Maya User Community / Animation / Mel Scripts & Programming

Reply
 
Thread Tools
Old 27-07-2018, 01:02 PM   #1
lauris47
Registered User
 
Join Date: Sep 2011
Posts: 109
Default Automatically rename objects and their children

Hi, I have an issue,
I have 2000 objects and some of them have children.
At max each object has two more children.
At minimum, objects has one child.

Could someone help in renaming them with Mel or Python?

I want them named for example:
Object1_LOD0
Object1_LOD1
Object1_LOD2

Object2_LOD0
Object2_LOD1

etc.

Thank you.
Attached Images
File Type: jpg Rename children.jpg (71.2 KB, 3 views)
__________________
www.laurynaslubys.com
lauris47 is offline   Reply With Quote
Old 30-07-2018, 11:19 AM   #2
lauris47
Registered User
 
Join Date: Sep 2011
Posts: 109
Default

My wonderful colleague created this script in Python for me. It does exactly what I have described above.
I have attached it.


import maya.cmds as mc
import os

def rename_lod(path, name, n):
if "LOD" in name:
name = name[:-5]
print "Renaming", path, "to", name
rels = mc.listRelatives(path, children=True, fullPath=True)
print rels
if len(rels) == 1:
mc.rename(path, name+'_LOD'+str(n))
return
elif len(rels) > 2:
print "Too many children in one layer"
os.exit(1)
else:
child = rels[1]
rename_lod(child, name, n+1)

mc.rename(path, name+'_LOD'+str(n))


sel=mc.ls(selection=True)

for each in sel:
try:
name = each.split('|')[1]
except:
name = each
rename_lod(each, name, 0)
Attached Files
File Type: zip Unity_LOD.zip (489 Bytes, 1 views)
__________________
www.laurynaslubys.com

Last edited by lauris47; 30-07-2018 at 11:22 AM.
lauris47 is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.