How to know if a material's name is Exist? SDK(C++)

How to know if a material's name is Exist? SDK(C++)

xiaobin
Enthusiast Enthusiast
1,002 Views
9 Replies
Message 1 of 10

How to know if a material's name is Exist? SDK(C++)

xiaobin
Enthusiast
Enthusiast

When I create a new material, I need known Is the name unique. If I do not judge in advance, the system will create multiple materials with the same name.

0 Likes
1,003 Views
9 Replies
Replies (9)
Message 2 of 10

istan
Advisor
Advisor

Why you don't use ip->AssignNewName(Mtl *m)  ?

0 Likes
Message 3 of 10

xiaobin
Enthusiast
Enthusiast
This function will rename the new material whether or not it has the same name.
0 Likes
Message 4 of 10

istan
Advisor
Advisor

there's also a "NameMaker" class..

0 Likes
Message 5 of 10

denisT.MaxDoctor
Advisor
Advisor

@xiaobin wrote:

When I create a new material, I need known Is the name unique. If I do not judge in advance, the system will create multiple materials with the same name.


the only one safe way to do it is collect all material names (scene or any other material collection) and check new name against this list.

 

built-in 'new name' or 'unique name' logic was always broken in the MAX system (IMHO)

0 Likes
Message 6 of 10

istan
Advisor
Advisor

built-in 'new name' or 'unique name' logic was always broken in the MAX system (IMHO)

well, I use it often and nobody complained so far 😉

0 Likes
Message 7 of 10

denisT.MaxDoctor
Advisor
Advisor

here are examples of 'broken' logic:

# the system doesn't check for uniqueness names with numeric suffix

# the system always offers a new name for whether it is used in the scene or not

# the NameMaker works with only 'root' names, that makes it useless when you want to check a names with numeric suffix

0 Likes
Message 8 of 10

denisT.MaxDoctor
Advisor
Advisor
b0 = box material:(Standard name:#std)
b1 = box material:(Standard name:#std_01)

b0.mat.name
b1.mat.name

okMtlForScene b0.mat
okMtlForScene b0.mat

okMtlForScene returns TRUE for both materials but as you can see they both exist in the scene

 

0 Likes
Message 9 of 10

denisT.MaxDoctor
Advisor
Advisor
assignNewName b0.mat

it modifies the name but the original name was already unique for the scene...

 

is it not a 'broken' logic?

0 Likes
Message 10 of 10

denisT.MaxDoctor
Advisor
Advisor

check another example:

resetMaxFile #noPrompt 

for k=1 to 9 do 
(
	b = box material:(Standard name:("Material #" + (k+20) as string))
	format "% >> "b.mat.name
)

assignNewName objects[1].mat

objects[1].mat == objects[5].mat
objects[1].mat.name == objects[5].mat.name

 

0 Likes