Replace ":" with "_" in object names with hotkey

Hey guys and girls,

first of all, i wish this beautiful community Merry Christmas and happy New Year, and all your wishes to come true in 2019, without too much effort. Now the question, hoping this wouldn't take much effort, neither:

I use small file saving tool that picks up random scene object name, and saves max file with that object's name as file name (for example "Teapot005.max").
But now i have constant problems with imported dwg files with layers, since in that case, object names get "Layer:" prefix. For example, if layer name is "Mur", object name after importing is "Layer:Mur" and this tool that i use shows an error, because of colon special character:

"File D:\KK\Layer:Mur.max is possibly corrupt. Would you like to try to resave?"

So it is not able to save Layer:Mur.max file because of colon special character.
Could you please help me with hotkey tool that would be able to replace all colon special characters in object names, with "_" characters on selected objects/groups? This way, the name of imported object would be Layer_Mur.max and the scene could be saved without problems.

I know there are several great renaming scripts here, like Universal Renamer, but i would like to use some simple, quick tool and assign a hotkey for it, as i import this kind of objects very often. As i said previously, i have these imported objects grouped sometimes, so it would be perfect if this character replacing tool could work on all selected objects, including objects in selected groups.

Thank you so much for your help, i really appreciate it.
Happy New Year everyone!
Igor

Comments

Comment viewing options

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

.

macroscript miauuFixObjectsNames
category:"miauu"
tooltip:"Fix objects names"
buttonText:"Fix objects names"
(
	if selection.count != 0 do
	(
		for o in selection do
		(
			oName = o.name
			for i = 1 to oName.count where (findstring oName[i] ":") != undefined do 
			(
				oName[i] = "_"
			) 
			o.name = oName
		)
	)
)

or this:

macroscript miauuFixObjectsNames
category:"miauu"
tooltip:"Fix objects names"
buttonText:"Fix objects names"
(
	if selection.count != 0 do
	(
		for o in selection do
		(
			while ((idx = findString o.name ":") != undefined) do ( o.name = replace o.name idx 1 "_" )
		)
	)
)
igamaximus's picture

Perfect and instant!

Hey Kostadin, Sergey,

this works perfectly and instantly with hotkey and groups, exactly as i want it!
I tried each one of your tools and each one works perectly, now the file can be saved every single time with this tool i use - no error messages anymore!

So great, thank you so much for your time helping me. I sincerely wish New Year to be helpful and generous to you as much as you are helpful to me for so many times here!

Thank you !

miauu's picture

.

Hi, Segrey!
Happy New Year to you too.
The jahman suggestion is the best so far, so you have to use it.

macroscript miauuFixObjectsNames
category:"miauu"
tooltip:"Fix objects names"
buttonText:"Fix objects names"
(
	if selection.count != 0 do
	(
		for o in selection do
		(
			o.name = substituteString o.name ":"  "_"
		)
	)
)
jahman's picture

.

or this

substituteString <source_string> <from_string> <to_string>

Returns a new string with all occurrences of <from_string> in <source_string> replaced with <to_string>. Available in 3ds Max 2008 and higher. Previously available in the Avguard Extensions.

Comment viewing options

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