The ability to record macros is a great addition to ZBrush but with a little zscripting knowledge it is possible to edit the recordings for greater efficiency, or even write a macro from scratch.
If you look at a recorded macro text file in a text editor you will see that it begins something like this:
//ZBRUSH MACRO - Recorded in ZBrush version 3.1
[IButton,???,"Press to run this macro. Macros can be aborted by pressing the ‘esc’ key.",
[IShowActions,0]
[IConfig,3.1]
/*main macro commands here*/
]//end of macro button
The button has a special name - ??? - and this is what identifies it as a macro. The commands that are wrapped inside the button begin with [IShowActions,0]. This is a useful command - it temporarily switches off the Show Actions button in the ZScript palette, so that the commands that follow are executed without the cursor opening palettes and so on. The [IConfig,3.1] identifies the ZBrush version and then the main macros commands follow. The button ends with a final square bracket.
Changing the button size:
The default size of the macro button will depend on the filename you give it, as the filename becomes the button label. But by adding a little code you can make the button exactly the size you want. This is very useful if you want to fit the button neatly onto a custom interface. All you need to do is add this code instead of the final square bracket:
,,.5 /*width*/,,,.25 /*height*/]
The width and height are proportions of the palette size, so in this example the button would be half a palette in width, and a quarter in height. The exact size will depend on the setting you have in the Preferences:Interface: Button Width slider but whatever that is a value of .5 for the macro button width should fit neatly below the color selector. There’s no need to enter a height value, but in this example the .25 will give a button the same size as the Projection Master button.
Avoiding Error Messages
Sometimes a recorded macro can throw up an error message when the button is pressed. This is usually because ZBrush is not in the same state as it was when the macro was recorded, so that an option that the macro requires is not available. It is possible to use zscript commands to test for the right conditions, and avoid errors of this sort. The following code is for toggling Y symmetry on or off. It first checks that the symmetry option is available before carrying out the necessary actions:
//ZBRUSH MACRO
[IButton,"???","Toggles Y symmetry on or off",
[IShowActions,0]
[IConfig,3.1]
[If,[IExists,Transform:ActivateSymmetry],//check for the 'Activate Symmetry' button
[If,[IsEnabled,Transform:ActivateSymmetry],//if the button is enabled (can be pressed) proceed
[If,[IGet,Transform:ActivateSymmetry],//will return 1 (true) is the button is already pressed
[If,[IGet,Transform:>Y<],//will return 1 (true) is the button is already pressed
[IUnPress,Transform:>Y<]
[NoteBar,"Y symmetry OFF"]
,//else button is not pressed so:
[IPress,Transform:>Y<]
[NoteBar,"Y symmetry ON"]
]
,//else button is not pressed so:
[ISet,Transform:ActivateSymmetry,1]
[IPress,Transform:>Y<]
[NoteBar,"Y symmetry ON"]
]
]
]
,,.5 /*width*/,,,.25 /*height*/]