[Closed] zip files by object names in scene
I have a bunch objects in the scene and a folder with an files with a same names as objects, so i need to collect in array object names and tell maxscript to zip files with the same name.
please help me
p.s.: i know about setting object names in array by
namesArray = for s in selection collect s.name
and also command could be like so:
ShellLaunch (scriptspath+"\ swbase\\7z.exe") @"a -mx9 -t7z ARCHIVE_NAME @listfile.txt"
Hi.
You don’t have to collect names in array, you can directly use them in the loop.
Code should look like that:
for object in selection do
ShellLaunch (scriptspath+"\ swbase\\7z.exe") @("a -mx9 -t7z " + object.name + " @listfile.txt")
actually i figured it out myself:
clearlistener ()
clearSelection()
try (destroydialog zip_rips) catch()
--global fpath="C:\\Users\1\\Documents\\_wrk\\18-ti-models\\07-fuel-truck\\sample\\"
global sourcedir = getSavePath
global out_path = maxfilepath
global file_ext = "rip"
global sevenz_fpath = scriptspath + "tswbase\\7z.exe" --7z.exe should be in ..\scripts swbase\ directory
global arch_cmnd = "a -mx9 -t7z"
global arch_prefix = "_source.7z"
global dq = "\"" --double quote character
global bs = "\\" --backslash characters
fn zrDefaultSettings =
(
sourcedir = ""
arch_name = ""
out_name = ""
out_file = ""
)
arch_name = MaxFileName --get max file name
if arch_name == "" then --if there is no name
arch_name = "Untitled" --use "Untitled"
else
arch_name = getFileNameFile arch_name+arch_prefix --use the file name without .MAX extension
rollout zip_rips "Rip Zipper"
(
group "Choose Dir then Zip"
(
--edittext EdTexPath "Path to materials" text:"fgdh" width:180 across:2
button dirselector "Choose Directory" align:#center height:16 width:100
button zipper "Zip Source Files" align:#center height:16 width:100 enabled:true
--checkbox ChkTexRecurse "Recurse" checked:false
--label LblMissingTex "On missing texture:" across:2
--radiobuttons RadMissingTex labels:#("do nothing", "ask") default:g_texMissAction align:#left columns:1
)
on dirselector pressed do
(
sourcedir = getSavePath caption:"Directory with .rip files" initialDir:out_path
if dir != undefined then
(
out_path = sourcedir
)
out_name = ((sourcedir)+(bs)+"process_file.cmd")
out_file = createfile out_name
max select all
for o in selection do
(
--property to export
format "%%% % %%%% %%%%.%%
" (dq) (sevenz_fpath) (dq) (arch_cmnd) (dq) (out_path) (arch_name) (dq) (dq) (sourcedir) (bs) (o.name as string) (file_ext) (dq) to:out_file
)
clearselection()
)
on zipper pressed do
(
HiddenDOSCommand "process_file.cmd" startpath:sourcedir prompt:"Waiting for process_file.cmd to exit" --donotwait:true
try (close out_file) catch()
--close out_file --No ""close"" function for undefined
destroydialog zip_rips
)
)
createDialog zip_rips 120 72 205 150
but this gives me an error every time i use it second time, so i have to reload it
I gusee that’s problem with globals. You can’t define already defined variable.
Now should works:
if sourcedir == undefined then
(
global sourcedir = getSavePath
global out_path = maxfilepath
global file_ext = "rip"
global sevenz_fpath = scriptspath + "tswbase\\7z.exe" --7z.exe should be in ..\scripts swbase\ directory
global arch_cmnd = "a -mx9 -t7z"
global arch_prefix = "_source.7z"
global dq = "\"" --double quote character
global bs = "\\" --backslash characters
--global fpath="C:\\Users\1\\Documents\\_wrk\\18-ti-models\\07-fuel-truck\\sample\\"
global sourcedir = getSavePath
global out_path = maxfilepath
global file_ext = "rip"
global sevenz_fpath = scriptspath + "tswbase\\7z.exe" --7z.exe should be in ..\scripts swbase\ directory
global arch_cmnd = "a -mx9 -t7z"
global arch_prefix = "_source.7z"
global dq = "\"" --double quote character
global bs = "\\" --backslash characters
)
I recomend you use more unique names for globals (or not use them if you really haven’t to). Other scripts can also use them and that will produce weird behaviour of your one.
thanks, i’ll try this at work
but why did you copy global block two times? i don’t get it
edit: btw, do you know how to prevent error when i close “open folder” dialog box after “Choose Directory” being pressed? something like “if then”?
error text:
>> MAXScript Rollout Handler Exception: -- No ""+"" function for undefined <<
and this is what i have so far, works fine, but only this error above annoys me:
clearlistener ()
clearSelection()
try (destroydialog zip_rips) catch()
if sourcedir_zr == undefined then
(
global out_path_zr = maxfilepath
global sourcedir_zr = getSavePath
global file_ext_zr = "rip"
global sevenz_fpath = scriptspath + "tswbase\\7z.exe" --7z.exe should be in ..\scripts swbase\ directory
global arch_cmnd_zr = "a -mx9 -t7z"
global arch_prefix_zr = "_source.7z"
global dq_zr = "\"" --double quote character
global bs_zr = "\\" --backslash character
)
fn zrDefaultSettings =
(
sourcedir_zr = ""
arch_name_zr = ""
out_name_zr = ""
out_file_zr = ""
)
arch_name_zr = MaxFileName
if arch_name_zr == "" then
arch_name_zr = "Untitled"
else
arch_name_zr = getFileNameFile arch_name_zr+arch_prefix_zr
rollout zip_rips "Rip Zipper"
(
group "Choose Dir then Zip"
(
button dirselector "Choose Directory" align:#center height:16 width:100
button zipper "Zip Source Files" align:#center height:16 width:100 enabled:true
)
on dirselector pressed do
(
sourcedir_zr = getSavePath caption:"Directory with .rip files" initialDir:sourcedir_zr
out_name_zr = ((sourcedir_zr)+(bs_zr)+"process_file.cmd")
out_file_zr = createfile out_name_zr
max select all
for o in selection do
(
--property to export
format "%%% % %%%%% %%%%.%%
" (dq_zr) (sevenz_fpath) (dq_zr) (arch_cmnd_zr) (dq_zr) (out_path_zr) (bs_zr) (arch_name_zr) (dq_zr) (dq_zr) (out_path_zr) (bs_zr) (o.name as string) (file_ext_zr) (dq_zr) to:out_file_zr
)
clearselection()
try (close out_file_zr) catch()
)
on zipper pressed do
(
HiddenDOSCommand "process_file.cmd" startpath:sourcedir_zr prompt:"Waiting for process_file.cmd to exit" --donotwait:true
try (close out_file_zr) catch()
)
)
createDialog zip_rips 120 72 205 150
Anton,
Try this:
on dirselector pressed do
(
sourcedir_zr = getSavePath caption:"Directory with .rip files" --initialDir:sourcedir_zr
if sourcedir_zr != undefined then
(
out_name_zr = ((sourcedir_zr)+(bs_zr)+"process_file.cmd")
out_file_zr = createfile out_name_zr
max select all
for o in selection do
(
--property to export
format "%%% % %%%%% %%%%.%%
" (dq_zr) (sevenz_fpath) (dq_zr) (arch_cmnd_zr) (dq_zr) (out_path_zr) (bs_zr) (arch_name_zr) (dq_zr) (dq_zr) (out_path_zr) (bs_zr) (o.name as string) (file_ext_zr) (dq_zr) to:out_file_zr
)
clearselection()
)
try (close out_file_zr) catch()
)
When a person runs the script for the first time, source-directory will be undefined.
So the script will ask to choose the directory.
You can do something like:
- If the source is undefined, and the user still does not select a directory then in that case,
Put a default Directory.
I actually want to know why you want to use an initial directory?
Its useful only if the person has made proper folder structure…
thanks
well basicaly this script implies that user have PROPER folder structure, right now i’m thinking about resolving all posible issues
thank you anyway, i’ll continue improving this script
You can check the pre-defined globals in Maxscript help.
eg:
maxfilepath
$Scripts
etc.
You might want to use a default path for initial dir if source is undefined.