Creating a RobotStudio Add-In
This example provides information on creating a RobotStudio Add-in project using Microsoft Visual Studio. This project can be used to run examples.
Note
If Visual Studio is installed on the computer before installing RobotStudio, or if you have installed the RobotStudio SDK, you will have the RobotStudio Add-In and SmartComponent project templates available in your computer. In this case, it is not necessary to follow these steps. Creating a new New Project and selecting any RobotStudio Add-In/Smart Component template generates the files described in the following steps.
The recommended and easiest way of creating a Add-In is by using a Visual Studio template included in the RobotStudio SDK installation.
Creating a RobotStudio Add-In.
Open visual Studio and select New Project.... From the list of available templates, select RobotStudio <version> Empty Add-in and choose a name for the project.
Add the following line of code in the "AddInMain" method. This will make the Add-In greet the user whenever it is loaded.
using System; using System.Collections.Generic; using System.Text; using ABB.Robotics.Math; using ABB.Robotics.RobotStudio; using ABB.Robotics.RobotStudio.Environment; using ABB.Robotics.RobotStudio.Stations; // To activate this Add-in you have to copy RobotStudioEmptyAddin6.rsaddin // to the Add-In directory, typically // C:\Program Files (x86)\Common Files\ABB\RobotStudio\AddIns namespace RobotStudioEmptyAddin { public class Class1 { // This is the entry point which will be called when the Add-in is loaded public static void AddinMain() { Logger.AddMessage(new LogMessage("Hello, I am a RobotStudio Add-In!")); } } }
Execute the Build command in Visual Studio to compile the code and generate an .rsaddin file for the Add-In. This .rsaddin file is the responsible to make RobotStudio load the Add-In's assembly (the .dll file).
Copy the .rsaddin file from the project directory to RobotStudio's Add-In folder, by default this is located in
C:\Program Files (x86)\ABB\RobotStudio version\Bin\Addins
.Load the Add-In in RobotStudio by navigating to the Add-Ins and selecting your Add-In from the drop down menu in the left panel. You will see your greeting message when the Add-In is loaded.
Creating an Add-In Project manually
Create a new project with Class Library as your template. In this example, the project will be called "AddIn1".
To use the RobotStudio API you need to reference the ABB.Robotics.*.dll assemblies. These are:
ABB.Robotics.Math
- Vector and matrix math.ABB.Robotics.RobotStudio
- General and top-level (e.g. non-station specific) classes.ABB.Robotics.RobotStudio.Environment
- For manipulating the GUI, e.g. adding menus and buttons etc.ABB.Robotics.RobotStudio.Stations
- For manipulating stations and their contents.ABB.Robotics.RobotStudio.Stations.Forms
- GUI controls used by RobotStudio.
To add references, refer to section Adding references to your code.
Add the following lines to the top of your code:
using ABB.Robotics.Math; using ABB.Robotics.RobotStudio; using ABB.Robotics.RobotStudio.Environment; using ABB.Robotics.RobotStudio.Stations; using ABB.Robotics.RobotStudio.Stations.Forms;
Add the following code to the class:
public static void AddinMain() { // This is where you write your code. }
The
AddinMain()
-method is the entry point for your Add-in.Add an XML file the to the project and change the name to AddIn1.rsaddin. The .rsaddin file, which provides information about the Add-In to RobotStudio, is optional.
<?xml version="1.0" encoding="utf-8" ?> <RobotStudioAddIn xmlns="urn:abb-robotics-robotstudio-addin" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:abb-robotics-robotstudio-addin file:///C:\Program%20Files%20(x86)\ABB\SDK\RobotStudio%202020%20SDK\RobotStudioAddin.xsd" autoLoad="false"> <ApplicationId>com.mycompany.AddIn1</ApplicationId> <AddInType>General</AddInType> <Assembly> <FileName>AddIn1.dll</FileName> <Path>c:\users\user\documents\visual studio 2019\Projects\AddIn1\AddIn1\bin\Debug</Path> <Path>c:\users\user\documents\visual studio 2019\Projects\AddIn1\AddIn1\bin\Release</Path> </Assembly> <MinimumHostVersion>20</MinimumHostVersion> <Dependencies>Station</Dependencies> <Platform>Any</Platform> </RobotStudioAddIn>
Adding references to your code
Some of the examples requires you to add a new reference to your Add-in. To do this, right click on "References" in the Project Explorer/Solution Explorer and choose Add Reference.... This will bring up a new window where you can choose which component to add a reference to. If it is a .Net reference, just scroll the first window and select the one you want. The click on OK to add it. If it is a RobotStudio reference, go to the Browse tab and browse to your RobotStudio SDK directory (normally this is
C:\Program Files (x86)\ABB\SDK\RobotStudio version SDK
) and choose which .dll you want to reference. After that, add a using statement for the namespace used in the referenced assembly in the beginning of your code file. For example:using System.IO;
To use the PCSDK API you need to reference the following assemblies. These are:
using ABB.Robotics; using ABB.Robotics.Controllers;
PCSDK references are normally found in
%ProgramFiles(X86)%\ABB\SDK\PCSDK version
.
Automating common Build operations
To automatically copy an Add-In's .dll to RobotStudios Add-In directory, go to the properties of the project (right-click the project in the Solution Explorer and select Properties) and select the Build Events. Add the following line to the Post-built event command line:
XCopy /y "$(TargetPath)" "%ProgramFiles(x86)%\ABB\RobotStudio version\Bin\Addins"
Assuming that this is the directory for your RobotStudio installation. This will copy your Add-in .dll file to the RobotStudio Add-in directory when building your Add-in.To automatically load your Add-In when RobotStudio starts, navigate to the Add-In's menu and select your Add-in under the General folder. Right click on your Add-in and select whether or not it should auto-load. If the Add-In is not loaded yet, it is possible to load it into RobotStudio from here.