Notifications
Clear all

[Closed] Naming script query

Hey,

I’m creating a mirror naming script which reads an array of objects, then starts rightwards, searches for “L” or “R” in the name string and renames it. The problem is that I need to terminate the program in exceptional cases, say the name of the object is only integers. In my case it gives a messagebox saying “Name only integers” but then contiues to execute the program. I tried exit, but that only exits from the current loop.

Secondly, i cannot create and array with a single object. I’m new to Max programming, so please excuse me for any stupid queries,

Thanks,

Vikram

My script is as follows:

 
rollout mirrorName "Mirror Name" width:167 height:86
(
label lbl1 "Select objects with named set" pos:[13,3] width:143 height:12 
button btn1 "Record object set" pos:[33,20] width:97 height:17 
label lbl2 "Select objects to rename" pos:[22,40] width:126 height:14 
button btn2 "Mirror Names" pos:[48,57] width:68 height:17 
label lb3 "Renaming will be in order of selection"
label lb4 "Select more than 1 objetcs"
 
global orig_objs = #() 
global side
global lastchar 
global chartype
global namecount
global flag 
 
on btn1 pressed do
(
try
(
orig_objs = $ as array
orig_count = orig_objs.count
namecount = (orig_objs[orig_count].name as string).count
lastchar = (orig_objs[orig_count].name[namecount])
chartype = classof(execute (lastchar))
flag = 1
)
catch()
 
 
 
if (chartype == integer) then
 
(
for i = 1 to (namecount-1) do
(
	lastchar = (orig_objs[orig_count].name[namecount - i])
	 chartype = classof(execute (lastchar))
	side = lastchar
	if (chartype != integer) then exit
	else 
	(
	 flag = flag + 1
	 (
	 if (flag == namecount)
	 then 
	 (
	 messagebox "The object name is only integers"
	 )
	 )
	) 
) 
)
else (side = lastchar)
 
if (side == "L" or side == "R")
then messagebox "Please select the target objects and press Mirror Names"
else messagebox "No side L or R mentioned"
 
)
 
 
 
on btn2 pressed do
(
	if side == "L" or side == "R"
then conside = side
	else "No side L or R mentioned"
new_objs = $ as array
new_count = new_objs.count
if orig_objs.count != new_objs.count
then messagebox "No. of Source and Target objects do not match"
 
	if conside == "L"
then
for i = 1 to new_count do
(
	new_objs[i].name = orig_objs[i].name
	new_objs[i].name = replace new_objs[i].name (namecount - (flag)) 1 "R"
)
else if conside == "R"
then
for i = 1 to new_count do
	(
	 new_objs[i].name = orig_objs[i].name
	 new_objs[i].name = replace new_objs[i].name (namecount - (flag)) 1 "L"
	)
 
) 
 
)
createDialog mirrorName width:180 height:110