Help with a simple renaming script

Lorem ipsum dolor Lorem ipsum dolor Lorem ipsum dolor Lorem ipsum dolor Lorem ipsum dolor

Comments

Comment viewing options

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

thanks barigazy, now it

thanks barigazy, now it worked perfectly in 3dsmax2013. I did not realize that the script WILL NOT WORK if you don`t have already a map named with the sufix (wood_SPEC.tga and wood_NORM.tga) inside the same folder of the original texture (wood.tga).

I will credit you on my game!

barigazy's picture

...

I saw the logic only that way. You can add also other map types to the same folder and adjust the script to work with theses also.

barigazy

barigazy's picture

...

I did'nt test this.

try(destroyDialog ::renameMaps)catch()
rollout renameMaps "rename Maps"
(
	local slots = #("Diffuse Map", "Specular Map", "Normal Map")
	local sufix = #("_DIFF", "_SPEC", "_NORM")
	local appendPath = pathConfig.appendPath
	group " _Sufix : " 
	(
		edittext et_diff "Diffuse   :" pos:[10,25] width:180 height:17 text:sufix[1]
		edittext et_spec "Specular :" pos:[10,45] width:180 height:17 text:sufix[2]
		edittext et_norm "Normal    :" pos:[10,65] width:180 height:17 text:sufix[3]
	)
	group " Add && Rename : "
	(
		checkbox cb_spec "Add Specular Map" pos:[10,110] checked:on
		checkbox cb_bump "Add Normal Bump" pos:[10,130] checked:on
		spinner spn_amount "Bump Amount:             " pos:[10,150] fieldwidth:60 range:[-999,999,100] type:#integer
	)
	button btn_doit "DO THE JOB!" pos:[4,170] width:192 height:35
	on cb_bump changed state do spn_amount.enabled = state
	on btn_doit pressed do
	(
		if selection.count == 0 then messageBox "Select Some Object!" title:"Warning" beep:off else
		(
			sufix = #(et_diff.text, et_spec.text, et_norm.text) ; array = #()
			for node in selection where node.mat != undefined do
			(
				if (material = getClassInstances Standardmaterial target:node).count != 0 do
				(
					for mat in material where mat.filterMapAmount != 17 do
					(
						if mat.diffuseMap != undefined and isKindOf mat.diffuseMap bitmapTex do
						(
							string = getFilenameFile mat.diffuseMap.filename
							mat.diffuseMap.name = string + sufix[1]
							ext = getFilenameType mat.diffuseMap.filename
							path = getFilenamePath mat.diffuseMap.filename
							if cb_spec.checked and doesFileExist (file = appendPath path (string + sufix[2] + ext)) do
							(
								mat.specularLevelMap = Bitmaptex name:(string + sufix[2]) filename:file
							)
							if cb_bump.checked and doesFileExist (file = appendPath path (string + sufix[3] + ext)) do
							(
								mat.bumpMap = Normal_Bump normal_map:(Bitmaptex name:(string + sufix[3]) filename:file)
								mat.bumpMapAmount = spn_amount.value
							)
						)
						mat.filterMapAmount = 17
						append array mat
					)
					array.filterMapAmount = 100
				)
			)
		)
	)
)
createDialog renameMaps 200 210 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

goldeneye007's picture

Thanks my friend, thanks for

Thanks my friend, thanks for trying to help me and sorry for taking your time.

Unfortunately, it did not work my friend, nothing happened.

I think i will go for the manual way instead of scripting.

Thanks.

barigazy's picture

...

This works fine in max2014
U need to write exact sufix name in text boxes for Specular and Normal map (not diffuse). Also in your folder if you have map "Wood" U need also "Wood_sufix" for specular and normal bump ("Wood_SPEC" and "Wood_NORM")
Script creates Bitmaptexture in specularlevel slot named "filename + _SPEC" and Normal Bump map where in Normal Map slot U can find Bitmaptexture named "filename + _NORM"

try(destroyDialog ::renameMaps)catch()
rollout renameMaps "rename Maps"
(
	local slots = #("Diffuse Map", "Specular Map", "Normal Map")
	local sufix = #("_DIFF", "_SPEC", "_NORM")
	local appendPath = pathConfig.appendPath
	group " _Sufix : " 
	(
		edittext et_diff "Diffuse   :" pos:[10,25] width:180 height:17 text:sufix[1]
		edittext et_spec "Specular :" pos:[10,45] width:180 height:17 text:sufix[2]
		edittext et_norm "Normal    :" pos:[10,65] width:180 height:17 text:sufix[3]
	)
	group " Add && Rename : "
	(
		checkbox cb_spec "Add Specular Map" pos:[10,110] checked:on
		checkbox cb_bump "Add Normal Bump" pos:[10,130] checked:on
		spinner spn_amount "Bump Amount:             " pos:[10,150] fieldwidth:60 range:[-999,999,100] type:#integer
	)
	button btn_doit "DO THE JOB!" pos:[4,170] width:192 height:35
	on cb_bump changed state do spn_amount.enabled = state
	on btn_doit pressed do
	(
		if selection.count == 0 then messageBox "Select Some Object!" title:"Warning" beep:off else
		(
			sufix = #(et_diff.text, et_spec.text, et_norm.text) ; array = #()
			for node in selection where node.mat != undefined do
			(
				if (material = getClassInstances Standardmaterial target:node).count != 0 do
				(
					for mat in material where mat.filterMapAmount != 17 do
					(
						if mat.diffuseMap != undefined and isKindOf mat.diffuseMap bitmapTex do
						(
							string = getFilenameFile mat.diffuseMap.filename
							mat.diffuseMap.name = string + sufix[1]
							ext = getFilenameType mat.diffuseMap.filename
							path = getFilenamePath mat.diffuseMap.filename
							if cb_spec.checked and doesFileExist (file = appendPath path (string + sufix[2] + ext)) do
							(
								mat.specularLevelMap = Bitmaptexture name:(string + sufix[2]) fileName:file
							)
							if cb_bump.checked and doesFileExist (file = appendPath path (string + sufix[3] + ext)) do
							(
								mat.bumpMap = Normal_Bump normal_map:(Bitmaptexture name:(string + sufix[3]) fileName:file)
								mat.bumpMapAmount = spn_amount.value
							)
						)
						mat.filterMapAmount = 17
						append array mat
					)
					array.filterMapAmount = 100
				)
			)
		)
	)
)
createDialog renameMaps 200 210 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

barigazy's picture

...

Adjust this example to suit your needs

try(destroyDialog ::renameMaps)catch()
rollout renameMaps "rename Maps"
(
	local slots = #("Diffuse Map", "Specular Map", "Normal Map")
	local sufix = #("_DIFF", "_SPEC", "_NORM")
	group " _Sufix : " 
	(
		edittext et_diff "Diffuse   :" pos:[10,25] width:180 height:17 text:sufix[1]
		edittext et_spec "Specular :" pos:[10,45] width:180 height:17 text:sufix[2]
		edittext et_norm "Normal    :" pos:[10,65] width:180 height:17 text:sufix[3]
	)
	group " Add && Rename : "
	(
		dropdownlist ddl_s "Source:" pos:[8,110] width:90 height:5 items:slots
		dropdownlist ddl_t "Target:" pos:[102,110] width:90 height:5 items:(for i = 2 to 3 collect slots[i])
	)
	button btn_doit "DO THE JOB!" pos:[4,150] width:192 height:35
	on ddl_s selected idx do (ddl_t.items = for n in slots where ddl_s.selected != n collect n)
	on btn_doit pressed do
	(
		if selection.count == 0 then messageBox "Select Some Object!" title:"Warning" beep:off else
		(
			sufix = #(et_diff.text, et_spec.text, et_norm.text) ; array = #()
			for node in selection where node.mat != undefined do
			(
				if (material = getClassInstances Standardmaterial target:node).count != 0 do
				(
					for mat in material where mat.filterMapAmount != 17 do
					(
						case ddl_s.selection of
						(
							1:
							(
								if mat.diffuseMap != undefined and isKindOf mat.diffuseMap bitmapTex do
								(
									string = getFilenameFile mat.diffuseMap.filename
									mat.diffuseMap.name = string + sufix[1]
									if ddl_t.selected == slots[2] then mat.specularLevelMap = (map = copy mat.diffuseMap ; map.name = (string + sufix[2]) ; map)
									else mat.bumpMap = (map = copy mat.diffuseMap ; map.name =  (string + sufix[3]) ; map)
								)
							)
							2:
							(
								if mat.specularLevelMap != undefined and isKindOf mat.specularLevelMap bitmapTex do
								(
									string = getFilenameFile mat.specularLevelMap.filename
									mat.specularLevelMap.name = string + sufix[2]
									if ddl_t.selected == slots[1] then mat.diffuseMap = (map = copy mat.specularLevelMap ; map.name = (string + sufix[1]) ; map)
									else mat.bumpMap = (map = copy mat.specularLevelMap ; map.name = (string + sufix[3]) ; map)
								)								
							)
							3:
							(
								if mat.bumpMap != undefined and isKindOf mat.bumpMap bitmapTex do
								(
									string = getFilenameFile mat.bumpMap.filename
									mat.bumpMap.name = string + sufix[3]
									if ddl_t.selected == slots[1] then mat.diffuseMap = (map = copy mat.bumpMap ; map.name = (string + sufix[1]) ; map)
									else mat.specularLevelMap = (map = copy mat.bumpMap ; map.name = (string + sufix[2]) ; map)
								)								
							)
						)
						mat.filterMapAmount = 17
						append array mat
					)
					array.filterMapAmount = 100
				)
			)
		)
	)
)
createDialog renameMaps 200 190 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

goldeneye007's picture

Hi my dear

Hi my dear friend,

WOW!

Thanks for taking your time to help me, i really don`t know how to thank you!

