[Closed] string compare and convert to integer
Hello this is probably an easy solution but I cant seem to get it im wondering if there is a way to get the material number instead of the strings.
clearlistener()
for obj in geometry do(
print obj.material
)
so instead of it saying 01 – Default it would say 1
for example in a situation where I have the array
01 - Default
01 - Default
01 - Default
01 - Default
02 - Default
01 - Default
01 - Default
02 - Default
I need an array that says
1
1
1
1
2
1
1
2
the flaw is , when you have material without number at all…say : “woodOak” …thats only string no number at all. what do you want to do?
yeah I know this is why im wondering if there is a way to convert them to an integer, when I print out the materials they are done in the order that I need but I really wish I could get numerals from them for my binary script.
you can use
GetHandleByAnim mat;
to return a unique id for a material. BTW This Id is not safe across different max sessions.
so I was thinking this possibly if I were to make an numeral array of the current medit materials then I could somehow compare strings and create an array from the object materials.
Example of this~
OBJECTMATERIAL_array=#()
MEDITMATERIAL_array=#()
clearlistener()
for obj in geometry do(
append OBJECTMATERIAL_array obj.material
)
for MTL = 1 to scenematerials.count do(
MTERL = meditmaterials[MTL]
append MEDITMATERIAL_array MTERL
)
print OBJECTMATERIAL_array
print MEDITMATERIAL_array
so I would take MEDITMATERIAL_array and make whatever order its in it will be 1,2,3,4 etc and I compare the names of OBJECTMATERIAL_array and append those numbers accordingly.
Ive come up with an unorthodox solution but it works.
OBJECTMATERIAL_array=#()
MEDITMATERIAL_array=#()
clearlistener()
for obj in geometry do(
append OBJECTMATERIAL_array obj.material
)
for MTL = 1 to scenematerials.count do(
MTERL = meditmaterials[MTL]
append MEDITMATERIAL_array MTERL
)
for a = 1 to geometry.count do(
for b = 1 to MEDITMATERIAL_array.count do(
if OBJECTMATERIAL_array[a] == MEDITMATERIAL_array[b] then(
print OBJECTMATERIAL_array[a]
print b
)
)
)
the print of OBJECTMATERIAL_array is to show what material is currently applied to the geometry and the print of b is to show its current meditmaterial number