Hi guys,
A couple of general maxscript questions from a novice programmer for anyone that could clarify:
1. Are there standard ways to set up your script to read functions/methods from another file.
For example, I have my main and I want to call functions from another file, ie class file, that I have set up. Is it as simple as telling max to go to a specific directory and read from a file with my functions already in it? (hope that made sense)
I just hate to make one giant file with every single function in it. I'm looking more for a common practice.
2. If I'm sending tools to clients to use, I'd like to do a basic encryption on the code with all my functions/methods.
For example, they receive my zipfile. They can see the open the main file, but the other file with my methods would be encrypted.
The help docs have been useful for some of my maxscript challenges, but more times then not, I find myself confused on how snippets of code are to be set up with out a lot of trial/error.
Thanks for any clarification or common practices you'd like to share.
J
Replies
1) You can trigger an external macro script by using Example:
The external macro script would start out like this:
You can also use "filein" to trigger a .ms script
You can also use "include" which will include the code from the external script into the current one, before it evaluates and runs the current script. This has some pitfalls but they should be well documented around the web.
TLDR
Search the maxscript help file for:
"Include scripts in scripts"
"Macro.run"
"filein"
2) Look up "encryptScript" maxscript allows you to generate encrypted maxscript files (.mse) files, they work with max but they can't be read by human eyes.
@mantragora - checking your video to get more clarification on your post. Thanks for your feedback!
@Mark - Thank you. Sometimes I think the most difficult part is trying to find the correct terminology to search for. I'll go through the help docs and check out includes.
As for the encryption stuff, I found info for this in the help docs.
I guess my question would be how to insert this snippet into my code properly?
Here's my example below. Although I'm posting this, I'll try to see if I can get something basic working:
macroScript sampleScript
category:"Sample tools"
(
scriptfile= "sampleScript.ms"
encryptScript scriptfile
(
for obj in selection do(
print "test"
)
)
)
replace "C: \\testDir\\testfile.ms" with the file path.
For the 'class calling' (Q 1) I made all my functions into seperate .ms files which I call at the start of every maxscript. Mostly because the tools we use often use the same functions and often need the same functionality regardless of tool.
simply put:
edit:
function1.ms would look something like this:
edit2:
Made a quick GUI (Dialog) so you can select a maxscript file and encrypt it in the GUI
Decided to work it out a bit more for personal use!
I left the old code in my previous post, below you can see the new code, have fun! Let me know if it works or not!
Just to clearify this does not overwrite your *.ms file, it will make a new one next to it. (Trust me, I tried and spilled some coffee while checking if it did!)
When installed the MZP defines an "Additional Plugins" folder, and this ms file goes there:
This is pseudo code, but the macros look something like this:
This is a valid function, but Autodesk added doesFileExist function a few versions ago. You're script is an excellent example. I've never used file encryption.
Mmm, for some reason I totally overlooked this! Time to change several of my scripts haha.
Guess I used the function since forever and never looked back!
This could potentionally speed this up a lot .
Basically, I like to have all the artists manually run the setup script. (It's more of a setup wizard.) The setup script points all user folders to perforce. Then whenever they get latest, they always have the updated tools.
Maybe I can hit you up when I have python questions.
This way of doing it will come out handy! I'll be sure to let you know how it works out, thanks. :thumbup:
I'm making my attempts to get this working on some basic things. Will post any updates hopefully soon!