How can I attach all the objects having same name in a scene??
Forum topic · General Scripting
Attaching same named objects
By Goonda · 2012-08-31
Description
Comments (4)
Try this code
barigazy · 2012-09-02
fn attachSameNameObj convertObjToPoly:off =
(
--filter function for geometry objects
fn filterGeo obj = (isKindOf obj GeometryClass and classof obj != TargetObject)
--collections of geo-objects
objArr = for obj in geometry where filterGeo obj collect obj
if objArr.count == 0 then (messagebox "No geometry objects on the scene!" title:"Warning" beep:false) else
(
while objArr.count > 1 do
(
local lastNode = objArr[objArr.count] --last node in array
for i = objArr.count-1 to 1 by -1 where lastNode.name == objArr[i].name do
(
-- check if base object is editable mesh (this is recomanded for attach operations)
if not isKindOf lastNode.baseobject Editable_mesh do (converttomesh lastNode)
attach lastNode objArr[i] --attach objects with same name
deleteItem objArr i -- remove attached item from objArr
)
-- place pivot at center
lastNode.pivot = lastNode.center
-- if convertObjToPoly is set to 'on' then convert attached object to poly or use default mesh
if convertObjToPoly do (convertToPoly lastNode)
-- remove last item from objArr
objArr.count = objArr.count-1
)
)
)
Goonda · 2012-09-03
Thanks Barigazy.....I have written something like this:
for o in geometry do
(
if classof o == editable_poly do
(
append newworking o
)
)
i = 1
while i <= newworking.count do
(
b = newworking[i]
j = i + 1
while j<= newworking.count do
(
if (newworking[j].name == b.name) then
(
b.attach (newworking[j]) b
deleteItem newworking j
select b
weldverts b
)
else
(
j = j +1
)
)
i = i + 1
)
Edit
barigazy · 2012-09-03
This is corrected code
newworking = for o in geometry where isKindOf o editable_poly collect o
i = 1
while i <= newworking.count do
(
b = newworking[i]
j = i + 1
while j <= newworking.count do
(
if (newworking[j].name != b.name) then j += 1 else
(
b.attach (newworking[j]) b
deleteItem newworking j
select b
weldverts b
)
)
i+=1
)
But your version is working only with epoly object.
My code works with any type of geometry except splines.
attach by name
joma · 2016-05-25
I have several meshes with similar names:
1_01
1_02
1_03
2_01
2_03
3_01
3_04
3_05
It's posible attach the meshes by initial names?
I get
1
2
3
thanks in advance