# Send / Create variables from URcap, they do not show up in Variable tab

**URL:** <https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773>\
**Category:** URCap Development\
**Tags:** variables, generate-script\
**Created:** [March 5, 2019, 11:31am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773 "2019-03-05T11:31:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon57702353](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon57702353](https://forum.universal-robots.com/u/anon57702353)\
**Post date:** [March 5, 2019, 11:31am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/1 "2019-03-05T11:31:32Z")

</div>

Hi everyone,  
I am facing an issue, I would like to be able to create a variable when adding my ProgramNode before executing the whole program.  
In this way I would be able to use this variable for example with an “if”. But I can manage to do it.

I tried sending URscripts commands with “global myVar = False” and tried the GlobalVariable from the SDK API too but they both have no effect.

Any tips on how to do this?

Thank you

Federico

---

<div class="post-metadata">

**Author:** ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)\
**Post date:** [March 5, 2019, 12:53pm UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/2 "2019-03-05T12:53:24Z")

</div>

If you want to send script from a URCap when a program isn’t running, you can use a secondary client interface, as outlined in jbm’s post in this thread:

> [@Can urcap send and execute ur script within the program node?](https://forum.universal-robots.com/t/can-urcap-send-and-execute-ur-script-within-the-program-node/378):
>
> I am try to write a URCap for saving pose and and assign it to variable. I also want to add an input button so that when i press it, it will execute movej or movel ur script for robot to move to target pose. Is it possible to execute ur script at this situation? similar case should be the “perform action now” button in Set or “Preview Popup” button in Popup. Here are the code that I am writing: [image] thanks

This allows you to send any URScript to the robot directly from within a ProgramNode, as opposed to script written in `generateScript`, which is only sent once you press play on the prgram.

---

<div class="post-metadata">

**Author:** ![anon57702353](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon57702353](https://forum.universal-robots.com/u/anon57702353)\
**Post date:** [March 5, 2019, 1:20pm UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/3 "2019-03-05T13:20:22Z")

</div>

Im not using the ScriptWriter but I am sending a TCP command which I think it’s the same thing the secondary client interface does, only through the URCap SDK

EDIT: Moreover in that way the script is only received if the robot is On and Started.

---

<div class="post-metadata">

**Author:** ![anon57702353](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon57702353](https://forum.universal-robots.com/u/anon57702353)\
**Post date:** [March 6, 2019, 10:22am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/4 "2019-03-06T10:22:20Z")

</div>

So I managed to make it work.

The problem with sending a command on the secondary interface is that is going to work only if the robot is up and running. But I think it needs to be working even when the only the teach pendant is on and the robot is idle.

So I used the GlobalVariable and VariableFactory from the SDK, which I found a bit confusing.

```
try {
     VariableFactory varFactory = api.getVariableModel().getVariableFactory();
     GlobalVariable myVar= varFactory.createGlobalVariable("var");
     model.set("var", myVar);
} catch (Exception e) {
     e.printStackTrace();
}

```

What I found confusing from the doc “Working\_with\_variables.pdf” was the model.set(SELECTED\_VAR, myVar) and the naming/registering. This way it works.

The only problem I have is that the variable is displayed in dropdown menus, for example if I put an assignement node I can see “myVar” but I cannot see it from the Variables tab. Any help on this?

---

<div class="post-metadata">

**Author:** ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)\
**Post date:** [March 6, 2019, 10:32am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/5 "2019-03-06T10:32:24Z")

</div>

I suspect the reason you can’t see it from the variables tab is because it hasn’t been assigned yet? The variable exists but doesn’t have a value so isn’t displayed. Try giving it a value and seeing if it pops up in the variables tab

---

<div class="post-metadata">

**Author:** ![anon57702353](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon57702353](https://forum.universal-robots.com/u/anon57702353)\
**Post date:** [March 29, 2019, 11:29am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/6 "2019-03-29T11:29:56Z")

</div>

well actually I am initializing all of them to an initial value with

`Expression initialValue = expressionBuilder.append("False").build();`

`GlobalVariable myVar = varFactory.createGlobalVariable("var", initialValue);`

But I cannot see them. Maybe something related with the model.set() ?

Federico

---

<div class="post-metadata">

**Author:** ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)\
**Post date:** [March 29, 2019, 11:51am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/7 "2019-03-29T11:51:23Z")

</div>

From what jacob said [here](https://forum.universal-robots.com/t/reading-installation-variable-values-to-urcap/3961/4), it seems that the value of a variabel is only known when a program is running, If you need the value of a polyscope variable in java, could you store it in a separate java variable and pass it to polyscope when needed?

---

<div class="post-metadata">

**Author:** ![anon57702353](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon57702353](https://forum.universal-robots.com/u/anon57702353)\
**Post date:** [March 29, 2019, 1:28pm UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/8 "2019-03-29T13:28:07Z")

</div>

I don’t need it in Java. I just need the variable to be present in the Variable Tab in Polyscope when writing the robot program.

Right now I can see the variable from the drop down list (e.g. wehn selecting variable with the assignment node or with If node).

If it’s not clear I can post a couple of pictures, in the meantime thank you.

Federico

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [March 29, 2019, 1:30pm UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/9 "2019-03-29T13:30:16Z")

</div>

Variables only show up in the Variables-tab, when they have been created by assignment in URScript.  
Before an assignment is made to them, they are not shown in the Variables tab.  
You may want to expressly “global” your variable like: `global varName = 42`

---

<div class="post-metadata">

**Author:** ![anon57702353](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon57702353](https://forum.universal-robots.com/u/anon57702353)\
**Post date:** [March 29, 2019, 2:41pm UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/10 "2019-03-29T14:41:01Z")

</div>

I tried sending an urscript command “global myVar = False” on secondary interface after creating the global variable but it’s still not showing on the URcaps Variables tab.

---

<div class="post-metadata">

**Author:** ![anon52646312](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@anon52646312](https://forum.universal-robots.com/u/anon52646312)\
**Post date:** [April 1, 2019, 11:39am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/11 "2019-04-01T11:39:36Z")

</div>

I am also facing the same issue.

I need to create new Variables and assign them a value and store them in the Variables tab found in the Installation screen, so that the value is retained when the robot is restarted.  
I tried sending the command `global varName = 42` through GenerateScript when a button is pressed; also followed the example of creating variables as per the working\_with\_variables.pdf (even though it creates the variable when the program is run) but no effect. Both approaches create variables that are available when the program is run and they disappear as soon as the robot is switched off.

@jbm Any suggestion on how to create a function in the Installation Node of a URCap that creates variables that retain the value and are stored for future use ? I do not wish to use the manual way of creating such variables from the Variables tab in the Installation screen

---

<div class="post-metadata">

**Author:** ![anon57702353](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon57702353](https://forum.universal-robots.com/u/anon57702353)\
**Post date:** [April 4, 2019, 10:09am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/12 "2019-04-04T10:09:31Z")

</div>

any update on this?

I still wasn’t able to display the variables until pressing Play on the robot

---

<div class="post-metadata">

**Author:** ![anon57702353](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon57702353](https://forum.universal-robots.com/u/anon57702353)\
**Post date:** [April 16, 2019, 8:49am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/14 "2019-04-16T08:49:51Z")

</div>

Ok it seems that this is giving me more problems than I though.

Apart from the variables not showing up in the “Variables” tab in the programming section what is happening is that I can create the global variables (and see them from drop down menus) but I am not able to change the values.

This is due to the fact that the variables names will get the suffix \_n but I will store them in the data model using the same name, i.e.:

```
ExpressionBuilder expressionBuilder = api.getValueFactoryProvider().createExpressionBuilder();
Expression initialValue = expressionBuilder.append("False").build();
VariableFactory varFactory = api.getVariableModel().getVariableFactory();
GlobalVariable myVar = varFactory.createGlobalVariable("MyVar_1", initialValue);
model.set("MyVar", myVar);

```

Then how can I modify the value from the generate script? I used something like:

```
line = "myVar= True\n";
writer.appendRaw(line);

```

But it’s just going to create a new variable “myVar” with the value and by the way it’s not going to be visible neither in the variables tab nor in the drop down menus.

---

<div class="post-metadata">

**Author:** ![anon57702353](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon57702353](https://forum.universal-robots.com/u/anon57702353)\
**Post date:** [April 16, 2019, 9:51am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/15 "2019-04-16T09:51:28Z")

</div>

Ok, so I was able to fix that by using ScriptWriter "getResolvedName(myVar) and use the returned string as var name in the script.

The problem of variables not showing up in the variable tab is still there though

---

<div class="post-metadata">

**Author:** ![Savoia](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/savoia/32/4844_2.png) [@Savoia](https://forum.universal-robots.com/u/Savoia)\
**Post date:** [January 27, 2021, 1:06am UTC](https://forum.universal-robots.com/t/send-create-variables-from-urcap-they-do-not-show-up-in-variable-tab/3773/16 "2021-01-27T01:06:36Z")

</div>


