[Closed] filter materials by name?
kinda of a noob at this, cant seem to get this to work – also I am not getting any responses from the listed from my print function, where is this going wrong. I am basically looking through the material scene slots checking their names. 1st the names should be inputXXXX where X is a number. So the first thing I try to pass is whether it is defined or not, next I pass whether it has input in the 1st 5 letters of the name and lastly if the last 4 numbers are ints. Then count them and report to the listener but its not doing anything.
Global input
fn getMeditSlotByName getname =
(
for i = 1 to 24 do
if meditmaterials[i].name == getname do
(
if getname != undefined and substring getname 1 5 == "input" then
(
namenumber = substring getname 6 9
for i in namenumber do
(
if namenumber <= 9999 then
(
list = getname.count as string
print list
)
)
)
)
)
You have a series of problems…
if getname != undefined and substring getname 1 5 == "input" then
Will not work as expected, as the substring function is not been given the chance to work and will most likely produce some weird compile error at the least, or some weird output at the worst.
It should read...
if getname != undefined and (substring getname 1 5) == "input" then
Maxscript is a fickel mistress, it likes to be treated right...
Also namenumber is string, comparing a string to an integer will always fail...
"999" == 999 -- is false
For me, the for loop also failed...you simply can not loop through a string like this...You'd have to
for index = 1 to namenumber.count do (
i = namenumber[index]
)
But to be honest, I don't know why you are trying to loop anyway, you don't even use "i"
This should do what you want
namenumber = substring getname 6 9
if (intvalue = (namenumber as integer)) != undefined and intvalue <= 9999 then
(
list = (getname.count as string)
print list
)
Note, that converting a string to integer will return undefined if there are any non-numerical characters at all in the string!
It would be worth while adding some additional print statements to check the string value at each stage while you are at it.
Hope this helps some…
Shane
Ohh thanks, that makes more sense, I was simply wanting to know what materials are named input0001, input0002, etc. and if they are I was going to do stuff to them like shange diffuse and such, and if it isn’t then do something else.
I just wanted to count and print to the listener just to make sure I was reading the scenematerials correctly.
[edit]
It still seems to not be doing anything.
Global input
fn selectMeditSlotByName getname =
(
for i = 1 to 24 do
if meditmaterials[i].name == getname do
(
if getname != undefined and (substring getname 1 5) == input then
(
namenumber = substring getname 6 9
for index = 1 to namenumber.count do
(
i = namenumber[index]
if (intvalue = (namenumber as integer)) != undefined and intvalue <= 999 then
(
changemat = getname[index]
changemat.Diffuse = color 255 255 255
)
)
)
)
)
basically now that I identified all materials with inputXXX change the diffuse to white. So basically I want to grabb all of them and use the change. Sorry I am used to c++, normally the function would be called selectMeditSlotByName(), maybe I am not calling the function right? do I even need to define a function here? or can I just run it?
getname is a variable of the function. You have to supply something for getname or it won’t work. So selectMeditSlotByName “string” should work, the getname needs to be a string, there are other things you can do to fix somethings. Such as the if getname != undefined can be removed, since you are testing if the meditmaterial[i].name == getname. To move on in the script the meditmaterial[i].name will == getname so it will never be undefined in the next line. Also, is input a string or a variable? If you define i = namenuber[index] you need to call it somewhere. Also, you never define a value for intvalue so it will never == (not =) namenumber as integer. == test if to items are equal, while = sets a variable to a value. you should read through the maxscript documents for some more information before continuing on.
-Eric
Okay, now I’m confused…
fn selectMeditSlotByName getname =
(
for i = 1 to 24 do
(
-- This is a cheat, I'm basically say "does this start with input??"
if (findstring meditmaterials[i].name "input") == 1 then (
-- Get the material name for eaiser use...
local sName = meditmaterials[i].name
-- Convert the sufix to an integer
local iSufix = (substring sName 6 sName.count) as integer
-- Check how big the integer is
if iSufix != undefined and iSufix < 999 then (
format "Found %
" meditmaterials[i].name
)
)
)
)
selectMeditSlotByName ""
I rewrote the function so that it will search the material slot for all the materials starting with “input” and that have a numerical sufix less then “999” and it works for me
It may not do exactly what you want right now, but it is a start
Ahh thanks man!!! Its working now I am able to affect all materials by that name and inversely affect materials not by that name. It works great! I think I finally found out what [] means, and what it means to have it defined.
MaxScript is a fickel mistress. Even after 7 years of software development, she can do something that will throw me completely and leave me ask “why?”
But once you get over that, it can be a lot of fun…