Script: Texture name to Material ID

Script: Texture name to Material ID

jeffpanek3d
Participant Participant
2,086 Views
7 Replies
Message 1 of 8

Script: Texture name to Material ID

jeffpanek3d
Participant
Participant
I came across this script which replaces the Multisub material's name with its texture name.
It works great, But unfortunately breaks if the material ID's are out of order or missing.
 
Is it possible to modify this to run under those conditions?
 
(
    SelMat = medit.GetCurMtl()
    nSbMats = SelMat.numsubs
    for j = 1 to nSbmats do
    (
    bitmp = getFilenameFile SelMat[j].diffusemap.filename
    SelMat[j].name = bitmp
    SelMat.names[j] =bitmp
    SelMat.material[j].diffusemap.name=bitmp
    )
)
 
Or if anyone has an equivalent script working with Max2016, that would be great too!
Thanks!
 
Jeff
0 Likes
Accepted solutions (1)
2,087 Views
7 Replies
Replies (7)
Message 2 of 8

Swordslayer
Advisor
Advisor
Accepted solution

Sure, and if by running under 2016+ you mean supporting the schematic material editor, I've added a switch for that too:

 

(
	local selMat = case matEditor.mode of
	(
		#basic : mEdit.getCurMtl()
		#advanced : SME.getMtlinParamEditor()
	)
	local matIDs = SelMat.materialIDList

	for id in matIDs do
	(
		local bitmp = getFilenameFile selMat[id].diffuseMap.filename
		selMat[id].name = bitmp
		selMat.names[id] = bitmp
		selMat[id].diffuseMap.name = bitmp
	)
)
0 Likes
Message 3 of 8

jeffpanek3d
Participant
Participant
Thanks, Swordslayer!
 
The script works great!!
Very much appreciated the time taken to make this.
 
Many thanks again!
 
Jeff
0 Likes
Message 4 of 8

system-core
Enthusiast
Enthusiast

I get an error in 2023

-- Error occurred in anonymous codeblock; filename: ; position: 160; line: 7
-- Unknown property: "materialIDList" in Map #1:Bitmap
-- MAXScript callstack:
--	thread data: threadID:18884
--	------------------------------------------------------
--	[stack level: 0]
--	In anonymous codeblock; filename: ; position: 161; line: 7
--		Locals:
--			selMat: Map #1:Bitmap
--			matIDs: undefined
--		Externals:
--	------------------------------------------------------
--	[stack level: 1]
--	called from top-level
0 Likes
Message 5 of 8

dmitriy.shpilevoy
Collaborator
Collaborator

Script doesn't check everything that can go wrong so it's on you to run it in proper conditions.

Make sure you have multisub selected.

0 Likes
Message 6 of 8

system-core
Enthusiast
Enthusiast

I have a Physical Material assigned to the object, I've tried with a Standard and Multi-Sub material the material slot name doesn't change to the bitmap name. There is not much information to what the issue is something on this line is not right. How can I figure out what?

local matIDs = SelMat.materialIDList

 

0 Likes
Message 7 of 8

dmitriy.shpilevoy
Collaborator
Collaborator

There is no materialIDList property in SelMat, and SelMat is current selection in material editor. In your error message you have

selMat: Map #1:Bitmap

I guess that's what you have selected instead of multisub.

0 Likes
Message 8 of 8

system-core
Enthusiast
Enthusiast

I did use a script years ago which gave the material the same name as a diffuse texture bitmap, I can't remember what it was though.

0 Likes