9 Replies - 625 Views - Last Post: 11 July 2011 - 09:15 AM Rate Topic: -----

#1 mimoss03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-July 11

Code for Zipping multiple files

Posted 06 July 2011 - 11:52 PM

Hello,
New here and ABSOLUTLY no C++ knowledge.

I am a 3D modeler and Visual FX artist, i need to create some code inside of Maya (the 3D application that i use)
Maya is a blend of 3D and MEL scripting (Maya embedded Language). Maya also understands C++.

What im doing is creating my own custom button inside of Maya, which when pressed, saves the current project via "Save as..." dialog box. then Zips all the files togethher and saves to specified location.

I have my button already created that saves the project. (that part is all done using MEL Language).
Now i need C++ code to zip it and save it.

I can write MEL code to call the C++ code and execute. But haven't the foggiest idea how to write the C++ part.
The project is a large file structure. All within one directory.

I just need to to take the single folder (+ all sub folders) zip it, then save it. If its possible to have the user pick where to save it great! If not, a default spot, like the desktop will work just fine.

I have Visual Studio 2008 and Visual C++ Express 2010.
Hopefully im clear on this, if not, please tell me and ill try elaborate.

Thanks for the help.

Mike

Is This A Good Question/Topic? 0
  • +

Replies To: Code for Zipping multiple files

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Code for Zipping multiple files

Posted 07 July 2011 - 08:49 AM

Well... first question: is C++ the best tool for the job?

might it be easier just to place a compression utility such as the open source 7Zip somewhere and use some kind of batch process to call that to do your compression?

The reason I make the suggestion is that this will require setting up and using a third party libary (or writing your own compression features). This is not hard per-se but for a beginner it can be frustrating.

So before you commit yourself to frustrations make sure that it is necessary. If you can just make a call to a utility then do that.


Having said that you can look into zlib which I understand works with visual studio. I *think* the windows API actually has some compression features however I really don't know much about it but you could poke around MSDN and see what there is to see.
Was This Post Helpful? 2
  • +
  • -

#3 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5305
  • View blog
  • Posts: 27,198
  • Joined: 10-May 07

Re: Code for Zipping multiple files

Posted 07 July 2011 - 08:58 AM

View PostNickDMax, on 07 July 2011 - 11:49 AM, said:

Well... first question: is C++ the best tool for the job?

I was thinking the same thing. A simple pkzip in a for loop would do the job under batch.
Was This Post Helpful? 0
  • +
  • -

#4 mimoss03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-July 11

Re: Code for Zipping multiple files

Posted 07 July 2011 - 10:06 AM

Thanks for the info guys, the reason i chose C++ is because that is the language Maya understands and can be implemented from inside of Maya. If there is a way to do it with out C++, then great.

So, with my limited computer programming skills, what i believe you are sayings is, when i click my custom button in Maya, that will save my project, then call the 7zip utility to zip and save the project...

Now, the problem that i foresee is i do not know how to call the 7zip utility using MEL script, (not sure if MEL can call an outside batch function) Which is why i was thinking of using C++, C++ can call the zip utility, and can be read from within Maya.

Am i not understanding this right?
Was This Post Helpful? 0
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Code for Zipping multiple files

Posted 07 July 2011 - 10:24 AM

According to this blog here MEL script has a system command similar to C/C++'s system command.

So to call a zip utility you would do something *like* this:

string $projectName = "project.7z";
string $projectDir = "C:/user/NickDMax/maya/project1/"
system("C:/Program Files/7zip/7z.exe a "+$projectName+" "+$projectDir);


Also can you use Python in Maya/MEL?

point is: try easier before harder.
Was This Post Helpful? 2
  • +
  • -

#6 mimoss03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-July 11

Re: Code for Zipping multiple files

Posted 09 July 2011 - 12:37 PM

Hi, sorry took so long for me to get back here.
First, Yes, you can use Python in Maya.

Second, i tried that system line you wrote above. Something's fishy. It displays the command prompt after it runs that line. but only briefly, cant see what it says. (tried to hit break when it comes up, no luck) Either, way, its not saving the file..anywhere.
Here is the line of code i have...

system("start C:/users/mike/documents/maya/scripts/rar.exe a -m5 -ed "+$currentSceneName+" "+$currentScenePath);
Was This Post Helpful? 0
  • +
  • -

#7 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Code for Zipping multiple files

Posted 09 July 2011 - 12:52 PM

ok, ditch the "Start" command there. Don't really need it.


next open a command prompt and try out your command and see what it does...

one of the problems with such commands is they can create the files in odd places. They create the file in the "current directory" -- which is not always someplace logical. So ensure that your archive name (at least until you know everything works) has a full path. You can work on making it configurable later.

another trouble shooting step you can take is to use a batch file at a intermediary.


So you might make a batch file called "dorar.bat":
echo --- begin creating archive ----
C:/users/mike/documents/maya/scripts/rar.exe a -m5 -ed %1 %2 %3 %4 %5
echo --- end creating archive ----
pause


and then change you system command to:

system("C:/users/mike/documents/maya/scripts/dorar.bat " + $currentSceneName + " " + $currentScenePath);


and this will let you see the command that actually gets executed and should show you the results.
Was This Post Helpful? 1
  • +
  • -

#8 mimoss03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-July 11

Re: Code for Zipping multiple files

Posted 10 July 2011 - 10:01 PM

Hi again guys, thats for all your help and patience.
I've decided to take another approach to this. That way whoever uses it won't have to worry about haveing to use winrar. There rar.exe path can differ from mine.

I've decided i like the idea of using Python as well. Because of the built in Zip module.
Do you know how to pass variables from MEL to Python? and vice versa?

Thanks.
Was This Post Helpful? 0
  • +
  • -

#9 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Code for Zipping multiple files

Posted 11 July 2011 - 08:20 AM

Well this is a C/C++ forum. So most of us will just have to google this anyway...

Is your Google kung-fu lacking?

I think you call python modules like: python("myPythonCommand('" +$arg1 +"', '"+$arg2+"')");

based upon what I see on this blog. That blog seems to have a lot of pything scripts for Maya so you might gleen though that and see what you see.
Was This Post Helpful? 0
  • +
  • -

#10 mimoss03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-July 11

Re: Code for Zipping multiple files

Posted 11 July 2011 - 09:15 AM

Opps, sorry. I forgot that C++ is the reason i started this thread. Sorry. Somehow i kinda got off track.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1