Universal Robots Forum

Creating new lines with strings

How can create a new line with string variables?

For example, in other languages like python, “first line\n second line” produces this:

first line
second line

How can I do this with urscript? I’m wanting to use a multi-line string with a yes/no pop. For example:

change_params = request_boolean_from_primary_client(“Width: 20 inches\n Height: 10 inches\ Would you like to continue with these settings?”)

Width: 20 inches
Height: 10 inches
Would you like to continue with these settings?

You can use HTML formatting inside a string in URScript, for example if you create a popup using the following command:

popup("<html>Width: 20 inches<br>Height:10 inches<br>Would you like to continue with these settings?</html>")

This will for mat the text as you wish, with the <br> tag indicating a new line. You can also use other html tags to aid formatting too, enabling you to centre text, use bold or italic text etc.

As for a yes/no popup, the only popups available URScript are those shown in the popup() command I used to demonstrate this. You will have to code your own if you want some yes/no functionality

Hope this helps.

EDIT: For anyone wondering this also works in java and thus can be used when configuring JLabels and other swing components for a URCap

5 Likes

Thank you!! Formatting the string with html solved my needs.

As for a yes/no popup, the only popups available URScript are those shown in the popup() command I used to demonstrate this. You will have to code your own if you want some yes/no functionality

Actually this is not true. The popup() is the only command published in the script manual, but there are additional commands to do the float, integer, string, or boolean options that are not published. If you create these operator inputs with polyscope and run the program, you can view the compiled program script. If you hook up a keyboard, CTRL+ALT+F1 (or CTRL+ALT+F7 for simulator) (u: root, p: easybot), cd to /programs or where you saved your files, you can run the following command to view the compiled script:
nano filename.script

So…
my_variable = request_boolean_from_primary_client(“Width: 20 inches
Height: 10 inches
Would you like to continue with these settings?<\html>”)

… produces this:
uryesno

the other commands are:
returnVar = request_float_from_primary_client(“description string”)
returnVar = request_integer_from_primary_client(“description string”)
returnVar = request_string_from_primary_client(“description string”)

3 Likes

That’s information worth knowing, thanks! I’m glad the html formatting helped.

2 Likes

This is extremely helpful information! We should ask to put this is the manual. I can see myself need this in the future and not finding this specific post…

2 Likes