[Closed] Copying texture map
I am trying write a script that will go through and grab all my texture maps for the scene and copy them to a new folder.
the “usedmaps ()” command will return me all the maps in the scene. At this point I would like to copy the files to a new folder but I am stuck on how to proceed.
I am not sure if I would use the “copyfiles” command or “copy()”
and then how to save to a new directory.
Hopefully this makes sense
newdir = "C:\\New Folder\\"
maplist = usedmaps()
makedir newdir
for map in maplist do
(mapname = FilenameFromPath map
copyfile map (newdir+mapname)
)
Instead of the above approach I get my array of maps used in the scene by using the function getClassInstances BitmapTexture
and sort through
bmaps = getClassInstances BitmapTexture
local filesCopied = 0
for b in bmaps do (
local tmp_fileToCopy = ("C_" + b.fileName)
if (doesFileExist b.fileName) then (
copyFile b.fileName tmp_fileToCopy
filesCopied+=1
)
else (
format "File: % does not exist. Skipping.
" b.filename
)
)
another approach you might consider. Usedmaps() is great because you can call it on a specific object.
-Colin
I appreciate the replies I was busy the last couple of days and unable to get to this.
I jumped in and was trying to get the this working but I am still running into some problems.
I got this to work but I am running into the problem that the file is being saved out into 1 level up folder of my getsavepath.
what I mean is if my “getsavepath” is c:\document and settings\sethwolford\MyDoc then it saves the file in the “sethwolford folder”
I am including the code so that you can see what I mean and if there are any better ways to do it. I am still learning so I appreciate any and all help.
P.S. I realized that there was a script called “mapcollector” that does an excellent job of doing what I want but I figured this is a good opportunity to learn more
/*
usedmaps() --used to get
all the maps
*/
rollout textureexport "Texture Grab"
(
button a1 "..." width:16 height:16 pos:[275,20]
edittext ftext "folder Path" width:250 pos:[10,20]
button bmaps "Grab Scene Texures" width:200 pos:[50,50]
on a1 pressed do
(
f1 = getsavepath caption:"Export Folder" initialDir:"C:\Documents and Settings\seth wolford\My Documents\3dsmax\sceneassets" --change ths if have specfic drive or folder location all te time
if f1 == undefined then
(messagebox "Select New Folder Location")
else
(
ftext.text = (f1 as string)
)
)
on bmaps pressed do
(
newdir = ftext.text as string
maplist = usedmaps()
makedir newdir
for map in maplist do
(
mapname = FileNameFromPath map
copyfile map (newdir+mapname)
)
)
)
createdialog textureexport width:300 height:150
I actually just wrote this function to do just that!
fn getSubDirectoryName thePath = (
local my_arr = filterstring thePath "/\\"
local arr_length = my_arr.count
local newPath = ""
if (findString my_arr[arr_length] ".") == undefined then
newPath = my_arr[arr_length] -- The path ends with a directory
else
newPath = my_arr[arr_length-1] -- The path has a filename at the end
return newPath
)
fn getSubDirectoryPath thePath = (
local my_arr = filterstring thePath "/\\"
local arr_length = my_arr.count
local new_length = 0
local newPath = ""
if (findString my_arr[arr_length] ".") == undefined then
new_length = arr_length-1
else
new_length = arr_length-2
for i = 1 to new_length do (
newPath += my_arr[i] + "/"
)
return newPath
)
getSubDirectoryPath "c:\\documents and settings\\sethwolford\\MyDoc"
getSubDirectoryName "c:\\documents and settings\\sethwolford\\MyDoc"
That should help you out!