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”)

4 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

I am trying to do something similar to this with line breaks but also variables in the text.

Example:

global a= 1
global b= 2
global c= 3

I want the Assignment text to display:

"
A = 1
B = 2
C = 3
Is this correct?
"

I’m not sure how to get the variables to populate along with the html text. (Coding is not my strong suit)

The trick here is to use a URScript function called to_str which allows you to turn a number into a string to allow it to be used in a popup. I have written a little example that can below:

global var = 12
global var_two = 47
popup("<html>look, a variable! "+to_str(var)+"<br>look, another! "+to_str(var_two)+"<html>")

2 Likes

This was exactly what I needed and worked perfectly. Thanks!

1 Like

Hello

Following the work explained before, I would like to ask you about the following information:

I have 1221 script files to mill different tiles that have to be done individually. It is possible to set up a path by which to have a popup command on which to be able to write the specific number and launch the .script file, or simply select continue?

I hope I have explained correctly(Coding is not my strong suit)
I will be very grateful if you can give me some idea what can be the best way to do it

Thanks in advance! :wink:
Best
Ric

Resurrecting this old thread. It appears you don’t get the same functionality when asking for an integer/float from the client:

Boolean (works fine):

When asking for an integer (doesn’t work)

I guess since the command calls different UI elements, and the numerical input doesn’t interpret the text as html. Very unfortunate.

Hi @eric.feldmann,

I raised this issue internally in the past. It have not been resolved yet and I might fear that it will not be addressed. I will forward the request for PolyScope X. Hopefully we can make it happen there🤞

Ebbe

I have a guess on this. I think the function is casting to string anything entered as input.

Test cases:




I was doing QC on the function and inadvertently learned how to generate None in URScript. It also lists out the valid types to feed into those functions:

I guess None by itself works too: