Hi everyone, as promised, here’s the first free thingie… actually I hope to make this section not only for free stuff but also for stuff where you can learn something about it, that’s why all the scripts I’ll post here are not being encrypted or anything like that and if I post more stuff here other than scripts, they’ll be free too, I love free stuff, free software, free learning! YEAH 😀 Most part of my knowledge was acquired by learning from what others posted, wrote on their blogs, etc, so I hope to be up to that and give back.
So… let’s get back to what really matters, this script I’ve gave it the artistic name of “Archive & Upload” … since it archives (using max default archive method) and uploads the scene to an FTP… So why I’m I posting this first? Well, because I wrote it to help someone on CGTalk so nothing more appropriate 🙂
This might come as a handy tool for you but you are starting to learn Maxscript take a look at the code where you can learn some cool stuff, both Maxscript and Dotnet.
On the Maxscript part, the most interesting thing in the script is the saving and loading settings from an INI file. On the Dotnet part, lot’s of stuff going on there, I would recommend bookmarking both Maxscript and MSDN online help.
First I’ve used System.Security.Cryptography.SymmetricAlgorithm that represents a class to create a Rijndael algorithm which I’ve used to encrypt and decrypt the password text field that goes into the INI file, we wouldn’t want to save passwords in plain text, right Sony? 😀
Each function uses some more Dotnet magic that I’ll skip explaining step-by-step in this post, but if you take a look at the Create Method example of the System.Security.Cryptography.SymmetricAlgorithm page it helps for sure.
Right, next step System.Net.WebClient, this provides methods to get/send data to HTTP or FTP and since we want to upload a file to an FTP, this is the way to go. After creating the System.Net.WebClient class, we need to connect the event handlers from the class to our Maxscript functions that will handle that job, how do we do that? Simple using dotnet.addEventHandler, here’s the code used in the script:
dotnet.addEventHandler webClient “UploadProgressChanged” UploadProgressChanged
dotnet.addEventHandler webClient “UploadFileCompleted” UploadFileCompleted
We’re using the first method to update our progress bar and the second method to check if the upload was completed successfully. How to actually upload? Using the UploadFileAsync method from the System.Net.WebClient class, why are we using the UploadFileAsync instead of the UploadFile? Because that way 3ds Max thread won’t freeze and we can continue working happilly while the file gets transfered.
theRemote=theFTP+theFile+”.zip”theUri=dotnetObject “System.Uri” theRemotewebClient.Credentials = dotnetObject “System.Net.NetworkCredential” theUsername thePasswordwebClient.UploadFileAsync theUri theZip
Right, first we create the full path to where we are uploading, containing the string entered in the FTP textbox plus the filename of the archive, we then need to convert that into an URI and then, since we are uploading to an FTP, we need proper credentials to connect to the host, so we set the Credentials properties of the System.Net.WebClient class using a System.Net.NetworkCredential followed by our username and password and then… and then… and then…. (I love Dude where’s my car) just upload using UploadFileAsync!
That’s about it, I hope the code isn’t to messy for you and remember Maxscript and MSDN help are your friends! If you made it till here… YOU ARE COOL! 🙂
Leave a Reply