[Closed] select last level of hierarchy objects
Hi everyone,
we are trying to import some mapped vrml models into max (several buildings, trees and ground planes).
Problem is, every triangle comes as a seperate object. We would like to write a script that selects us all of the triangles that are ‘grouped’ (in this case they are linked to a dummy) under one dummy and attach them to a single object.
Problem is, the whole scene is basically linked to upwards to a single object.
So the hirarchy looks a bit like this:
scene
-area
--street
---building_block_a
----house_a
-----walls_a
------triangle_1
------triangle_2
------triangle_3
-----roofs_a
------triangle_4
------triangle_5
------triangle_6
----house_b
-----walls_b
------triangle_1
------triangle_2
------triangle_3
-----roofs_b
------triangle_4
------triangle_5
------triangle_6
---building_block_b
----house_a
-----roofs_a
-----walls_a
----house_b
-----walls_b
-----roofs_b
and so on (with the triangles beeing edit mesh and everything else being dummy objects.
We would like to end up with a scene containing several buildings (each one as a single object).
So what we would need to do is:
select a dummy that has only edit_mesh as children
then select all of the childre
run script that attaches them to single object
go to next group with only edit mesh as children and do it all over
somehow we can’t quite get round on how to select only that helper with the mesh-children.
We always only manage to select either all of the dummys or all of the mesh objects but not the ones we actually need.
Can anyone point me in the right direction on how to only select the second to last level so to speak?
fn areOnlyMeshes list = list.count > 0 and
(
local only = on
for obj in list while only do only = iskindof obj Editable_mesh
only
)
fn collectDummiesWithMeshes =
(
for node in helpers where iskindof node Dummy and areOnlyMeshes node.children collect node
)
collectDummiesWithMeshes()
or if you want to check nested children as well :
fn collectDummiesWithMeshChildren all:off =
(
for node in helpers where iskindof node Dummy collect
(
children = if all then
(
children = join #() node
deleteitem children 1
)
else node.children
if areOnlyMeshes node.children then node else dontcollect
)
)
collectDummiesWithMeshChildren()
Thanks a lot. First answer did exactly what I wanted.
Im now trying to combine that with ivanisavichs clusterAttach but get the error
“Unable to convert: 2 to type: <node>” in the line
deleteItem objArr(j+1)
I assume it’s some error with the meshList = i.children that does not seem to produce the right type of array needed in the script, but I can’t fix it myself
see code:
fn areOnlyMeshes list = list.count > 0 and
(
local only = on
for obj in list while only do only = iskindof obj Editable_mesh
only
)
fn collectDummiesWithMeshes =
(
for node in helpers where iskindof node Dummy and areOnlyMeshes node.children collect node
)
function clusterAttach objArr =
(
j = 1
count = objArr.count
undo off
(
while objArr.count > 1 do
(
if classof objArr[j] != Editable_Poly then converttopoly objArr[j]
if classof objArr[j+1] != Editable_Poly then converttopoly objArr[j+1]
polyop.attach objArr[j] objArr[j+1]
deleteItem objArr(j+1)
j += 1
if (j + 1) > objArr.count then j = 1
)
)
return objArr[1]
)
dummyList = collectDummiesWithMeshes()
for i in dummyList do
(
meshList = i.children
clusterAttach meshList
)