Git and maxscript

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!

Repository

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.

Start a repository first before committing files to it
Start a repository first before committing files to it

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.

Open the user options file to start customizing
Open the user options file to start customizing

Add current file

command.name.5.*=Git add this file
command.5.*="C:Program Files (x86)_toolsGitbingit.exe" add $(FileNameExt)
The 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.

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.

This is the prompt which opens because of the *-character
This is the prompt which opens because of the *-character

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.

Here are the three new commands
Here are the three new commands

This is me actually committing a file to my Git repo
This is me actually committing a file to my Git repo

And here's the Git repo with the new update!
And here’s the Git repo with the new update!

2 Comments

Join the discussion and tell us your opinion.

  • 2016-11-19 at 12:04

    Hi, Klaas. Thanks for a great article.
    Do you have any idea of how to disable output panel to show up on execution of commands?

    • 2016-11-21 at 08:07
      In reply to: Serejah

      No I don’t, sorry

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.