RobotStudio event

Creating Button

The RobotStudio Development Center offers a description inclusive example source code for creating a button in RS.
http://developercenter.robotstudio.com/Index.aspx?DevCenter=RobotStudio&OpenDocument&Url=html/ad7828b5-c307-4562-905c-ea1981c2bfb8.htm

I copied the code into my VisualStudio 15, but I do not get any result in RobotStudio. I mentioned that the code is not completed.
For example is the command "using System.Drawing" missing.

Can anyone help me to fix this code, so I have something to work with?

Thank you, Sebastian

Comments

  • You must add 'System.Drawing' dll reference in your visual studio solution.
    Something more or less like this: References -> Add Reference -> Framework -> Find and Select 'System.Drawing'

    Regards
  • thank you haryprabs, but I already had the *.Drawing included. I also have the post-build event

    XCopy /y "$(TargetPath)" "C:\Program Files (x86)\ABB Industrial IT\Robotics IT\RobotStudio 6.02\Bin\Addins" 

    implemented. This works fine, the .dll-copy is in the correct folder, but I don't see anything in RobotStudio, which also opens automatically.

    Any suggestions?
  • Have you done this:
    Go to add-in tab. Under general folder you will find list of add-in then load or enable autoload.
    Otherwise can you share your code snippet. It should look like this:
    public static void AddinMain()
    {
      CreateButton();
    }
    private void CreateButton()
    {
      //Write code to create button as in the example source code
    }

    Regards
  • my add-in actually doesn't even appear in RobotStudio, although, I have the copy-command in the project-properties.

    My code looks like this:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Drawing;
    using System.Windows.Forms;

    using ABB.Robotics.Math;
    using ABB.Robotics.RobotStudio;
    using ABB.Robotics.RobotStudio.Environment;
    using ABB.Robotics.RobotStudio.Stations;

    namespace Add_Button_RS
    {
        public class tab
        {
            
            private void button_ExecuteCommand(object sender, ExecuteCommandEventArgs e)
            {
                //Perform any action like creating paths and targets
            }

            private void button_UpdateCommandUI(object sender, UpdateCommandUIEventArgs e)
            {
                // This enables the button, instead of "button1.Enabled = true".
                e.Enabled = true;
            }

            private void CreateButton()
            {
                //Begin UndoStep
                Project.UndoContext.BeginUndoStep("Add Buttons");

                try
                {
                    // Create a new tab.
                    RibbonTab ribbonTab = new RibbonTab("MyTab", "MyTab");
                    UIEnvironment.RibbonTabs.Add(ribbonTab);
                    //make tab as active tab
                    UIEnvironment.ActiveRibbonTab = ribbonTab;

                    // Create a group for buttons
                    RibbonGroup ribbonGroup = new RibbonGroup("MyButtons", "MyButton");

                    // Create first small button
                    CommandBarButton buttonFirst = new CommandBarButton("MyFirstButton", "MyFirstButton");
                    buttonFirst.HelpText = "Help text for small button";
                    buttonFirst.Image = Image.FromFile(@C:\Users\sebastian\Offline\Programmierung_o\button-test\button.png);
                    buttonFirst.DefaultEnabled = true;
                    ribbonGroup.Controls.Add(buttonFirst);

                    //Include Seperator between buttons
                    CommandBarSeparator seperator = new CommandBarSeparator();
                    ribbonGroup.Controls.Add(seperator);

                    // Create second button. The largeness of the button is determined by RibbonControlLayout
                    CommandBarButton buttonSecond = new CommandBarButton("MySecondButton", "MySecondButton");
                    buttonSecond.HelpText = "Help text for large button";

                    // Set the image of the button.
                    buttonSecond.Image = Image.FromFile(@C:\Users\sebastian\Offline\Programmierung_o\button-test\button.png);
                    buttonSecond.DefaultEnabled = true;
                    ribbonGroup.Controls.Add(buttonSecond);

                    // Set the size of the buttons.
                    RibbonControlLayout[] ribbonControlLayout = { RibbonControlLayout.Small, RibbonControlLayout.Large };
                    ribbonGroup.SetControlLayout(buttonFirst, ribbonControlLayout[0]);
                    ribbonGroup.SetControlLayout(buttonSecond, ribbonControlLayout[1]);

                    //Add ribbon group to ribbon tab
                    ribbonTab.Groups.Add(ribbonGroup);

                    // Add an event handler.
                    buttonFirst.UpdateCommandUI += new UpdateCommandUIEventHandler(button_UpdateCommandUI);
                    // Add an event handler for pressing the button.
                    buttonFirst.ExecuteCommand += new ExecuteCommandEventHandler(button_ExecuteCommand);

                }
                catch (Exception ex)
                {
                    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
                    Logger.AddMessage(new LogMessage(ex.Message.ToString()));
                }
                finally
                {
                    Project.UndoContext.EndUndoStep();
                }
            }

        }

        public class window
        {
            internal class Forms
            {
                internal class Control
                {
                }
            }

            private static void AddDocumentWindow()
            {
                //Begin UndoStep
                Project.UndoContext.BeginUndoStep("AddDocumentWindow");

                try
                {
                    System.Windows.Forms.Control control = new System.Windows.Forms.Control();
                    DocumentWindow window = new DocumentWindow(Guid.NewGuid(), control, "MyDocumentWindow");
                    UIEnvironment.Windows.Add(window);

                }
                catch (Exception ex)
                {
                    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
                    Logger.AddMessage(new LogMessage(ex.Message.ToString()));
                }
                finally
                {
                    Project.UndoContext.EndUndoStep();
                }
            }
        }
    }
  • Where is 'AddinMain' method? This method is the entry point as stated at point 4 in this tutorial
    http://developercenter.robotstudio.com/Index.aspx?DevCenter=RobotStudio&OpenDocument&Title=Creating%20RobotStudio%20Add-in

    From this method, call CreateButton() method.

    Regards
  • sebastian_staudinger
    edited March 2016
    Thank you! Now I can see my Tab...finally :smile: 

    But shouldn't there also be a RibbonGroup and a Button!? :sweat: