# Get Variable values in Toolbar

**URL:** <https://forum.universal-robots.com/t/get-variable-values-in-toolbar/10077>\
**Category:** URCap Development\
**Created:** [November 18, 2020, 12:03pm UTC](https://forum.universal-robots.com/t/get-variable-values-in-toolbar/10077 "2020-11-18T12:03:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon29287759](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anon29287759](https://forum.universal-robots.com/u/anon29287759)\
**Post date:** [November 18, 2020, 12:03pm UTC](https://forum.universal-robots.com/t/get-variable-values-in-toolbar/10077/1 "2020-11-18T12:03:23Z")

</div>

This is my code to get all the variables on my instalaltion but I cannot find methods to get the value of the variable. The objective is to visualize some variables (such as counters) in a toolbar.

import java.util.Collection;  
import java.util.Iterator;

import com.ur.urcap.api.domain.variable.Variable;  
import com.ur.urcap.api.domain.variable.VariableModel;

public class VariableHandler {

```
private final VariableModel variableModel;

public VariableHandler(VariableModel variableModel) {
	this.variableModel = variableModel;
}

/*Returns variable object found by its default name
 * 
 */
public Variable getVariable(String defaultName){
	Collection<Variable> Variablecollection = variableModel.getAll();
	int VAR_count = Variablecollection.size();
	if(VAR_count > 0){
		Iterator<Variable> VAR_itr = Variablecollection.iterator();
		while(VAR_itr.hasNext()){
			Variable thisVAR = VAR_itr.next();
			String thisDefaultName = thisVAR.getDisplayName();
			System.out.println("Found A VAR named "+thisDefaultName);
			if(thisDefaultName.equals(defaultName)){
				return thisVAR;
			}
		}
	}
	return null;
}

```

}

Thanks.

---

<div class="post-metadata">

**Author:** ![anon3164729](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon3164729](https://forum.universal-robots.com/u/anon3164729)\
**Post date:** [November 24, 2020, 8:50am UTC](https://forum.universal-robots.com/t/get-variable-values-in-toolbar/10077/2 "2020-11-24T08:50:30Z")

</div>

This is not as simple. I’m also trying to find the best way to view and edit a variable from a toolbar. These are the possibilities I know to get the current value of a URScript variabile in a URCap:

- Read it from Primary Interface - You have to write a “reader” for the packages sent by the controller, maybe based on this sample which is for Realtime: [getRobotData](https://forum.universal-robots.com/t/sample-getrobotdata-real-time-client-reader-urcap/1195)
- Send it from URScript through a socket to a java server (see [ScriptCommunicator](https://forum.universal-robots.com/t/urcap-scriptcommunicator/8460) or this older one [ScriptCommunicator](https://forum.universal-robots.com/t/sample-urscript-communicator-examples/3093))
- Send it from URScript through XML-RPC (see `mydaemonswing` sample or [Dialog Script URCap](https://forum.universal-robots.com/t/sample-urcap-with-xml-rpc-server-by-java-dialog-script-urcap/8707))

I think maybe the second method is the simplest one.

---

<div class="post-metadata">

**Author:** ![anon29287759](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anon29287759](https://forum.universal-robots.com/u/anon29287759)\
**Post date:** [November 24, 2020, 9:12am UTC](https://forum.universal-robots.com/t/get-variable-values-in-toolbar/10077/3 "2020-11-24T09:12:54Z")

</div>

I tried with the ScriptCommunicator (the ScriptExtractor part), but I can get only data by using built-in function like get\_…().Do you have an example where you get the value of a pose (like i\_home\_pose) or a general int variable (i\_var\_1) stored in the installation variables?

---

<div class="post-metadata">

**Author:** ![anon3164729](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon3164729](https://forum.universal-robots.com/u/anon3164729)\
**Post date:** [November 24, 2020, 10:37am UTC](https://forum.universal-robots.com/t/get-variable-values-in-toolbar/10077/4 "2020-11-24T10:37:49Z")

</div>

You are correct, I forgot I was using scriptExporter to export a value from the integer registers, as e.g.:

```
ScriptExporter export = new ScriptExporter();
ScriptCommand commandInt = new ScriptCommand("Command1");
commandInt.appendLine("int_value = read_output_integer_register(21)");
int resultInt = export.exportIntegerFromURScript(commandInt, "int_value");

```

So a possible workaround is to constantly copy the variable you are interested in to a register and read from that. Sorry but I don’t know if it is possible to read a variable with this code.

---

<div class="post-metadata">

**Author:** ![anon29287759](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anon29287759](https://forum.universal-robots.com/u/anon29287759)\
**Post date:** [November 24, 2020, 11:20am UTC](https://forum.universal-robots.com/t/get-variable-values-in-toolbar/10077/5 "2020-11-24T11:20:12Z")

</div>

Thank you!!! I did not know this feature, I’m testing it right now and it’s working. It is a good workaround.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/system/32/1_2.png) [@system](https://forum.universal-robots.com/u/system)\
**Post date:** [November 26, 2020, 11:20am UTC](https://forum.universal-robots.com/t/get-variable-values-in-toolbar/10077/6 "2020-11-26T11:20:12Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
