ZBrushCentral

Mini ZScript Tutorial: 'ZButtons'

Mini ZScript Tutorial: ‘ZButtons’

While you’re getting bored reading this, check out these links:
Davey’s Code Reference
About IButtons, by Davey

Important commands for this tutorial:
:white_small_square:[MouseHPos]
:white_small_square:[MouseVPos]
:white_small_square:[MouseLButton]
:white_small_square:[If…]
:white_small_square:[Loop…]

:large_orange_diamond:About ZScript Buttons:
If you have read Davey’s ZScript tutorial on IButtons, you will be aware that an IButton creates a small red button in the Tutorial Window, which, when clicked, can perform instructions. It includes options for hotkeys and other helpful tools. In addition to all this, the IButton is very easy to use. It is a designed part of the language. However, suppose you want to make a button, not in the Tutorial Window, but in the Canvas area. Enter the ZButton.

:large_orange_diamond:The ZButton:

Before anything else, you should know that the ZButton doesn’t really exist. Fortunately for us, the ZScript command language provides us with all the tools to make a ‘ZButton’, whether such a thing “really” exists or not. So what does a ZButton do? It acts like a regular button. It is an area on the screen that, when the mouse is inside, performs an action. To let the user know a button is there, it usually has a visual element to it. This often explains the button’s purpose, by saying things like “OK” or “Cancel” on it. One thing about the part where the button performs an action: There are actually two places where this can occur. The first is when the mouse is just on top of the button. This “rollover” event is often used to change the appearance of the button, a good secondary visual indicator that this is indeed a button, and that clicking it will do something. The second event happens when you click on the button. This is usually the part where the button does the big thing it supposed to do. By the way, in the current version of ZBrush, there are no separate commands for a mouse click down and a mouse click up. There is also no support for second or third buttons, or a scroll wheel. And finally, one more note. Unless you are prepared to do insane amounts of work to more carefully define it, plan on the button being a rectangle in shape. Or at least the area that will activate the button will be rectangular; the button itself need not look rectangular.

:large_orange_diamond:Making the ZButton:

:white_small_square:Creating the graphic:

<LI>The first thing to do for the button is make a graphic for it. If you want the area that activates the button to be exactly the same size and shape of the button, make this graphic a rectangle. Otherwise, do whatever you want. Save this graphic as a PSD.

<LI>Place the graphic on the screen. An easy way is to load the graphic into the Texture Palette, then put them on a Plane3D. Use the Transform Palette to position, resize, and rotate it as necessary.

<LI>Note: If you want, the button graphic can be made using ZScript commands so there is not separate file.

:white_small_square:Defining the area that will activate the button:

<LI>This is a simple trick that makes use of the [MouseHPos] and [MouseVPos] commands. These output the current location of the mouse. You will use them inside the [If…] and [Loop…] commands.

<LI>Start with the following code:


