-- this function selects polygons assigned to mat and assigns a matid of count
-- mat is the mat to select the polys by and count is the mat id to assign to the polys
function assignMatId mat count = (
-- set the mat into meditMaterials in the second slot
meditMaterials[2] = mat
-- set the second slot to the active one
medit.SetActiveMtlSlot 2 true
-- select the polys assigned to mat
objarr = for obj in objects where obj.material == meditMaterials[medit.getActiveMtlSlot()] collect o
--assign selected polys a matid of count
--.. still writing this code
)
This is the function I'm trying to write. However I'm currently stuck on the select the polys assigned to mat. So my question is:
How would I given a selected material (activeSlot in meditMaterials) select all the polys with that material assigned to them. There may be multiple objects the material is assigned to, so it needs to select into other editable poly objects as well.
Any thoughts on where to start?
function assignMatId mat count = (
--collect all of our objects that are editable polys
objs = for x in $* where classOf x == PolyMeshObject collect x
-- collect all of our objects where the material is the same as the mat
objarr = for obj in objs where obj.material == mat collect obj
-- go through and assign the correct mat id
for obj in objarr do polyop.setFaceMatID obj #{1..obj.numfaces} count
)
I got it.