Need help with renaming script

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2008   #1
Need help with renaming script

I am building a renaming script for a class project. My script works in two ways it has a manual mode for selections also an Automatic mode. I have the manual mode working fine just like it should work however the Automatic mode is proving to be quite unforgiving.

Right now I am working on making it auto rename all the lights in the scene if for some reason you wanted all the lights to be one name. Heres that script.

if ((`menuItem -q -radioButton aut` == 1) && (`menuItem -q -radioButton light` == 1))
	{
//checks for lights
	string $sel[] = `ls -lt`;
	string $ind_obj;

//loop
for ($ind_obj in $sel)
		{
		rename $ind_obj $txRename;
		}
	}
}



Here is the rest of the code

global proc EasyName()
{
//Code written by Apophis3d(Chris Hatchie) This script provides a fast and easy way to renaming objects just select and go! Or automaticly renaming a bunch of objects quickly using the auto renaming function!!
//Checks to see if the window exists
if (`window -query -exists Ename`)
deleteUI Ename;

//Window setup
string $menu = `window -menuBar true -title "Easy Namer" Ename`;

//File Menu
menu -label "File" -tearOff true;
    menuItem -label "Exit"
    -command ("deleteUI -window " + $menu);
    
//Objects Menu
menu -label "Objects" -tearOff true;
    radioMenuItemCollection;
        menuItem 
            -label "NURBS Primitives"    
            -radioButton on nurbs;
        menuItem 
            -label "Polygon Primitives" 
            -radioButton off poly;
        menuItem 
            -label "Subdiv Primitives" 
            -radioButton off subd;
        menuItem 
            -label "Lights" 
            -radioButton off light;
            
            
            

//Selection Mode Menu        
menu -label "Selection Mode" -tearOff true;
        radioMenuItemCollection;
            menuItem 
                -label "Manual"   
                -radioButton on man;
            menuItem 
                -label "Auto"   
                -radioButton off aut;

//Help Menu
menu -label "Help" -helpMenu true -tearOff true;
    menuItem 
        -label "About"
        -command "about1();";

rowColumnLayout 
        -numberOfColumns 2
        -columnWidth 1 150;

//Text Field            
textField -tx "Unkown"rename_TF; 

//Renaming Button    
button
    -label "Rename Object"
    -command "namehere();";

showWindow $menu;

//Edits Window
window -edit -widthHeight 283 90 $menu;
window -edit -tlc 180 50 $menu;
}

//renaming script
global proc namehere()
{
//Querys text in the text field
string $txRename = `textField -q -tx rename_TF`;

//Querys Objects
string $mSel = `menuItem -q -radioButton poly`;
string $mSel = `menuItem -q -radioButton nurbs`;
string $mSel = `menuItem -q -radioButton subd`;
string $mSel = `menuItem -q -radioButton light`;

//Querys Selection Mode
string $mSel = `menuItem -q -radioButton man`;
string $mSel = `menuItem -q -radioButton aut`;

//statements

//checks for selection mode if manual is selected object type does not matter
if (`menuItem -q -radioButton man` == 1)
    {    
    //checks for selected objects
    string $sel[] = `ls -sl`;
    string $ind_obj;
    
    //Loop
    for ($ind_obj in $sel)
        {
        rename $ind_obj $txRename;
        }
    }
    
if ((`menuItem -q -radioButton aut` == 1) && (`menuItem -q -radioButton light` == 1))
	{
//checks for lights
	string $sel[] = `ls -lt`;
	string $ind_obj;

//loop
for ($ind_obj in $sel)
		{
		rename $ind_obj $txRename;
		}
	}
}

//About the program
global proc about1()
{
confirmDialog -title "About Easy Namer" -messageAlign center -message "Easy Namer v1.0 \n Created by Apophis3d (Chris Hatchie) \n Questions or Comments visit www.apophis3d.net" 
-button "OK" -defaultButton "OK";
}
 
Old 02 February 2008   #2
You should name your problem more directly, I guess.
Anyway, I think your `ls -lt` command returns light shapes and you want to rename transforms (and shapes accordingly). So just find the first parent of each shape and rename it. Smth like that:

//loop
 for ($ind_obj in $sel)
 		{
 		string $tr[] = `listRelatives -parent $ind_obj`;
 		rename $tr[0] $txRename;
 		}
 	}
 }
 
Old 02 February 2008   #3
Thank you very much

One thing I am confused with though.

what exactly is this line doing?

string $tr[] = `listRelatives -parent $ind_obj`;
 
Old 02 February 2008   #4
It lists all parents of your lightShape node. Corresponding transform node in most cases would be the first one
 
Old 02 February 2008   #5
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:11 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.