ScriptSpot

Forum topic · Scripts Wanted

Rename multiple object (only mesh) with FileName

By adriengallinaro · 2018-12-12

Description

Hi Everyone.

At my company, Im working on the objects data base. It’s a big one : 17 500 .max files.

All my .max files have a good file name. By inside the files, I want the mesh to have the FileName.

I use “batch it max”. That allow me to run the following little script in every max file automatically :

SetSelectFilter 1
actionMan.executeAction 0 “40021” – Selection: Select All

$.name = maxFileName
$.name = trimRight $.name “.max”

When I have only one mesh in the file, no problem. it’s work.

But, when I have multiple mesh in the scene, the script goes wrong.

So, what can I add in the script if I want to rename multiple mesh with the same name ?

For exemple :

My filename is : test.max

in the file I want :

mesh1 : filename01
mesh2 : filename02
etc…

I really need your help. I can’t find any issues.

Thanks a lot

Adrien

Comments (1)

barigazy · 2019-01-10

This is the simple function for your problem


-- this FN affect all object in the scene
-- but u can change "type" argument ei. replace "objects" with geometries or selection or lights etc.
-- also depending on the number of objects on the scene your suffix counter will starts
-- for example if you have more then 1000 objects, first object wil have suffix counter 0001
fn renameObjects type:objects = if type.count > 0 do
(
	count = (type.count as string).count as string
	fName = getFilenameFile (maxFilePath + maxFileName)
	for i = 1 to type.count do
	(
		type[i].name = fName + formattedPrint i format:("."+count+"d")
	)
)
RenameObjects()