View Full Version : Combining all Objects that Share a Material?

 CronoC04 April 2008, 05:41 PMHi guys, Is there a way to combine several objects in a scene that use the same Material ID? Are there any scripts that could do that or any guidance would be greatly appreciated! Newton
erilaz
04 April 2008, 11:40 PM
Can you define what you mean by combine? Do you want them to be one object, grouped, booleaned etc.?

MoreInfoPlz
04 April 2008, 04:18 AM
This was the first script I've ever made like 2 years ago. From what I understand you want to attach all the geom with the same material.

for i = 1 to sceneMaterials.count do
(
f = for g in geometry where ( g.material == sceneMaterials[i]) collect g
convertToPoly f[1]
gCount = f.count - 1
for j = 1 to gCount do
(
polyop.attach f[1] f[2]
)
)

CronoC
04 April 2008, 05:17 PM
I'd like them to be attached to each other and then become 1 object. MoreInfoPlz I ran your script, and it gave me an error..

-- Runtime error: Attempt to access deleted scene object

Thank you though, I'll play around with it and see what I can figure out :)

MoreInfoPlz
04 April 2008, 07:14 AM
ah ok, so basically you just need to attach all the geometry in the scene.
geom = geometry as array
undefinedGeom = #()
convertToPoly geom[1]
for i = 2 to geom.count do
(
if(geom[i].material != undefined) then
(
polyop.attach geom[1] geom[i]
)
else
(
append undefinedGeom geom[i]
)

)
if undefinedGeom[1] != undefined then
(
convertToPoly undefinedGeom[1]
for i = 2 to undefinedGeom.count do
(
polyop.attach undefinedGeom[1] undefinedGeom[i]
)
)

This script combines all the objects and if there are undefined materials on the object it combines the undefined. Didn't thoroughly test it so it will most likely have bugs.

CGTalk Moderation
04 April 2008, 07:14 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1