# \[IMPLEMENTED\] Adding variables

**URL:** <https://forum.universal-robots.com/t/implemented-adding-variables/675>\
**Category:** Product Wishlist\
**Created:** [April 11, 2017, 8:02am UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675 "2017-04-11T08:02:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon58840761](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@anon58840761](https://forum.universal-robots.com/u/anon58840761)\
**Post date:** [April 11, 2017, 8:02am UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/1 "2017-04-11T08:02:54Z")

</div>

Is it possible to add variable in here like this? If yes then how?  
In your example com.ur.urcap.examples.scriptfunction you have done it with functions.

I want to dynamically change a certain variable while the robot is running, that should be possible right?  
cheers.

 ![](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/b29a0d44fb19999ff0aa78b69a016eaa3c37ac29.png)

---

<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:** [May 10, 2017, 9:11am UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/2 "2017-05-10T09:11:54Z")

</div>

Currently, it is only possible to show PolyScope generated variables (Installation variables and by Assignment) in the “Variables” list.

I believe using functions to read and write certain variables would be a more robust way to access your variables, instead of just overwriting another variable. Especially from a “variable ownership” point of view. So it would be my recommendation to create a “get” and “set” function in the dropdown list, to be able to access your variables.

---

<div class="post-metadata">

**Author:** ![anon16416181](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon16416181](https://forum.universal-robots.com/u/anon16416181)\
**Post date:** [May 29, 2017, 6:39pm UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/3 "2017-05-29T18:39:44Z")

</div>

Hi @jbm,  
I was looking into this also. Where do I have to look to add installation variables to that list? Is there an example around?  
Thanks!

---

<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:** [May 29, 2017, 6:43pm UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/4 "2017-05-29T18:43:46Z")

</div>

Simply go to the Installation tab, and then Variables.

---

<div class="post-metadata">

**Author:** ![anon16416181](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon16416181](https://forum.universal-robots.com/u/anon16416181)\
**Post date:** [May 29, 2017, 6:48pm UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/5 "2017-05-29T18:48:17Z")

</div>

Oh I see, thanks!  
Can that be done within a URCap, like it is with functions in the “scriptfunction” sample? I mean, can a URCap generate assignments that add the assigned variables to the list from the installation node? (something like a `VariableModel`)

---

<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:** [November 27, 2017, 1:20pm UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/6 "2017-11-27T13:20:28Z")

</div>

Check out the new 3.5 release, this feature have now been implemented.  
[Release of 3.5](http://forum.universal-robots.com/t/release-of-polyscope-3-5-and-sdk-1-2/1365)

---

<div class="post-metadata">

**Author:** ![jea](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@jea](https://forum.universal-robots.com/u/jea)\
**Post date:** [March 20, 2018, 12:01pm UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/7 "2018-03-20T12:01:46Z")

</div>

Hi @jbm  
I have a question regarding this: As I read your response here, it is possible to create new variables through the installation contribution of a URCap. I have been trying to do exactly that, but ended up stopping since it is stated in the “working\_with\_variables.pdf” that: “Note that variables should not be used in an  
URCap installation node contribution, since it is a programming construct only  
used at runtime of a robot program.” (pg. 3, sec. 2)  
How is it possible to create and assign variables from the installation contribution, like @anon16416181 ask?

---

<div class="post-metadata">

**Author:** ![roman.reiner](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/roman.reiner/32/1294_2.png) [@roman.reiner](https://forum.universal-robots.com/u/roman.reiner)\
**Post date:** [March 22, 2018, 5:00pm UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/8 "2018-03-22T17:00:58Z")

</div>

In the installation contribution part of your URCap you add and remove functions that can be used to assign variables during run time. Here is an example of how to add/remove functions to the function model. ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/08e343df67eed842d7861e23c78a7c7903693d1b.png)

The functions will need to be within the generateScript(ScriptWriter writer) portion of the URCap installation contribution example: ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/d50de8bf9cc2d6c103a6fa45a1999688e32f2de8.png)

Adding the function to the function model would then be: ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/d0c6b93ffb2d52d90475954cefdba89a404dceb7.png)

Now within the program tree of the UR you can assign a variable from the function drop down menu example:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/afafb1c8db8de2cb924481d8fd0d7eafd20b4d8e.png) ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/a7e86a750e40f294edcd61544036c9a478c73687.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/03a44d01b2a29cfaf5f9cde57bc2e710452174dc.png)

Sorry for long post but hope this helps you out!

---

<div class="post-metadata">

**Author:** ![anon24511591](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@anon24511591](https://forum.universal-robots.com/u/anon24511591)\
**Post date:** [May 27, 2020, 8:13am UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/9 "2020-05-27T08:13:19Z")

</div>

What if I want to add a function that returns something depending on the model?  
i.e. I have a series of positions set in the installation node and I want to get position N.  
I can `addFunction("get_position","index")` but then I cannot simply define a static script like the example, I need to examine the value of `"index"` at runtime and return the corresponding position stored in the model.  
_Edit_ oh, and throw an error if the index is out of range.

---

<div class="post-metadata">

**Author:** ![anon24511591](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@anon24511591](https://forum.universal-robots.com/u/anon24511591)\
**Post date:** [May 27, 2020, 11:14am UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/10 "2020-05-27T11:14:36Z")

</div>

I started writing a program node for that, but it has the same problem: the generateScript method is called only once so I need a way to inspect the current value of the variables and get the position from the installation node depending on that and I could find no examples on how to do that.

---

<div class="post-metadata">

**Author:** ![anon24511591](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@anon24511591](https://forum.universal-robots.com/u/anon24511591)\
**Post date:** [May 27, 2020, 11:37am UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/11 "2020-05-27T11:37:24Z")

</div>

I think that what I want to do is impossible. Oh, well, I’ll go on with the band-aid solution I’m using now.

---

<div class="post-metadata">

**Author:** ![anon24511591](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@anon24511591](https://forum.universal-robots.com/u/anon24511591)\
**Post date:** [May 29, 2020, 2:04pm UTC](https://forum.universal-robots.com/t/implemented-adding-variables/675/12 "2020-05-29T14:04:20Z")

</div>

In case somebody is interested, I programmed an xmlrpc server in my urcap and the urscript function simply uses an xmlrpc client to obtain the indexed pose from the installation node.  
I would have preferred to be able to extend the urscript interpreter with a real function but this is working now.  
BTW: I didn’t like java too much before, now that I’ve been forced to program in it I hate it with a passion.
