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
Forum topic · General Scripting
By asymptote · 2015-03-23
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
Heroes are there
ratatouille · 2020-03-08
But you still can use "interactive renamer" from here in scriptspot.
works on the whole scene
crystal3d · 2020-02-23
happy that i tested on a test scene,
can we get one that works on the selected group only?
and without numbers?
barigazy · 2015-03-24
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
)
)
`
pixamoon · 2015-03-24
ha ! Thank you :)
o_O
barigazy · 2015-03-24
Now you see what I talking about :)
Group topics are interesting and mind blowing in the same time :)
~
pixamoon · 2015-03-24
true true, thanks you for great examples to learn :)
barigazy · 2015-03-24
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
`
pixamoon · 2015-03-23
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
barigazy · 2015-03-23
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"
`
pixamoon · 2015-03-24
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
)
)
`
pixamoon · 2015-03-24
how about this ?
To rename all object inside, inside ... groups by main group name
-- firts rename all by group witout numbers
for g in objects where isGroupHead g do
for o in g do o.name = g.name
-- collect unique names array
uNames = #()
for o in objects where isGroupHead o == false do appendifunique uNames (o.name as name)
uNumbers = #()
for i = 1 to uNames.count do uNumbers[i] = 0
--add numbers to the same names
for o in objects where isGroupHead o == false do (
if (a = findItem uNames (o.name as name)) > 0 then (
uNumbers[a] += 1
o.name = o.name + (formattedPrint uNumbers[a] format:"0.3d")
)
)
Just quick idea... please test it and let me know how it works.
Best,
Pixamoon
barigazy · 2015-03-24
I will use example of previous mentioned thread by DenisT.
Here you have groups inside group and some of theses are just linked to each other.
(
f0 = box name:"f0" pos:[80,40,0] wirecolor:orange
in f0 (f1 = box name:"f1" pos:[80,80,40] wirecolor:orange)
in f1 (f2 = box name:"f2" pos:[80,80,0] wirecolor:orange)
c0 = box name:"c0" pos:[40,40,0] wirecolor:orange
c1 = box name:"c1" pos:[40,80,40] wirecolor:orange
c2 = box name:"c2" pos:[40,80,0] wirecolor:orange
b0 = box name:"b0" pos:[40,0,0] wirecolor:orange
b1 = box name:"b1" pos:[80,0,0] wirecolor:orange
b2 = box name:"b2" pos:[40,40,0] wirecolor:green
b3 = box name:"b3" pos:[80,40,0] wirecolor:green
g4 = group #(c1,c2) name:"g4"
g0 = group #(b0,b1) name:"g0"
g4.parent = b0
g1 = group #(b2,b3,g0) name:"g1"
g2 = group #(c0, g1) name:"g2"
in b0 (box name:"d0" pos:[0,0,80] wirecolor:blue)
in g0 (box name:"d1" pos:[0,0,120] wirecolor:blue)
a0 = box name:"a0" pos:[0,40,80]
a1 = box name:"a1" pos:[0,80,80]
g3 = group #(a0,a1) name:"g3"
g3.parent = g2
g5 = group #(f0,f1,f2,g2) name:"g5"
for g in #(g0,g1,g2,g3,g4,g5) do setGroupOpen g on
)