If you are familiar with ZScript, you’ll realize this line doesn’t work yet. So continue on and complete it:

  • Open the Transform Palette, and its Info sub palette. Make sure you are in Draw Pointer mode. Notice that the first two Sliders show the X and Y coordinates of the mouse. Move the mouse to the left edge of the graphic you created. Remember the first number. Now move the mouse to the right edge, and look at that number. Repeat for the bottom and top edges. Now fill in the code line with these numbers:
    
    

    The actual line might look like this:

    
    
    :white_small_square:Make the button do something when the mouse is over it:
    
  • The line of code above still doesn’t do anything. You need to decide what you want it to do. This can be just about anything, and all you need to do is add the code to the inside of the command after the last comma, like this:
    
    

    You might do something like this:

    
    

    This would draw a little square on the screen.

    :white_small_square:Adding a mouse click event:
    
  • And now we finally get to the part where the button performs the important actions. The, again, can be a lot of things. First we need to let the button know it need to look for a mouse click. This will be done with the [MouseLButton] command. Insert it into our code like this:
    
    
  • Simply insert the actions you want done. For example:
    
    
    :white_small_square:Making it work:
    
  • You may realize that for this to work, it will need to be contained in a trigger command, and it needs to happened over and over and over again. The first part is easy: To trigger this whole process, put it in an IButton. Or a Routine, a Section, a Slider, or any other top level commands that will let you do things.
  • The second part needs the [Loop…] command. This loops a certain number of times, repeating actions over and over again. Use this code:
    
    

    If necessary, you can add more [Loop…] commands inside of the first one to make it last longer.

    :white_small_square:And now, guess what, you have a ZButton! Happy with it? I didn’t think so. So to cheer you up a bit, here is a method that is very similar, but adds a few things. Both methods have a time and place for their use.
    
    :white_small_square:The next method:
    
  • This method is very similar to the last one. The difference is that whereas before we used where the mouse was in a 2D world, now we will use the fact that ZBrush is a 3D one to define the button shape. This will also take away the rectangle shape constraint.
  • This is done using the [PixolPick…] command. This command helps you find out what is beneath the mouse on the canvas. And one thing it tells you is depth. Here is the code for the [PixolPick...]:
    
    

    Which says, “Look where the mouse is, and tell me the ZDepth.”

  • To let it know where the mouse is, we need to define to variables for the purpose.
    
    
  • To make use of this, you just need to make areas of different ZDepths. For example, you might have a Circle3D object at -4 Z. You might then have the following code:
    
    

    This code is the same as the code in Method One, only with the [PixolPick…] command used.

    :small_blue_diamond:For a real demonstration of both techniques, here is a ZScript: Example Every line has a comment next to it explaining what it does, so take a look at the code.

    I hope this is a useful tutorial for you, any questions, ask!

    -Muvlo

  • Nice tutorial, Muvlo. Thank you!

    yeah man thank a z Zillion this is going to come in real handy :+1: :+1:

    Glad it was helpful. Both of these methods play a major part in a script I’m doing now. I wanted to get it up this weekend, but other things intervened, and I’ll probably not get it finished until next weekend. ZScript are a lot of fun! :smiley: I’m very curious to know what they’ll do in the next version. Pix has said they concentrated on them, so I’m sure it’ll be interesting. :slight_smile:

    i made this just playing around with it.
    don"t over Load the .zlt because it wont stop if your curser over the Plane 3D lol
    :small_orange_diamond:TestMuvlo.zip
    And
    :small_orange_diamond:Blink.zip i didn’t do much to this script but took off a symbol to make it blink i think i forgot LOL.
    i made some mouse over to my zscript/default.txt thats pretty cool haven’t tryed any images yet but im thinking of useing .ZBR like on the texturemaster show and tell button thank muvlo

    thanks muvlo im just now really starting to get into zscipts…will all the help ive been getting from you,davey, and others its all coming together…so far i have made a zscript loader… ive customized by entire interface and its so much fun… ive also discovered how to minimize or reduce my zscript folders… more on this later tonight… thanks buddy…

    Muvlo:

    ZButtons look like a great thing. I, like many of your readers, am not a programmer, and have trouble focusing on tiny details in scripts like [ and ]] and , , etc. One mistake, and you’re history. It is very frustrating. We can, most of us, record a ZScript that does useful things. Now, just recently, I recorded some 20 of these that I would like to combine in an attractive format, and in order. Are ZButtons a good way to load separate ZScripts, and make them appear to function as one complete “application”, or should I do this another way. I don’t mind if it is in the ZScript window, but when I use the “zscriptInsert” command, it just puts the script name on for each separate script on a line below the previous one. It works just fine, but looks terrible. Can you help us who are disabled in this way?

    To reiterate: can multiple ZScripts be called from within a single script and formatted nicely, whether they appear in the main window (the canvas) or the ZScript window (for the sake of argument, let us say we want all of these script-calling buttons in a line across the screen horizontally)? And, if this is possible, how do you do it?

    Thank you for sharing your knowledge,

    Bruce Gregory