PDA

View Full Version : Need help with renaming script


Apophis3d
02-27-2008, 10:05 PM
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";
}

Sagroth
02-27-2008, 10:30 PM
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;
}
}
}

Apophis3d
02-27-2008, 10:54 PM
Thank you very much :)

One thing I am confused with though.

what exactly is this line doing?

string $tr[] = `listRelatives -parent $ind_obj`;

Sagroth
02-27-2008, 11:33 PM
It lists all parents of your lightShape node. Corresponding transform node in most cases would be the first one :)

CGTalk Moderation
02-27-2008, 11:33 PM
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.