random rename object

Hi there,

I'm very nooby to maxscript and so i need a very little help.

My target it's to rename different object randomly from 1 to 100.

I explain my problem. I have 10 box, 10 sphere, 10 cylinder...and when I rename it on
obj_### i have as result all the box named obj000,obj001,obj002 etc and after all the sphere like obj011, obj012 etc.

and I don't need that, i need then obj000 to be a box, obj002 a sphere, obj003 another box, and obj004 a cylinder ...and so randomly

any suggestion ?

(sorry for my english)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
druigant's picture

Tnx

Works perfectly, both,

Thanks you very much

miauu's picture

.

Why you not use Tools - Rename Objects to rename the boxes, spheres and so on, as you want?

pixamoon's picture

`

Hey, try this:

basename = "obj_"
 
objArray = deepcopy (selection as array)
t = timestamp()
 
do (
	if objArray.count > 0 do (
		i = random 1 objArray.count
		objArray[i].name = uniquename basename
		deleteitem objArray i
	)
	if timestamp() - t > 1000 do exit
) while objArray.count > 0

cheers,
Pixamoon

barigazy's picture

...

a bit simplified version

fn randomrename objs name: = if (count = objs.count) > 0 do
(
	array = #()
	while array.count != count do appendifunique array (random 1 count)
	for i in array do objs[i].name = uniquename name
)
randomrename selection name:"obj_"

bga

pixamoon's picture

`

but I'm not sure if faster.
because it has to find all items in array by random shots. plus find if they not exist in second array.
It can take sec but it can freeze max too.

What you think ?

Best,
Pixamoon

PS. to not freeze max is good to use timestamp() inside of while and let it run only for max 1s (or more)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.