Website powered by

Zbrush Zscript 03 - Macro Example - Cycle Brushes

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

[IKeyPress,CTRL,
[If,[IGet,Brush:MaskPen]==1,
[IPress,Brush:MaskLasso]
,
[If,[IGet,Brush:MaskLasso]==1,
[IPress,Brush:MaskCurve]
,
[IPress,Brush:MaskPen]

]
]
]

,,,CTRL

]

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:

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/#IButton

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/#IKeyPress

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/#If

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/#IGet

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/#IPress


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.




  

Zbrush Zscript 02 - Macros

Tutorial / 20 January 2019

Most people start making macros by recording actions in Zbrush (ZB) and then spitting out a macro to the startup/macros folder.  Let's try this:

1. I dock the Macro menu to one of the side tabs and press "New Macro"

This option will appear - I haven't ever needed to initialize so far I always click NO before I start recording.  There's reasons you may want to initialize I can cover later but for simple scripts selecting NO is ok.

After which this notification will appear - you need to be careful since almost everything you are doing in zbrush is now being recorded.


2. Now you are ready to do something that you want automated:

Very simply I had 2 cylinders and then performed the following sequence in Zbrush:

Sequence 1: I pressed - Tools:Polygroups:Autogroups

Sequence 2: I then pressed - Tools:Polypaint:Polypaint From Polygroups

Sequence final: I then pressed Macro:End Macro and a save dialog appears.  I saved the macro in a new sub folder and gave it the name "AGPtoPP.txt"

This folder and file is held in the ZB install with all the other macros:

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

3. You should now have a working macro button in the macros menu:

Yay it's performing that exact sequence over and over.  You can now copy this button out to a custom UI or hotkey it too.

Let's look at the script that was made:

And here's how I usually trim it immediately:

The body of the script explained:

Line 1:   IButton is ZBs way of recognizing the script as a UI element, the "???" is a special tag that tells ZB the script is a macro, the "Text" is what appears in ZB as you hover above the button.  Macros with this line saved in the macro folder appear as a button with the file name under the Macros Menu.

NOTE - Often when writing macros you'll break them.  They'll disappear from the macros menu because Zbrush failed to compile them from the TXT file to the ZB format of .zsc

Line 2:  IShowActions,0 "0" is code for "No" so this line is telling zbrush to hide the actions while the macro performs its function.

Line 3 and 4: IPress, and then the path to the UI item you want pressed.  In this case it was the two pressed buttons I recorded earlier.

NOTE - Every ui in zbrush has a path.  If you hold and Control and hover over a button the path will appear in the bottom of the tool tip.  Match this path to the path on line 4 above to see how it's working.

Even more explanation in human speech:

So you should now know how to record, save and edit simple macros and understand a little more about how they are talking to ZB.  Let me know if you record any cool ones - or have an idea of one you want made.  

Next post I'll show some more advanced stuff like performing something on all your subtools and cycling through the trim tools with one hotkey.