Import Script in another Script

How to call another robin script from existing script.

@jpap Thanks in advance.

1 Like

@harikrushna.bhosale hi.

Currently it is not possible to execute .robin scripts from inside another Robin script.
You could either utilize rules (like labels) to redirect and execute specific functionality or follow a functional design that runs scripts sequentially and utilize the C# program I developed.
You can download and build the source. The only thing you should do is set the path where you have saved your .robin scripts, then the application will execute them through the command line sequentially (the sequence happens alphabetically).

Best regards,
J.

1 Like

Thanks, @jpap. I have a related question, which perhaps should go on a wish list rather than here:

Might we at some point be able have what amounts to an ‘#Include’ directive? (Perhaps it already exists and I just haven’t found it.)

Just for clarification, by that I mean being able to include the contents of an existing Robin script by a reference to its location in the file system.

Best regards,
burque505

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RobinMerge
{
class Program
{
static List Includes = new List();
static string OutFilename = string.Empty;

    static void Main(string[] args)
    {
        if (args.Count() != 2)
        {
            Console.WriteLine("RobinMerge <main.robin> <output.robin>");
        }
        else
        {
            OutFilename = args[1];
            using (StreamWriter w = new StreamWriter(OutFilename))
            {
                ProcessFile(args[0], w);
            }
        }
    }

    private static void ProcessFile(string filename, StreamWriter w)
    {
        string line;
        using (var reader = new System.IO.StreamReader(filename))
        {
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Trim().StartsWith("include"))
                {
                    string[] splitParts = line.Split('"');
                    if (splitParts.Count() == 3)
                    {   // valid include found
                        if (!Includes.Contains(splitParts[1]))
                        {
                            Includes.Add(splitParts[1]);
                            ProcessFile(splitParts[1], w);
                        }
                    }
                }
                else
                {   // normal line -> add to output
                    w.WriteLine(line);
                }
            }
        }
    }
}

}

Create a console application and use this code.
The program will replace all include lines that it finds with the content of the file that is adressed after the include. The resulting output file will be a robin file with all separated files included. :grinning:

I called my console app: RobinMerge
so the call would be: RobinMerge.exe Main.robin Final.robin
when the Main.robin file looks like
main
the additional file
Additional

and the final file
final

Have fun

3 Likes

Great example @Code4FunVienna!
Feel free to post it as a separate guide for everyone to be able to find it!
Thank you and looking forward to the next one!

Best regards,
J.

2 Likes

@Code4FunVienna, beautiful. Kudos!
Regards,
burque505

2 Likes