Rename Object to Group name

I have a scene with with 1,400 single objects each within it's own group. the objects are named object001. 002,003 etc etc, and the group has the name I want the object to be.
Is this possible via maxscript ?

tia

Comments

Comment viewing options

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

Heroes are there

But you still can use "interactive renamer" from here in scriptspot.

crystal3d's picture

works on the whole scene

happy that i tested on a test scene,

can we get one that works on the selected group only?
and without numbers?

barigazy's picture

...

Or if you not like random unique name numbering then use this fn

fn renameGroupMembers groupNode &hendles sufix =
(
	if findItem hendles (hnd = (getHandleByAnim groupNode)) == 0 do
	(
		name = groupNode.name ; number = 0 ; append hendles hnd
		groupNode = getAllGroupMembers groupNode
		groupNode = for o in groupNode collect
		(
			if isgrouphead o then o else
			(
				o.name = name+sufix
				o.name += (formattedPrint (number += 1) format:"0.3d")
				dontcollect
			)
		)
		if groupNode.count > 0 do for g in groupNode do renameGroupMembers g &hendles sufix
	)
)

bga

pixamoon's picture

`

ha ! Thank you :)

barigazy's picture

o_O

Now you see what I talking about :)
Group topics are interesting and mind blowing in the same time :)

bga

pixamoon's picture

~

true true, thanks you for great examples to learn :)

barigazy's picture

...

Here is the solution.After you run this open Schematic View to see result

hendles = #()
groups = for g in objects where isGroupHead g collect g
fn isGroupHeadMember head node act:off = 
(
	while isvalidnode node and isgroupmember node and not (act = (node.parent == head)) do node = node.parent
	act
)
fn getAllGroupMembers head = if isgrouphead head do
(
	for node in (join #() head) where isGroupHeadMember head node collect node
)
fn renameGroupMembers groupNode &hendles sufix =
(
	if findItem hendles (hnd = (getHandleByAnim groupNode)) == 0 do
	(
		name = groupNode.name
		append hendles hnd
		groupNode = getAllGroupMembers groupNode
		groupNode = for o in groupNode collect
		(
			if isgrouphead o then o else
			(
				o.name = uniquename (name+sufix) ; dontcollect
			)
		)
		if groupNode.count > 0 do for g in groupNode do renameGroupMembers g &hendles sufix
	)
)
for g in groups do (renameGroupMembers g &hendles "_Object")
free groups ; free handles

bga

pixamoon's picture

`

This should make a job. Take a look.

for g in objects where isGroupHead g do (
	i = 1 
	for o in g where o != g do (
		no = case of (
			(i < 10):("00" + i as string)
			(i <100):("0" + i as string)
			default:(i as string)
		)
		o.name = g.name + no
		print o.name
		i += 1
	)
)

Best,
Pixamoon

AttachmentSize
rename_object_to_group_name.ms 254 bytes
barigazy's picture

...

The question is more complex if U need to consider group inside group.
Take look this thread where I and DenisT "wage a war" about groups. :)
http://forums.cgsociety.org/showthread.php?f=98&t=1224794
Also to get "no" variable in your for loop try eazy way

no = formattedPrint i format:"0.3d"

bga

pixamoon's picture

`

Thank you !
Still so much to learn :)

And yes, of course to groups inside groups... but it is just simple renaming tool base on group names

simplified code :

for g in objects where isGroupHead g do (
	i = 1 
	for o in g where o != g do (
		o.name = g.name + (formattedPrint i format:"0.3d")
		i += 1
	)
)

Comment viewing options

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