Using some kind of version control when programming is always a good idea. While building my maxscripts I tend to explore options, preview stuff to clients and need to go back for lost pieces of code. Version control is a great way to enable that without going crazy. I’m using GIT, but there are many other version control systems out there. I’ve set it up with 3ds Max in such a way that I can commit files quickly and add sensible comments. I’m aware I’m not the most advanced GIT-user but it works for me!
First, you have to create a repository to add files to. I use a shell extension for GIT: gitextensions for that. After that you’re all set actually. You can start adding files and committing them. However, you can also set up the maxscript editor to help speed up the commits.
Customize the maxscript editor
Open the maxscript editor and open the User options file (menu > tools > open user options file). Here you can add stuff to customize the editor. I’m going to add three GIT actions:
- add the current maxscript file
- add all maxscript files in the same folder as the current maxscript file
- commit all files to the repository.
Each of these three items will be added to the tools menu of the maxscript editor.
Add current file
command.name.5.*=Git add this fileThe first line defines the text we’re putting in the menu-item. I’m using command.5, but you can choose your own number. The second line is the actual GIT command. The first part is the path to where I’ve installed GIT, then comes the “add” command and finally the filename of the currently selected file.
command.5.*="C:Program Files (x86)_toolsGitbingit.exe" add $(FileNameExt)
Add all files from the same folder
command.name.4.*=Git add all *.ms files from this folder command.4.*="C:Program Files (x86)_toolsGitbingit.exe" add "*.ms"Here I’ve changed the add-command to include all .ms-files in the same folder as the currently opened maxscript.
Commit files to the repository
command.name.6.*=Git commit command.6.*=*"C:Program Files (x86)_toolsGitbingit.exe" commit -m "$(1)"Here’s the command which actually commits the added files to the repository. It starts again with the path to where I’ve installed GIT followed by the commit command, then the -m option. This signals GIT we want to add a commit-message (and you really should). FInally the “$(1)” part symbolizes the message. But wait, where’s the message? Notice the “*” character between the = character and the GIT path? This is a neat feature of the scite editor. This asterisk opens a small dialog when calling this command. The dialog has 4 input fields. The “$(1)” says we’re using the first input field.
Using these custom commands is very easy. You can go the the menu > tools and pick your commands. You can also use the keyboard shortcuts CTRL+4,5 and 6. If you’ve picked different numbers for these commands the shortcuts will be different.