PDA

View Full Version : MAXSCript to Select by material ID?


stuh505
01-22-2005, 12:58 AM
The max utility panel is able to very quickly select material ID's...however, I did not see any meshops that would getFacesByMatID as I expected...is there a more efficient way to do it than what I am doing below? I ask because this hangs the computer for a number of seconds which is really annoying.


obj = selection[1] --get selected object
newFaceSel = #() --empty bitarray
for f = 1 to obj.numfaces do
(
if getFaceMatID obj f==spn_Select.value do
(
append newFaceSel f
)
setFaceSelection obj newFaceSel
)

Bobo
01-27-2005, 12:11 AM
The max utility panel is able to very quickly select material ID's...however, I did not see any meshops that would getFacesByMatID as I expected...is there a more efficient way to do it than what I am doing below? I ask because this hangs the computer for a number of seconds which is really annoying.

I think that unfortunately you have to loop yourself through all faces.

Your script has a severe error though!


obj = selection[1]
newFaceSel = #()
for f = 1 to obj.numfaces do
(
if getFaceMatID obj f==spn_Select.value do
(
append newFaceSel f
)--end if
setFaceSelection obj newFaceSel --THIS IS VERY WRONG!
)--end f loop

As you can see, you are setting the selection as often as there are faces in the object! This causes the mesh to update the selection again and again, and it gets worse as the mesh density increases...

The last line should be outside of the for loop:

obj = selection[1]
newFaceSel = #()
for f = 1 to obj.numfaces do
if getFaceMatID obj f== 1 do append newFaceSel f
setFaceSelection obj newFaceSel --set the selection when the loop is done!

The above code selected 180754 out of 262144 faces (64 segments Teapot) in about 500 miliseconds (half a second!) on my machine.

In contrast, you code worked on the same mesh for about 10 minutes before crashing...

See what a single misplaced bracket can do ;)

stuh505
01-27-2005, 09:58 PM
eh...hehe...thanks

CGTalk Moderation
01-27-2006, 10:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.