[Closed] Map name conflict
Hi, I recently wrote a copy and paste script, but I found a big problem. If there are two different material maps in the copied model, but the map name is the same, the paste will cause inaccurate map.
For example: the model “a” and “B” in the copy, the material of “a” has the map name “1. JPG”, and the material map name of “B” also has “1. JPG”, but the maps are not the same. At this time, the paste will have problems.
So how do you rename conflicting maps?
The easiest way to get an answer is to show your code and someone can help you fix it.
Here’s the code. Take a look
(
local MaxVer = (2000+(((maxVersion())[1]/1000.0)-2) as Integer)
fn CollectMap C_Map=
(
for a in selection do
(
Everything = usedMaps a
for b in Everything do
(
copyFile b( C_Map + (filenameFromPath b))
)
)
)
fn Copy_Files =
(
Makedir ("C:\\HG\\Copy")
MapPath = ("C:\\HG\\Copy\\")
MaxPath = ("C:\\HG\\Copy\\HG.max")
if selection.count > 0 then
(
-- create folder
MakeDir MapPath
-- delete file
files = getFiles ("C:\\HG\\Copy\\*.*")
for f in files do (deletefile f)
-- Collect maps
CollectMap MapPath
-- save max
if MaxVer > 2010 then
(
if MaxVer <= 2013 do
(
saveNodes $ MaxPath saveAsVersion:2010 quiet:true
)
if MaxVer >= 2014 do
(
saveNodes $ MaxPath saveAsVersion:(MaxVer-3) quiet:true
)
)
)else
(
queryBox "Please select the model before copying! "
)
)
)
as I can see from your code, you want to collect all used texture files in the specified folder.
but of course some files may have the same name despite the different file path.
the best I see is to add some unique identifier to the textura name, made from, for example, the original path. Commonly used for this CRC32…
we don’t have built-in crc32 in MXS, so we can try getHashValue for example:
fn renameFilename file hash:0 =
(
path = getfilenamepath file
name = getfilenamefile file
type = getfilenametype file
name + "_" + formattedPrint (getHashValue path hash) format:"010u" + type
)
/*
renameFilename @"C:\Users\all\Desktop\TEMP\adv_spline_ik.gif"
--- "adv_spline_ik_1709774516.gif"
*/
This is a good way, but it will slow down when copying a lot of files. Maybe you don’t want to add a unique identifier to so many map names.
My idea : when copying, get whether the selected map path name has a duplicate name. If there is a duplicate name map file, rename the file with the same name. In this way, a large number of map renames can be avoided…
It’s an idea, but I can’t do it…
You’re kidding? 10,000 renames take ~250ms on my machine … This means that renaming is nothing compared to looking up names for uniqueness.