select by material...

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  09 September 2003
Unhappy select by material...

Hello,

I've been using Max for a while now and I've finally decided that 'all those little things' I do over and over again could be made easier. So (perhaps foolishly) I've started to try and learn MaxScript.

Basically, the script I've been trying to create should select all materials with a certain name, change the attributes of that material - opacity/diffuse/self illumination (so far, not problem). However, I then want to select all the objects that do not have that material applied (sort of 'select by material/invert'), and apply one material to them all.

So far the closest I've gotten to selecting by material type is Macro Recording the ActionMan for that option, however it still requires me to manually press 'invert' then 'ok'.

Also - my (poor poor) script currently requires the material to be in the active slot, is there anyway to choose the active slot by the material name?

Please be gentle with me - I'm an idiot.
__________________
SKETCHBOOK
MDI
moonjam.com
 
  10 October 2003
Re: select by material...

Quote: Originally posted by AJ_23
Hello,

I've been using Max for a while now and I've finally decided that 'all those little things' I do over and over again could be made easier. So (perhaps foolishly) I've started to try and learn MaxScript.

Basically, the script I've been trying to create should select all materials with a certain name, change the attributes of that material - opacity/diffuse/self illumination (so far, not problem). However, I then want to select all the objects that do not have that material applied (sort of 'select by material/invert'), and apply one material to them all.

So far the closest I've gotten to selecting by material type is Macro Recording the ActionMan for that option, however it still requires me to manually press 'invert' then 'ok'.

Also - my (poor poor) script currently requires the material to be in the active slot, is there anyway to choose the active slot by the material name?

Please be gentle with me - I'm an idiot.



Here is a function that will do the select invert using plain vanilla MAXScript without macroRecorder actions (sorry, I never use the recorder).

--Define a new function with a single parameter - the material not
--to be selected:
fn selectByMaterialInvert mat =
(
--Loop through all geometry objects and collect those that do
--NOT have the material passed to the function as parameter.
--Then select the result (read below for more info!)
select (for i in geometry where i.material != mat collect i)
)

--Call the function by passing the Material Editor material
--usually in slot 1 called "1 - Default". You can also use
--meditMaterials[1], but you asked about access by name
--The single quotes allow you to use spaces inside the name,
--# denotes a name value.
selectByMaterialInvert (meditmaterials[#'1 - Default'])


Some words about the for loop. We check only Geometry objects since they are the only ones that make sense (note that you can assign materials to other classes without any visible effect though).
The loop has a variabe 'i' which is assigned a single object on each loop iteration. The 'where' statement compares the .material property to the material passed to the function and only allows an object to be collected when the materials do not match (!= is 'not equal to').
Usually, you would collect the objects in a user variable first,
then select the collection. The code would be more readable that way and would look like

fn selectByMaterialInvert mat =
(
selArray = for i in geometry where i.material != mat collect i
select selArray
)

But since tha assignment to a variable costs memory and time, it is a good practice to remember that MAXScript is expression-based and can handle alot of things without assigning to variables. In addition, a one-liner always looks cooler
In this case, it evaluates all the code inside the brackets and the result of the evaluation is an array. Instead of defining a new variable, writing the array to the variable, then passing the variable to the 'select' function, you can pass the result of the expression directly to the select function and - voila! The objects that don't have the specified material will be selected.

If you have any question, please feel free to ask.

Cheers,
Bobo

Last edited by Bobo : 10 October 2003 at 03:05 AM.
 
  10 October 2003
Re: select by material...

Quote: Originally posted by AJ_23

Also - my (poor poor) script currently requires the material to be in the active slot, is there anyway to choose the active slot by the material name?



Oh yes, here is a way to select a material slot by name:

fn selectMeditSlotByName theName =
(
for i = 1 to 24 do
if meditmaterials[i].name == theName do
medit.setActiveMtlSlot i true
)

selectMeditSlotByName "6 - Default"
 
  10 October 2003
bobo,
is there any smart "put to scene" function?
__________________
[see.]
 
  10 October 2003
Bobo - you're a genius and a saint!

Thank you so much.
__________________
SKETCHBOOK
MDI
moonjam.com
 
  10 October 2003
Quote: Originally posted by AJ_23
Bobo - you're a genius and a saint!


 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:55 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.