Multimaterial issue

I am trying to a script, which will work on all geometries, separate them into separate objects based on material ids so that each resulting objects will have single material (not multimaterial).....here is the script upto now:

(
-- Collect objects from scene in working list
workingObject = #()

for o in Geometry do
(
append workingObject o
)

fn detachFBI obj =
(
objname = obj.name
ids = obj.material.materialIDList

for id in ids do
(
obj.selectbymaterial id
_faceSel = polyOp.getFaceSelection obj

polyOp.detachFaces obj _faceSel delete:true asNode:true name: (objname +"_tempdelface")
)

select $*_tempdelface*
$.name = objname
)

-- Run though all objects in array and detach them
for o in workingObject do
( mat = o.material
if (classof mat == Multimaterial) do
(
select o
detachFBI o
)
)
)

.......its working fine....but the resulting objects are still having the multimaterials assigned to them....whereas I want them to have only the single material. Any clue???

Comments

Comment viewing options

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

Hi Goonda... Try

Hi Goonda...

Try this...

workObj = for o in geometry collect o
 
fn detachFBI obj =
(
	ids = obj.material.materialIDList
	matMulti = for i in obj.material collect i
 
	for id in ids do
	(	
		objName = obj.name + "_id_" + (id as string)
		obj.selectbymaterial id
		faceSel = polyOp.getFaceSelection obj
		if faceSel.isEmpty != true then (
			polyOp.detachFaces obj faceSel delete:true asNode:true name:objName 
			prov = getNodeByName (objName)
			if prov != undefined then prov.material = matMulti[id]
		)
	)
)
 
for o in workObj do	
	(
		if (classof o.material == Multimaterial) do detachFBI o	
	)

kimarotta.com.br
3d Artist  

Goonda's picture

Thanks a lot Kimarotto!!

Thanks a lot Kimarotto!!

Comment viewing options

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