Universal Robots Forum

generateScript() clarification

Hey All!
Thanks for all the help thus far, the forum was a great place for information, but i cant seem to figure SciptWriting with a URCap out.
My URCap is esentialy a UI for our welding Robots parameters.
Upon selecting the parameters i would like to create the script code, so that the robot can read it when it starts to weld. But i cant seem to call the generateScript() method, nor am i able to create a writer myself. I’ve dug into it and i found that it only runs once. Is that true? If yes, than does it run when i load the URCap, or when i start the actual program?
If it runs only when the program starts than could i use java get-methods to specify what to write with the script writer?
IE:
public void generateScript(ScriptWriter writer){
writer.appendLine(getWeldingCurrent());
}

You don’t have to call generateScript() method. It is called automatically when you start the program and when you save it; the code “appended” to the writer is added to the program script in the position where the URCap program node occurs in the program.

Also you don’t have to create the writer, it is provided by the robot controller/PolyScope.

What @a.mora has said is correct, generateScript() is only called when pressing play on a program. If you want to run script code outside of genrate script, have a look into the secondary client interface. This will allow to send script when a program is not running if this is something that you require. For an example implementation of the secondary client, take at look at the following sample. It has a class which is used to send the script that you can copy if required.

1 Like