# URCap for calling URscript

**URL:** <https://forum.universal-robots.com/t/urcap-for-calling-urscript/3988>\
**Category:** URScript\
**Created:** [March 30, 2019, 9:43am UTC](https://forum.universal-robots.com/t/urcap-for-calling-urscript/3988 "2019-03-30T09:43:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon94763411](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@anon94763411](https://forum.universal-robots.com/u/anon94763411)\
**Post date:** [March 30, 2019, 9:43am UTC](https://forum.universal-robots.com/t/urcap-for-calling-urscript/3988/1 "2019-03-30T09:43:25Z")

</div>

I am working on URcap project. I have prepare a code in URScript. The following URScript is of 200 lines. I want to write a script in generate script() function. Is there any way that I can directly call a function for URscript instrad of writting 200 line code.

---

<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:** [April 1, 2019, 6:58am UTC](https://forum.universal-robots.com/t/urcap-for-calling-urscript/3988/2 "2019-04-01T06:58:52Z")

</div>

You could place your 200 lines of script code in a file in your resources folder.  
Then read this file, and use the ScriptWriter `appendRaw()` method.

---

<div class="post-metadata">

**Author:** ![anon94763411](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@anon94763411](https://forum.universal-robots.com/u/anon94763411)\
**Post date:** [April 1, 2019, 4:56pm UTC](https://forum.universal-robots.com/t/urcap-for-calling-urscript/3988/3 "2019-04-01T16:56:21Z")

</div>

Thanks Jacob. So the appendRaw() will able to compile full URScript.  
Is this a correct way to do it.  
@Override  
public void generateScript(ScriptWriter writer) {  
writer.appendRaw( **"home/rohan/Documents/URDevelopment/URCap/resources/impl/temp.script**");

---

<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:** [April 2, 2019, 6:41am UTC](https://forum.universal-robots.com/t/urcap-for-calling-urscript/3988/4 "2019-04-02T06:41:57Z")

</div>

According to the Javadoc, the `appendRaw()` method will append the raw script to the ScriptWriter, without auto-indentation and similar. This means you can import this from i.e. a file which has indentation and so on.

Unfortunately, the approach is not just quite as easy, as you suggest above.  
You need to open and read the file. I suggest you take a look at this sample:

> [@URCap Sample: Script Wrapper URCap](https://forum.universal-robots.com/t/sample-script-wapper-urcap/1196):
>
> Script Wapper URCap Description of functionality: This URCap wraps the contents of a selected script file into a program node in PolyScope. The user can select which script file to wrap, and select a decent image to show instead. User must place a script file (.script) and optionally image (.jpg, .jpeg, .png .bmp) in the /programs/ folder on a real robot, or /home/ur/ursim-current/programs/ in a URSim. The URCap checks the robots serial number, to decide what folder to look in. The sample d…
