ScriptSpot

Forum topic · Scripts Wanted

Rename texture name

By SmallGhost · 2011-06-13

Description

The scene have many textures, but the texture name is not correct. I want to rename the textures, and the link of texture should be keep!

I'm sorry for my bad english,I wish you can understand it.

Can someone help me? So thanks!

Comments (12)

Corona Bitmap Support

3dwannab · 2016-12-23

[code]--Script to rename paths of bitmap textures in a scene.
try(destroyDialog ro_bmRename)catch()
rollout ro_bmRename "Single edit Bitmap filepaths or do a search & replace on all (case insensitive)" width:906 height:495
(
local arrBMs = #()
local arrPaths = #()
combobox cbx_bm "Bitmap Filepaths" pos:[6,5] width:890 height:31
button btn_get "Get Bitmaps in Scene" pos:[5,449] width:124 height:40
checkbutton ckb_edit "Enable Edit" pos:[134,449] width:140 height:40
edittext edt_s "Search for:" pos:[323,450] width:439 height:16 enabled:false
edittext edt_r "Replace with: " pos:[323,472] width:439 height:16 enabled:false
button btn_rep "Do for All" pos:[769,449] width:132 height:40 enabled:false
button btn_swap "Swap" pos:[279,449] width:40 height:40

fn update_list=
(
arrBMs = #()
arrPaths = #()
arrCoronaBMs = getClassInstances coronaBitmap
for o in arrCoronaBMs do append arrPaths o.filename
arrBMs = getClassInstances bitmapTexture
for o in arrBMs do append arrPaths arrBMs[i].filename
cbx_bm.items = arrPaths
)--end fn

on cbx_bm entered txt do
(
if ckb_edit.checked do
(
arrBMs[cbx_bm.selection].filename = txt
update_list()
)--end if
)--end on
on btn_get pressed do
(
update_list()
)--end on
on ckb_edit changed state do
(
if state then
(
edt_s.enabled = true
edt_r.enabled = true
btn_rep.enabled = true
)--end if
else
(
edt_s.enabled = false
edt_r.enabled = false
btn_rep.enabled = false
)--end else
)--end
on btn_swap pressed do
(
temp = edt_s.text
edt_s.text = edt_r.text
edt_r.text = temp
)--end on
on btn_rep pressed do
(
local searchFor = edt_s.text
local replaceWith = edt_r.text
if searchFor != "" AND replaceWith != "" then
(
--loop through object names:
for i=1 to arrBMs.count do
(
local startIndex = findString arrBMs[i].fileName searchFor -- returns the starting index of the found string

if startindex != undefined do
(
-- replace the string at "startIndex" with length of "searchFor.count" with "replaceWith"
arrBMs[i].fileName = (replace arrBMs[i].fileName startIndex searchFor.count replaceWith)
)--end if
)--end for
update_list()
)--end if
else displayTempPrompt ">>>>>> Fill in what to search for and what to replace with! <<<<<<<" 5000
)--end on
)
createDialog ro_bmRename[\code]

Kudla · 2017-01-06

Hi thats excatlu what Im looking for but dosnt work.....it says

