object merge by material

object merge by material

Anonymous
Not applicable
910 Views
5 Replies
Message 1 of 6

object merge by material

Anonymous
Not applicable
hi,

i got 21000 objects in my scene and there are 1500 scenematerials.
i want to attach all objects with the same material applied.
in the end there should be 1500 objects.
i think it is not possible to do it manually for this quantity of objects (pick material - select objects by material - attach ...)
i think there should be a better maxscript solution ... i am really new to maxscript, so any help would be appreciated.

one way could be. replace objectname with materialname (they are unique) >> check if objectname is assigned multiple times >> if so >> select objects by this name >> attach >> if not it is already processed ... end of loop

thank you

regards sebastian
0 Likes
911 Views
5 Replies
Replies (5)
Message 2 of 6

Steve_Curley
Mentor
Mentor
Things to note...

If you managed to get 2 or more materials with the same name, this will fail. It assumes that the materials are Instanced to the objects.

Attaching that many objects is slow and fills up the Undo stack rapidly, which uses a lot of memory. The code attempt to mitigate those problems, but it means there is no going back once you have run the script. You MUST ensure your scene is saved before running it.


(
suspendEditing()
disableSceneRedraw()
with undo off
(
for m in sceneMaterials do
(
newObj = Editable_Mesh()
convertTo newObj Editable_Poly
newObj.name = "Object_" + m.name
for o in geometry where (o.material == m) do
polyOp.attach newObj o
centerPivot newObj
)
)
enableSceneRedraw()
resumeEditing()
)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 6

Anonymous
Not applicable
hi,

wow thank you for your fast response.
i think in principle this exactly what i need.
i run this on a simple test scene and getting an unknown system exception here.

polyOp.attach newObj o


any idea?

using max 2010
my test scene consits of 5 primitives and 2 scenematerials applied to those
so in the end there should be to editable polys

thank you!
0 Likes
Message 4 of 6

Steve_Curley
Mentor
Mentor
I can only assume that you somehow have a scene material which is not actually applied to any geometric objects.

You should end up with an Editable Poly object for each material in the scene. It should attach objects which are not already Editable Polys because the Attach method is supposed to automatically convert the object to a Polymesh, so a Box primitive or even an Editable Mesh object should attach just fine. The code does work here, so if the modified version below doesn't, then it will be difficult to work out what is wrong without having the actual scene to look at.


(
suspendEditing()
disableSceneRedraw()
with undo off
(
for m in sceneMaterials do
(
newObj = Editable_Mesh()
convertTo newObj Editable_Poly
newObj.name = "Object_" + m.name
objs = for o in geometry where (o.material == m) collect o
if objs.count > 0 then
(
for o in objs do
(
polyOp.attach newObj o
centerPivot newObj
)
)
)
)
enableSceneRedraw()
resumeEditing()
)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 6

Anonymous
Not applicable
thank you very very very much!!!
you saved my day 🙂 it is working ...

regards sebastian
0 Likes
Message 6 of 6

Steve_Curley
Mentor
Mentor
Cool - glad it helped. 🙂

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes