Zbrush Zscript 03 - Macro Example - Cycle Brushes

Tutorial / 22 January 2019
[IButton,???,"Cycle Mask Brushes",





You can copy paste this into sublime text and save as a .txt file into the macro directory: 

"C:\Program Files\Pixologic\ZBrush 2018\ZStartup\Macros"

Whatever filename you saved the text file as will now appear in the macro menu in zbrush:

If you hot key this for example to the number "5" - every time you press 5 you'll cycle through the brushes in the script.  You can bind the 5 keypress to your mouse or tablet.  I do this to free up a hand and not press control to switch my masking tools when I need to.  

So, we're using the following commands:






The first line is what you'll always see for a macro:

NOTE: [BRACKETS] are like the bread in a sandwich.  And the code is the meat.  If you have an open bracket [ it must have a closed one somewhere after it ] missing a bracket is a common error so keep an eye on their pairing in sublime shown by an underscore.

[BLT,Bacon,Lettuce,Tomato] - If brackets are the bread then commas signify a new ingredient.  If you read the entry on IButton in the command reference you can count 8 commas.  This is the amount of ingredients the IButton can have.  They must also remain in the correct order.  Be aware some ingredients for the button icon only work for plugins and not macros - I can explain more in a later post.

So if we want a BLT and exclude an ingredient this is how  [BLT,,Lettuce,Tomato] [BLT,Bacon,,Tomato] [BLT,Bacon,Lettuce] or my favorite [BLT,Bacon*2] - you'll notice you can leave the leftover commas off but you have to put the internal commas to "get to" the correct ordered ingredient.  Getting your [Brackets, and commas, out of order] is a common source for errors so make them part of your error checklist.

Ok back to the script I'm hungry.

If you go to View in sublime you can make a 2 column layout.  This is helpful when looking over other scripts and snipping to new ones.

Indentations, Line Spacing, and //Comments.  All good habits to keep your script legible.

^ Continuing the sandwich metaphor we'll add an [IKeyPress,CTRL, ] into the [IButtons,,,Command Ingredient]. ^

^ In the Command Group of the IKeyPress I'll add an IF statement.  Read the right column above to see more about the IF. ^

^ In the IF question I use " [IGet,Brush:MaskPen]==1 " to ask " Is the current brush a MaskPen? "  Remember according to the script I am holding CTRL for the mask tool in zbrush.  If this question returns as 1 for True I'm going to then change to the MaskLasso brush.  If it's not the MaskPen I'll get a False and do something else:

NOTE: This is obscure because it's a lot to cover.  But basically = is like saying "equals." But == is like saying "equals?"

So to be a little tricky I nested another IF statement in the False section of it's parent IF Statement.  This checks for mask lasso, if true it switches to Mask Curve, If false it switches to MaskPen.  Now the complete script works like so if you read it line for line:

1. I press CTRL

2. If I'm using Mask Pen I switch to Mask Lasso

3. If I'm using MaskLasso I switch to Mask Curve

4. If I'm using neither of these I switch to Mask Pen

This creates a 3 brush cycle every time you press the macro button.  Pretty convenient if you want to use the keyboard a little less.

Here's another on the right to cycle some clip brushes in the same way - see if you can pick out the differences.  You can hotkey them both to be flipping between these brushes much faster.  See what you can do with the script - you can even do cycles of more than 3 if you keep nesting.  But there's a more advanced way to do this I can go over later so 3-4 seems ok for this exercise.

Next post I will do some looping actions on all available subtools by assigning or clearing matcap assignments.