循环选择并将子对象附加在一起

Looping through Selection And attaching Child Objects Together

(

on execute do
(

    local AttachableObjectArray = #()
    local SelectedNodes = getCurrentSelection()
    local Idx = 1





            for object in SelectedNodes[Idx].children do 
            (                   
                append AttachableObjectArray object
            )       

                for i = 1 to AttachableObjectArray.count do
                    (           
                        polyop.attach attachableobjectarray[1] attachableobjectarray[i]

                        for j = 1 to AttachableObjectArray.count do
                        (
                            if attachableobjectarray.count <= j do
                            (
                                deselect SelectedNodes[Idx]

                            )
                        )

                    )
                    SelectedNodes = getCurrentSelection()
                    print SelectedNodes.count

)

这是我当前的脚本它可以工作但是一次只能在一个层次结构上工作我需要它循环遍历我的选择直到所有父子都附加到 彼此

问题: 父-----子-子-子 父-----子-子-子 当前脚本: Parent----Children-Attached Parent-----Child-Child-Child

父级是一个虚拟对象,盒子链接到虚拟对象

提前致谢

for obj in $/selection/* do -- use just the top-level nodes
(
    local children = join #() obj
    local childrenToAttach = for i = 2 to children.count where canConvertTo children[i] Mesh collect children[i]
    if childrenToAttach.count > 1 do convertToPoly childrenToAttach[1]
    for i = 2 to childrenToAttach.count do polyop.attach childrenToAttach[1] childrenToAttach[i]
)