converting to a single mesh by material

Hi!

Is there a script which convert meshes in a scene to a single mesh based on their material. For example I have 100 meshes with 5 materials assigned, as a result I should have 5 meshes.

Thanks in advance!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Chumazik's picture

Hi Anibus, Sorry if I seemed

Hi Anibus,
Sorry if I seemed to be demanding! Didn't mean to. It is always possible to convert primitives to meshes in a few cliks.
But anyway thanks a lot for your time! You saved a lot of mine!

Best regards!

Anubis's picture

well, the script is updated

well, the script is updated

my recent MAXScripts RSS (archive here)

Anubis's picture

Yes, according to your

Yes, according to your request I wrote the script for meshes only.
Okay, I am here in 40 C (104 F) heat and try to work :) ...
but I'll modified the script for you, maybe soon ...
At the moment you can use snapshot tool to convert your objects to mesh ;)

my recent MAXScripts RSS (archive here)

Chumazik's picture

Update: Oh, I have found why

Update:

Oh, I have found why it didn't work. I tested the script with simple boxes, but it handles only editable meshes. Maybe there is a point to make it work with primitives as well.
And again thanks a lot!

Chumazik's picture

Hi, Anubis! Thank you very

Hi, Anubis!

Thank you very much for attention!
While testing your script I always get the warning message - No meshes with material in selection! Tested in 3DS Max Design 2009 SP1.

Anubis's picture

I am not sure if there are

I am not sure if there are similar so I wrote a script from scratch.

(
	mtl = #() ; tmp = #() ; fin = #()
	sel = selection as array
	if sel.count > 0 do -- filter selection
		sel = for i in sel where classOf i == Editable_mesh \
			and i.material != undefined collect i
	if sel.count == 0 then
		messageBox "Selection is empty!" title:"Attach Mesh by Material"
	else
	(
		for i in sel do
			appendIfUnique mtl i.material
		for m in mtl do
		(
			tmp = for i in sel where i.material == m collect i
			append fin tmp
		)
		undo on
		(
			for i in fin do
			(
				trg = i[1]
				deleteItem i 1
				for j in i do
					meshop.attach trg j attachMat:#IDToMat condenseMat:true
			)
		)
	)
)

I hope this help
(p.s. - script works also with Multi/Sub-Object materials)

[EDIT] Ultimately I changed the code slightly and upload the script here:
http://www.scriptspot.com/3ds-max/attach-mesh-by-material

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.