Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Selecting Polygons by Material ID
  RSS 2.0 ATOM  

Selecting Polygons by Material ID
Rate this thread
 
24632
 
Permlink of this thread  
avatar
  • Total Posts: 13
  • Joined: 19 March 2009 12:00 AM

Hi,

I’m working on a script which will run through a model and detach polygons based on the Material ID that is assigned to them.

macroscript Jeff category:"Dazza"
(
    
on isEnabled return 
    (
        
selection.count == and classOf selection[1].baseobject == Editable_Poly
    
)

    
on execute do
    (
        
max modify mode
        local obj 
= $
        
select obj
        max modify mode
        subobjectlevel 
4
        obj
.ButtonOp #SelectByMatID

    
)
)

So far my script is only looking to simply select the Polygons that have a certain material ID. My script seems to work, but only selects material ID 1. I need to know how I can change the Material ID it is selecting so it can loop through all the materials that are assigned to a model.



Max 2010 (SP1), Windows Vista 64bit
NVIDIA Quadro FX 1600M, 4GB RAM

Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

This has to be some kind of record - 3 threads on detaching polys in 2 days… :-)
I really would stay away from “automated button pressing” if you can - straightforward scripting is much easier to deal with.

(
local MatID 1
    
while (polyop.getNumFaces $ > 0) do
    (
    $.
selectByMaterial MatID
    polyList 
polyop.getFaceSelection $
    
    if (
polyList.count 0) do
        (
        
newName = (uniquename "DetachedObject")
        
polyOp.detachfaces polyList delete:true asnode:true name:newName    
        
)
    
MatID += 1
    
)
)


Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 0
avatar

Thanks Steve, does exactly what I needed it to do. Still getting my head around Maxscript. I’m trying to create a super script that will run through a whole scene, attach everything together, detach by mat id, add a uvw unwrap to each object, flatten uvws, then work out the surface area of the polys to prep for a lightmap, and hopefully automate all the lightmap renders so I can walk away.

I’ll no doubt be back soon when I get stuck on the next bit.

Thanks again,

Darren.



Max 2010 (SP1), Windows Vista 64bit
NVIDIA Quadro FX 1600M, 4GB RAM

Replies: 1
/userdata/avatar/234tptgj3_159515783649ebfe783a8f3.png

Did you ever finish this superscipt? It’s what I need as well.

Author: IonDave

Replied: 09 December 2009 08:31 AM  
avatar

Bumped the wrong thread.



Max 2010 (SP1), Windows Vista 64bit
NVIDIA Quadro FX 1600M, 4GB RAM

Replies: 0