View Full Version : Add current Project to a Winzip Archive?

06 June 2007, 07:33 PM
Hey guys, there is a script on Highend that makes a winRar file out of your project, but my question is this, can you do the same with winZip? I know nothing of system commands and whatnot, and was wondering if someone could give me some help, or at least point me in the right direction. Thanks.

06 June 2007, 10:44 PM
Well you've got a couple of different options here. If you want to do it through MEL and winZip this absolutely possible. You have to use the system command to control winZip via the command line.

I have an old script that archives scene files using winZip. I'm not sure if I still have it lying around anywhere. When I have some free time, I'll see if I can dig it up and then I can give you some code samples.

If you're using Maya 8.5 python is an option. Python has a zipfile module built in. The advantage to this is that you won't need any external programs. You'll be able to do everything you need right in Maya.

06 June 2007, 01:43 AM
Wow, cool! Thanks for the info grantimus! Yes that would be totally awesome of you. Im actually using Maya 7.0 at the moment, but the python thing sounds pretty neato as well. We gotta upgrade our copies of Maya, 8.5 is so much better.

06 June 2007, 09:55 AM
Well dude I can't seem to find my old script anywhere. But I can still give you the command you'll need to add your project to a zip file using winzip. It is this:

system("start \"c:/program files/WinZip/WINZIP32.EXE\" -min -a -r \"" + $pathToZipFile + "\" \"" + `workspace -q -rd` + "\"");

Naturally, $pathToZipFile is a string containing the path to the zip file you want to archive your project to. If this file is nonexistent, winzip will create it. If the file already exists, winzip will add your project to the contents of the zip file.

06 June 2007, 09:18 PM
Awesome! Thanks Gantimus! You rock my world. Haha. Im gonna try this out.

06 June 2007, 10:02 PM
Yay! It works like a charm! Thanks for your help! Although, would you mind going over what all the tags mean? I have no idea whats going on other then the $pathToZip variable.

06 June 2007, 01:45 AM
Yeah I can break down the command for you. It's certainly a little more involved than most MEL commands. But once I break it down, I think you'll see it's really not that big of a deal.

Fist there is the system command. You can think of the system command as a command prompt. Whatever string you send to the system command will get evaluated as if you had typed it into a command prompt. So I think the best place to start, is to go over what you'd type into a command prompt to archive your Maya project.

First of all, you'd want to start Win Zip. To do this from a command prompt you'd type in the path to winzip. If you used to default installation, this is:

"c:\program files\WinZip\WINZIP32.EXE"

Since the path to winzip has a space in it, it is important to put it in quotes. Otherwise DOS would think the command is c:/program and you'll get errors.

Now that you know how to start winzip you need to tell it what to do from the command line by adding flags. This is actually very similar to adding flags to a mel command. On winzip's webpage they have a breakdown of what the flags for winzip are. The flags we want are these:

-min -a -r "path of winzip file we're adding stuff to" "path of stuff to add to winzip"

-min tells winzip to start minimized. Things would work just fine without this command but winzip would start in it's regular way, and I felt like that was kind of annoying.

-a tells winzip that we want to add something to a zip file

-r tells winzip that we want to add a folder and all of that folder's sub folders to the zip file. This saves a lot of time because without this flag we'd have to add all of your projects sub folders to the zip file one at a time.

The rest of the flags are paths, first the path of the zip file we want to add stuff to followed by the path to the folder/file we want to add to the zip file.

So on my computer if I wanted to add my default Maya project to a zip file in c:\temp I'd type in the following:

"c:\program files\WinZip\WINZIP32.EXE" -a -r "c:\temp\" "c:\Users\Owner\Documents\maya\projects\default"

Now that we know what to type in a command prompt, we need to modify things so that they will work in MEL with the system command. Since the system command works with strings, we need to convert the above command into a string. To start off, we will put it in quotes:

""c:\program files\WinZip\WINZIP32.EXE" -a -r "c:\temp\" "c:\Users\Owner\Documents\maya\projects\default""

But if we try and run that through the system command you'll get errors. This is because the quotes that are already in the command are messing things up. In MEL, whenever you're putting a quote into a string you need to use the escape character followed by a quote. In mel you'll need to type \" this tells Maya that you're using a quote and not ending the string. With this in mind, the string will look like this:

"\"c:\program files\WinZip\WINZIP32.EXE\" -a -r \"c:\temp\\" \"c:\Users\Owner\Documents\maya\projects\default\""

If you use the above string Maya itself won't have a problem with it, but once it reaches DOS it won't execute. This is because "\" is the escape character in MEL, so the paths in the command aren't being read correctly. To get around this, I use "/" in my paths instead of "\". If you use "/" in the command prompt things won't work. Fortunately, the system command is smart enough to swap out "/" for "\" when it sends the command to DOS. So now where left with the following string:

"\"c:/program files/WinZip/WINZIP32.EXE\" -a -r \"c:/temp/\" \"c:/Users/Owner/Documents/maya/projects/default\""

This string will work, but Maya will freeze while the zip file is being created. This is because when the system command is used it waits while the submitted command is being executed. In this case, and most cases, this really isn't very efficient. So you need to tell winzip to run in the background, this is done by using DOS's start command like so:

"start \"c:/program files/WinZip/WINZIP32.EXE\" -a -r \"c:/temp/\" \"c:/Users/Owner/Documents/maya/projects/default\""

Now, if you want to add the current project to the zip file, and not the default one, we need to find the path to the current project. In mel this is done with the following command:

workspace -q -rd

This leaves us with the following:

"start \"c:/program files/WinZip/WINZIP32.EXE\" -a -r \"c:/temp/\" \"" + `workspace -q -rd` + "\""

If you don't want to archive things to the same zip file all of the time, you'll want to add the ability to specify a different path than "c:\temp\". I did this by adding the $pathToZip file variable as follows:

"start \"c:/program files/WinZip/WINZIP32.EXE\" -a -r \"" + $pathToZipFile + "\" \"" + `workspace -q -rd` + "\""

Now that you have the string you want, you just need have the system command execute it:

system("start \"c:/program files/WinZip/WINZIP32.EXE\" -min -a -r \"" + $pathToZipFile + "\" \"" + `workspace -q -rd` + "\"");

06 June 2007, 05:25 PM
Grant, you are teh man! I love you. Hehe. No seriously, thanks for the break down, you rock!

CGTalk Moderation
06 June 2007, 05:25 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.