ZBrushCentral

Put a ZScript on a button

It must be possible to put a Zscript onto a custom UI button, but how?

[IButton, "Hello", "Hello World message!",
[VarDef, msg, ""]
[VarSet, msg, "Hello World!"]
[MessageOk, msg, "Word up!"] 
]

Without confusing matters, what if I wanted to put this simple script onto a button BUT with the caveat of needing to change the script on the go - say I needed to change the message halfway through sculpting -

    [VarSet, msg, "Hello Coffee!"]

Does that mess things up as the existing script is already complied and any link would be to the .zsc and not the text file?

Hope this make sense. #actuallyautistic
Answers on a postcard, please.
Cheers :slight_smile:

The simplest way is to create a macro. All you need to do is change the button name to ??? and save the text file to the ZStartup\Macros\Misc folder. So for your example:

[IButton, ???, "Hello World message!",
[VarDef, msg, ""]
[VarSet, msg, "Hello World!"]
[MessageOk, msg, "Word up!"] 
]

should work fine.

-Marcus

Thanks Marcus.

However, with the but UI macro button set up, how do I shorted the sequence of
Edit the script
Run & re-compile script
Re-load script
Press button

To just:
Edit the script
Press button

You can’t do less than:

  1. Edit script.
  2. Press Macro>Reload All Macros.
  3. Press button.

However, it occurs to me that you can achieve what you want by using the macro button to load a separate script.

Your macro has to be like this:

[IButton, ???, "Load my code",
   [FileNameSetNext,"My_Code.txt"]
   [IPress,ZScript:Load]
]

The “My_Code.txt” bit must be the path and name of the zscript text file. If there is just a filename then the file must also be in the ZStartup\Macros\Misc folder.

The actual ZScript that is loaded cannot have a button and must run immediately it is loaded. To achieve this the code is wrapped inside an [If} statement that is always true like this:

[If,1,
   [Note, "Hello World!"]
   //other code here
]//end of zscript

In this code “1” is always true so the Note will show every time the zscript is loaded. Make sure this is saved as “My_Code.txt” to the ZStartup\Macros\Misc folder.

You can edit the code as much as you want in this zscript file and it will be loaded when you press the macro button.

HTH,
Marcus

1 Like

Thanks Marcus,

However, a reload all macros will be needed - which can be added as button but oddly not as code. Not sure why?

   // reload all macros
   [IPress,Macro:Reload All Macros]

You shouldn’t need to press “Reload All Macros”. Once the macro file is registered by ZBrush it won’t need loading again. But perhaps having the My_Code.txt file in the Macros folder is not a good idea. It would probably be best to have it in the ZScripts folder instead - that will also make it easier to edit.

Here’s a working example. Note the zip file shows the folders to install the two files. Once you’ve restarted ZBrush, pressing the “Load_My_Code” macro should load the other zscript and immediately show any changes you’ve made (so long as you save the file after making changes!).

ZScript example.zip (1.4 KB)

1 Like

Perfect!

1 Like