This is the perfect idea for a script, this is what i really wanted and need, but unfortunately, it did not worked my friend, i selected the object and clicked on the button DO THE JOB, but nothing happenned.

I am using 3dsmax 2009 64 bit, and the object i want to rename its maps has a multi-subobject material.

I can`t make any suggestions because i really don`t understand too much about maxscript.

But if you could help me untill we make this script work, i would be very grateful.

Best Regards,

Nidal Nijm.

barigazy's picture

...

Not understan.Can you explain a bit more?

barigazy

goldeneye007's picture

Hi man, Ok, i tested it on

Hi man,

Ok, i tested it on 3dsmax 2013 64 bit, it works, however, one thing is missing.

it copies the diffuse map to specular / bump slot, fine, however, what it changes, is the name of the submaterial to use the sufix, however, it does not change the bitmap name, like texture_SPEC.tga, it remains texture.tga in both slots (diffuse and specular).

If you could correct it for me, i would be very grateful, if not, i will also thank you for all this help you gave me.

barigazy's picture

...

If I undertand you correctley.
U have scene with some objects which have assigned material (Standard or Multimaterial with Standard submaterials) that have already assigned DiffuseMap (Bitmap Texture for example "wood.jpg"). Now you want to assigne in specular level slot new bitmap texture which is located in the same folder where is "wood.jpg" but map with sufix "_SPEC" ei. "wood_SPEC.jpg". Same for the bump map but with sufix "_NORM".
if I'm right then previous code is not useful at all and your explanation of what you want to accomplish is not well formulated.

barigazy

Comment viewing options

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