Script Program in a URCap

Hello everyone,

I am currently working developing my first URCap. So far it’s going good, but i have a question from my side.

I have written some script commands in a robot program which is saved in .urp file, but i would like to create a simple URCap which just executes the program in a single node, when i select the URCap node in the program. Also adding to this question, i would like to add user data which has to be done through installation node and then the script program uses the data from the installation node and executes the program.

I looked into the forum to get examples as such, but i could not find one. Could someone help me with such examples?

For eg:

Robot program
xxxx
xxxx
xxx
xxx

All the xxx are the script commands and i would save them in a script file. After i develop a URCap the robot program should look like

Robot program
URCap Node. (And this URCap node executes all the xxxx commands).

Thanks in advance,

What you seem to be trying to do is to add to the script to the program nodes generateScript function?

No. I have a .script file with all my functions in it. I need to obtain the data from installation node and then this data must be used in .script file. After the data is obtained, in the program node, i need to run this .script file/function i created as a URCap node.

I looked into the example of the tutorial for adding script functions in generateScript function in java, but i cannot write all the commands in the generateScript function. So i would like to use it as a function command to call my .script file/function and then the program runs. I would like to receive some examples regarding this.

I hope this answers your question.

So you mean the scriptfile will be changed at runtime?

If so you could use a socket connection and from Java read each line and send one at a time to a socket that you listen to in generateScript.

Otherwise, anything that you can do in a scriptfile you can add with writer.appendLine(yourScriptLine), even things that aren’t in the ScriptManual, but is valid URScript language.
Ofc if you use appendLine you need to be more careful with syntax etc.

Also, if you have all the script lines in your installation node contribution, you can add them there as a defined function, then in the program node just call that function you created

No, the script file does not change in runtime.

Let me make this clear, I have a script file with
def Program_1():
var_1
var_2
xxxxxx
xxx
xxx
xxx
etc.

I can do this program in a UR Program right now, but i would like to create a URCap node to make it easier. At the start of the program a user gives var_1 and var_2 input. And based on that input the program runs. So my idea of this URCap node is to put
var_1 and var_2 in the installation contribution node, where user gives the input before the start of the program.
def Program1(): in the program contribution node, where selection of the URCap node in the program view executes this program.

Ofcourse writing each line of my Program1 in the generateScript takes a lot of time. So i would like to know whether i can just call def Program1(): in the program contribution node and also can i append the var_1 and var_2 into this Program1() node?

Instead of writing all the lines of the Program1 in the generateScript is there a way i can call this function def Program1():? Is there any example for this?

I don’t know of any way of appending a variable not created by your URCap, but you can create variables in your scriptcode in generateScript to get user input.
You don’t find them in the script manual, but I think the commands are request_float_from_primary_client(“message string”), request_integer_from_primary_client(“message string”), request_boolean_from_primary_client(“message string”) or request_string_from_primary_client(“message string”).

To be sure, you can create operator input variables in a URP, save it and read the .script file that has been created with your .urp file, then you can see exactly what the command is.

So your generateScript in the InstallationNode would be:

@Override
	public void generateScript(ScriptWriter writer) {
		writer.appendLine("def Program_1():");
		writer.appendLine("request_integer_from_primary_client("messageString")");
		// Rest of your code in writer.appendLine()
		writer.appendLine("end");
	}

and your programNode generateScript:

@Override
	public void generateScript(ScriptWriter writer) {
		writer.appendLine("Program_1()");

	}
1 Like

Thank you for the reply. I will try this and get back if it works.

And one more question, where do i have to save my .script file when the code is executed? It must be saved somewhere right?

Same folder as the URP is saved, so in the on a real robot on /programs/
On a simulator, ursim-current/programs.UR10/ or which simulator model you’re running.

I will try this. Thank you.