-- Syntax error: at bad, expected
-- In line: createDialog ro_bmRename[\c

Can I use it for 3dsmax 2016 and corona 1.5

thx for hrlp

Ill formatting of the post

3dwannab · 2017-01-06

Remove

[\code]

from the end of the code posted above.

Yes. It should a straight forward script there's little that can go wrong. Credit to the OP. I just made that edit for Corona.

okay , what he wants is...

crystal3d · 2012-03-16

actually what i want too...
is

the script to rename all bitmaps renamed to "scene name"+ extension.
i.e.
pine_tree.max has some mesh and two textures.
leaf.bmp
leaf2.bmp

he wants a script to do some actions so the result will become:

pine_tree.max
pine_tree.bmp
pine_tree2.bmp.

and materials target the new bitmap names...so they wont report as missing.

rename w/o relink, right?

Anubis · 2012-02-22

I re-read 2-3 times the original question:

"I want to rename the textures, and the link of texture should be keep!"

and looks like all replies below are about Relinking texture #FileNames.
--Here is 2 staffs:

<TextureMap>.name
assignNewName <TextureMap>

And as you say

"the texture name is not correct"

, then give more details about.

good subject, you want to turn an untidy scene into a tidy scene

crystal3d · 2012-02-21

like evermotion's scenes...
dont have a solution for you however...

SmallGhost · 2011-06-17

Thanks br0t!

I will try it.

SmallGhost · 2011-06-17

I have try it,but the file name is not change, how to set it?

br0t · 2011-06-17

Dont really know if this is what you want but maybe it helps:


--Script to rename paths of bitmap textures in a scene.
try(destroyDialog ro_bmRename)catch()
rollout ro_bmRename "Single edit Bitmap filepaths or do a search & replace on all (case insensitive)" width:906 height:495
(
	local arrBMs = #()
	local arrPaths = #()
	combobox cbx_bm "Bitmap Filepaths" pos:[6,5] width:890 height:31
	button btn_get "Get Bitmaps in Scene" pos:[5,449] width:124 height:40
	checkbutton ckb_edit "Enable Edit" pos:[134,449] width:140 height:40
	edittext edt_s "Search for:" pos:[323,450] width:439 height:16 enabled:false
	edittext edt_r "Replace with: " pos:[323,472] width:439 height:16 enabled:false
	button btn_rep "Do for All" pos:[769,449] width:132 height:40 enabled:false
	button btn_swap "Swap" pos:[279,449] width:40 height:40
	
	fn update_list=
	(
		arrBMs = #()
		arrPaths = #()
		arrBMs = getClassInstances bitmapTexture
		for i=1 to arrBMs.count do
			append arrPaths arrBMs[i].filename
		cbx_bm.items = arrPaths
	)--end fn
	
	on cbx_bm entered txt do
	(
		if ckb_edit.checked do
		(
			arrBMs[cbx_bm.selection].filename = txt
			update_list()
		)--end if
	)--end on
	on btn_get pressed do
	(
		update_list()
	)--end on
	on ckb_edit changed state do
	(
		if state then
		(
			edt_s.enabled = true
			edt_r.enabled = true
			btn_rep.enabled = true
		)--end if
		else
		(
			edt_s.enabled = false
			edt_r.enabled = false
			btn_rep.enabled = false
		)--end else
	)--end
	on btn_swap pressed do
	(
		temp = edt_s.text
		edt_s.text = edt_r.text
		edt_r.text = temp
	)--end on
	on btn_rep pressed do
	(
		local searchFor = edt_s.text
		local replaceWith = edt_r.text
		if searchFor != "" AND replaceWith != "" then
		(
			--loop through object names:
			for i=1 to arrBMs.count do
			(
				local startIndex = findString arrBMs[i].fileName searchFor -- returns the starting index of the found string
	
				if startindex != undefined do
				(
					-- replace the string at "startIndex" with length of "searchFor.count" with "replaceWith" 
					arrBMs[i].fileName = (replace arrBMs[i].fileName startIndex searchFor.count replaceWith)
				)--end if
			)--end for
			update_list()
		)--end if
		else displayTempPrompt ">>>>>> Fill in what to search for and what to replace with! <<<<<<<" 5000
	)--end on
)
createDialog ro_bmRename

To see bitmap names, press the "Get.." Button. To edit them, enabled the checkbox. You can then select single bitmap filepaths in the list and change them on top. The changes will be accepted when you leave the edit field with your mouse.
You can also do a search and replace on all paths, e.t. to change "C:\" to "D:\"
or "silly.jpg" to "dummy.tif"
This is case insensitive, which might not be so good.
Be careful with it, better save to a new scene first before you accidently kill any paths.
Cheers

So thanks for your help!

SmallGhost · 2011-06-20

I test it...

Yes,the bitmap name is changed,but the bitmap lost the link. The bitmap which is saved in disk is not changed name with it.

theMaps = getClassInstances BitmapTexture
for i in 1 to theMaps.count do
(
fileName = theMaps[i].filename
newFilename = getFilenamePath fileName + "\\map_" + i as string + getFilenameType fileName
if renameFile fileName newFilename then theMaps[i].filename = newFilename
)

this is someone help to change the bitmap name,but it can't change others except the diffuse channel....

Thank you for your help!

Nice Script

aj2jjworld · 2015-06-05

Hey, i use this script. and it really work for me. script change all jpg name according to me. but in max only. but its fine and i change name with advance rename. ALL OVER VERY GOOD SCRIPT. Save lots of time.