Modifier property checking if exist or not

Hello everybody,

I’m a beginner considering Maxscript (and also new on this forum),
I'm trying to create a script that select objects by a material modifier.materiaID property
I found a few lines from a certain @Swordslayer (great thanks to him \m/ by the way) it works perfectly but to finalise it, I would add an option like
if the value set by user doesn't exist in all materialmodifier in the scene, script will show up a message box like "nothing match" or something :D

This is what I got now
Someone can help me please :)

rollout MtlID "MtlIDtools" width:281 height:158
(
spinner 'spn2' "" pos:[197,126] width:56 height:16 align:#left type:#integer range:[0,100,0]
on spn2 changed val do

(
local objs = #()
local mods = getClassInstances MaterialModifier
for m in mods where m.materialID == a do
(
if (a==val) then
(
join objs (refs.dependentNodes m)
select objs
)
else
(
messagebox "Nothing Match!"
)
)
)
)
createDialog MtlID

or juste a few which check if the materialID is used or not in the scene would be so cool
Thank you all

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

I don't have a proper scene to test so try this:

rollout MtlID "MtlIDtools" width:281 height:158
(
	spinner 'spn2' "" pos:[197,126] width:56 height:16 align:#left type:#integer range:[0,100,0]
	on spn2 changed val do
 
 
	local objs = #()
	local mods = getClassInstances MaterialModifier
	for m in mods where m.materialID == a do
	(
		if (a==val) then
		(
			join objs (refs.dependentNodes m)
-- 			select objs
		)
	)
	if objs.count == 0 do
	(
		messagebox "Nothing Match!"
	)
)
createDialog MtlID
rithox's picture

oh yeaah thank you ;) I tried

oh yeaah thank you ;)
I tried this and seems works fine but not sure if it is the best way :D

rollout MtlID "MtlIDtools" width:281 height:158
(
spinner 'spn1' "" pos:[197,126] width:56 height:16 align:#left type:#integer range:[0,100,0]
on spn1 changed val do
(
local objs = #()
local mods = getClassInstances MaterialModifier
for m in mods do
(
if (m.materialID == val ) then
(
join objs (refs.dependentNodes m)
select objs
)
)
--if not then deselect all and show up message
if (objs.count < 1) then
(
messagebox "Nothing Match!"
deselect $*
)

miauu's picture

.

Why do you need to select the objs?

rollout MtlID "MtlIDtools" width:281 height:158
(
	spinner spn1 "" pos:[197,126] width:56 height:16 align:#left type:#integer range:[0,100,0]
 
	on spn1 changed val do
	(
		local objs = #()
		local mods = getClassInstances MaterialModifier
		for m in mods do
		(
			if (m.materialID == val ) then
			(
				join objs (refs.dependentNodes m)
				--	"why you need the next line?"
-- 				select objs
			)
		)
		--if not then deselect all and show up message
		if (objs.count < 1) then
		(
			messagebox "Nothing Match!"
			max select none
		)
	)
)
createDialog MtlID
rithox's picture

Since I can't select object

Since I can't select object by material ID on a Multi-sub material, I thought of this script,
It scan and select all the object with a specific materialID assigned on it
I usually works with poly select + material modifier instead of collapsing all to an editable poly or mesh to keep my mod dynamic (line+shell...) and lightweight max file
I don't know if it is the best way to work but that is how I did till now
Let me know if you have a suggest ;)
Cheers and mega thanks to you @miauu

miauu's picture

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.