Load station from addin

mathiasmathias Lund, Sweden
Hi, I am trying to load a station into robotstudio from an addin when robotstudio starts up, but I am not succeeding.


I have created an addin and configured the rsaddin configuration file with <Dependencies>None</Dependencies> to enable the addin to start immediately upon launching RobotStudio.

In order to give the RS environment some breathing space when starting I have hooked up a small state machine on the idle callback.

            UIEnvironment.Idle += SequencedSetup;

I use this state machine to perform the load.

        private static void SequencedSetup(object sender, EventArgs e)
        {
            Station station = null;
            switch (state)
            {
                case 0:
                    if (Project.ActiveProject == null && !Station.IsLoading)
                    {
                        var ctrl = UIEnvironment.CommandBarControls["FileNewEmptyStation"];
                        var btn = ctrl as CommandBarButton;
                        btn.Execute();
                    }
                    if (Project.ActiveProject != null)
                    {
                        state++;
                    }
                    break;
                case 1:
                    string path = AppData.Path + "\\RobotStudio\\Stations\\xxx.rsstn";
                    station = Station.Load(path, false);
                    state++;
                    break;
                case 2:
                    if (!Station.IsLoading)
                        state++;
                    break;
                case 3:
                    Project.ActiveProject = station;
                    UIEnvironment.Idle -= SequencedSetup;
                    break;
            }
        }

I am trying to get the Station.Load method to work. First, it seems that RS is unable to call the method unless there is a station previously loaded, I have solved this with a "hack", i.e. state 0, then the station is loaded in state 1, waiting for completion in state 2 and finally set as active in state 3. The code executes all states with no error message, but in later states the station does not load. If I load the station manually in RS it works. What am I doing wrong?

Comments

Sign In or Register to comment.