Have a look here: URCap Sample: URScript Communicator examples In particular the class ScriptExporter.
ScriptExporter