Home Technical Talk

[MaxScript] Select Polygons by material - need help

polycounter lvl 13
Offline / Send Message
csprance polycounter lvl 13
-- 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?

Replies

  • Noors
    Options
    Offline / Send Message
    Noors greentooth
    You need to collect obj, and not o :)
    objarr = for obj in objects where obj.material == meditMaterials[medit.getActiveMtlSlot()] collect obj
    
    If you already give the mat to the function tho, i'm not sure why you put it in the medit.

    If you just want to get objects that have the currently selected mat in the medit, you just need that
    function assignMatId count = 
    (       
       objarr = for obj in objects where obj.material == meditMaterials[medit.getActiveMtlSlot()] collect obj
        --considering objects are editable poly...
       for obj in objarr do polyop.setFaceMatID obj #{1..obj.numfaces} count  
    )
    
    if you already know the mat, you just need that
    function assignMatId mat count = 
    (       
       objarr = for obj in objects where obj.material ==  mat collect obj 
      --considering objects are editable poly...
       for obj in objarr do polyop.setFaceMatID obj #{1..obj.numfaces} count  
    )
    
  • csprance
    Options
    Offline / Send Message
    csprance polycounter lvl 13
    Noors! You're the man! Thank you.
Sign In or Register to comment.