Dialog Tutorial

Corona Virus banner illustration - Microbiology And Virology Concept - by Mike Fouque

When you want to replace a printer controlled display you might want to show some dialogs triggered by some actions or printer responses. For this purpose the server supports some server commands that show a dialog on the touchscreen, regular gui and Repetier-Server Monitor if the printer is active.

The same dialogs also get used if the firmware supports the host prompts. Then you will see the firmware generated dialog the same way. But this happens automatically, so we will ignore that in this tutorial and concentrate on dialogs that are generated through special printer configuration.

Basic dialogs

The server supports 3 standard dialogs that just show a message – info, warning and error dialogs. To create them just add the command like this:

@info Some message text
@warning Some warning text
@error Some error text

Now that you know how to show them the big question is where to add them. While you can add them anywhere they should of course only appear when there is a reason. In the generated g-code you might want  to add a info at some special places, e.g. a warning that you need to do xy soon or before a @pause command to inform the user why you are going to pause.

More likely is that you want some printer action trigger a message. So it is now time to learn the more advanced settings in the Printer Settings->G-Code tab. There is a sub tab called Response to Event which you will need. Lets assume you have added a trigger to your printer that detects when the spool has only 90% capacity. When that is reached the firmware writes “filament_low” once. We want to get a warning when this happens without watching the console constantly.

So you add a event – the event name must not contain spaces! It is a message send to all connected interfaces so you can also use this to trigger some other functions. In this case it is not relevant.

Next is the regular expression that should match the output. In our case the expression is “^filament_low$”. The ^ means the line must start with this. The $ marks the end of the line. So only lines that exactly contain that term are matched. If you omit these chars any line containing the text “filament_low” anywhere would match. If you are unsure I advise to pretest your expression in an online tool like https://regex101.com/. If you are unfamiliar with regular expressions, there are many tutorials or just ask wikipedia.

Last block is G-code to execute. Here we enter our warning:

@warning Filament is low. Make sure you have a replacement

Now save the new settings and try to trigger it. You should then see the warning.

Dialogs

If you need some interactivity, you need to use server dialogs. These work the same like the host prompt support some firmwares offer, just completely handled by the server. First you create the dialog. Here a simple Homing example that lets you choose which axis to home:

@dialogStart "Select the axis for homing" "Home"
@dialogButton All "G28"
@dialogButton X "G28 X0"
@dialogButton Y "G28 Y0"
@dialogButton Z "G28 Z0"
@dialogButton Cancel
@dialogShow

So how does it work? With @dialogStart you initiate the creation of a dialog box. The first parameter is the messege in the dialog and the second one the header text. If the text contains spaces, put it in double quotes like shown in the example.

Next step is defining the buttons. There is no limit but too many might look not so nice. They again take two commands. The first is the button text and the second one is the g-code to execute. Put it in quotes and split commands with \n.

Last step is calling @dialogShow which finally shows the dialog to all users that are on the printer interface. If they are in a global window they won’t see the dialog until they switch to printer. In Repetier-Server Monitor dashboard you will see a warning icon when dialogs from printer are available.

The user can now move the dialog around dragging it at the header (except on the touch interface) and select one of the buttons. Any selection of a button closes the dialog for all users and executes the g-code associated with that button. If a button has no g-code like the “Cancel” button in this example only the dialog gets closed.

Now you might wonder where to add it. One good place is in your printer configuration in G-Codes->Replacements. The following image shows, how to add it there as “home” command. Means whenever the server sees the command “home”, e.g. entered in console, it will execute the dialog.

As a test I move back to printer console after saving the configuration and send the command “home” in console. Here the result:

If the commands get too much to be set in the button, you can implement them a replacement command and call that instead. As an example we will now implement a manual bed leveling that moves to the 4 corners. Here we assume a bed 200×200 mm and want a border of 20mm to each measuring point. At each point the user levels the bed height manually with the paper method and then moves to the next corner. The command to start leveling is “level”.

Start command

Regular Expression: ^level$

G-Code to Execute:

G28
level1

1. Corner

Regular Expression: ^level1$

G-Code to Execute:

G1 Z10 F600
G1 X20 Y20 F6000
G1 Z0 F600
@dialogStart "Level 1. Corner" "Bed Leveling"
@dialogButton "Next" "level2"
@dialogButton "Finished"
@dialogShow

2. Corner

Regular Expression: ^level2$

G-Code to Execute:

G1 Z10 F600
G1 X180 Y20 F6000
G1 Z0 F600
@dialogStart "Level 2. Corner" "Bed Leveling" @dialogButton "Next" "level3" @dialogButton "Finished" @dialogShow

3. Corner

Regular Expression: ^level3$

G-Code to Execute:

G1 Z10 F600
G1 X180 Y180 F6000
G1 Z0 F600
@dialogStart "Level 3. Corner" "Bed Leveling" @dialogButton "Next" "level4" @dialogButton "Finished" @dialogShow

4. Corner

Regular Expression: ^level$

G-Code to Execute:

G1 Z10 F600
G1 X20 Y180 F6000
G1 Z0 F600
@dialogStart "Level 4. Corner" "Bed Leveling" @dialogButton "Next" "level1" @dialogButton "Finished" @dialogShow

You see the logic is quite simple. The start command initialises the printer and then we show the first dialog. Then we stop either when user hits “Finished” or we activate the next dialog by calling the appropriate replacement.

With some fantasy other interactive wizards can easily be written to help frequent tasks. The initial command can also be put as quick command so it even gets a menu entry.

You should consider with your designs that only one server dialog can be opened. Opening a new dialog automatically closes the old dialog!

At the end a small note on replacements. It is not allowed to call the same rule directly. But it is ok to call the same rule from a button assigned g-code. The reason is that in the latter case the rue is already finished when you call it again, so it is not considered a recursive loop.