RoboDK API

The RoboDK API (Application Program Interface) is a set of routines and commands that RoboDK exposes through a programming language. The RoboDK API allows you to program any robot using one of the supported programming languages, such as C#, Python or C++. You can also automate repetitive tasks using the RoboDK API.

Compared to vendor-specific robot programming, with the RoboDK API it is possible to simulate and program any robot using a unique/universal programming language, such as Python. The following page provides an overview and a video showing offline programming with the API.

The RoboDK API is available for Python, C#, C, C++, Visual Basic (.NET) and MATLAB. Any of these programming languages can be used to simulate and program any robot arm.

The RoboDK API can be used for the following tasks:

1.Automate the simulation: Create macros to automate specific tasks within the RoboDK simulator, such as moving objects, reference frames or robots.

2.Offline programming: Programming robots offline from a universal programming language. RoboDK will generate specific programs for a specific robot controller when the API is used (such as a program in Python or C#). The robot program is generated according to the post processor selected for a specific robot. The Offline Programming with Python section of this document provides more information and examples.

3.Online Programming: Programming robots online using a universal programming language: It is possible to move robots and retrieve their current position from the RoboDK API. RoboDK will drive the robots using robot drivers. The Online Programming with Python section in this document provides more information and examples.

In other words, the same program that is used for simulation (1) can be used to generate robot programs (2, Offline Programming) and to move the robot in real time (3, Online Programming).

This document covers the following topics:

The Python API with examples for Simulation, Offline Programming and Online Programming

The C# API with examples for Simulation, Offline Programming and Online Programming

The MATLAB API with a Simulink example for simulation

The Command line options to start RoboDK

Python API

Python is a widely used high-level programming language for general-purpose programming. Python is a programming language that lets you work faster and integrate your systems more effectively. Python's syntax allows programmers to express concepts in fewer lines of code compared to other languages, making it friendly and easy to learn.

The previous section explains the advantages of using the RoboDK API with a widely used programming language for robot programming such as Python.

Python is automatically installed and integrated with RoboDK by default. Select ToolsOptionsOther to change the default settings (Python location and Python Editor).

RoboDK API - Image 1

The RoboDK API for Python is divided in the following modules:

The robodk package is the distributed entry point of the Python API. It is the common parent of all sub-packages and modules.

The robolink sub-module (robolink.py) is the interface between RoboDK and Python. Any object in the RoboDK Station Tree can be retrieved using a Robolink object and it is represented by the Item object. It is possible to perform different operations on that item according to the Robolink.Item class.

The robomath sub-module (robomath.py) is a robotics toolbox for Python that allow operating with pose transformations and obtain Euler angles for different robot vendors. All post processors depend on this module.

The robodialogs sub-module (robodialogs.py) is a dialogs toolbox. For instance, open and save file dialogs, message prompts, etc.

The robofileio sub-module (robofileio.py) is a file operation toolbox. File properties, CSV, FTP, etc.

The roboapps sub-module (roboapps.py) is a RoboDK Apps toolbox. More infofmation on Apps is available here: AppLoader.

You can find the Python modules in the folder C:/RoboDK/Python/. This folder is automatically included by default (used as PYTHONPATH) when you run Python programs and post processors in RoboDK.

The following sections show how to create a simple program for simulation, offline programming and online programming respectively. More examples are available in the Python API for RoboDK page. Also, the RoboDK library comes with sample Python scripts in the folder Scripts and Macros, available in the default Library (C:/RoboDK/Library/).

Python Simulation

This example shows how to create a new station using a UR robot and simulate a hexagonal movement with the robot.

1.Select FileRoboDK API - Image 2 Open

2.Open the UR10 robot

3.Select FileRoboDK API - Image 3 Open

4.Open the Paint_gun.tool file

5.Open the sample Python program SampleOfflineProgramming.py from C:/RoboDK/Library/Macros/

6.Double click the SampleOfflineProgramming item to run the simulation. The robot should draw a hexagon around the current location of the robot and the trace of the TCP will be displayed in yellow. 
Alternatively, right click the program and select RoboDK API - Image 5Run Python Script.

7.Right click the RoboDK API - Image 6 SampleOfflineProgramming item and select Edit Python Script. We should see the program as shown in the following image.

The SampleOfflineProgramming macro will draw a polygon of side n_sides and radius R at the current location of the robot, with respect to the robot reference frame. If desired, move the robot to a different location changing the polygon dimensions and re-run the program.

This example is similar to the program displayed in the offline programming section of the website (video included).

RoboDK API - Image 7

Python OLP

Python programs can be generated offline using the same Python code used to simulate the robot (as shown in the previous Python Simulation section). Offline Programming allows generating robot programs that can be executed on a specific robot controller:

1.Right click a RoboDK API - Image 8Python program

2.Select Generate robot program (F6)

In this case the program is not simulated but executed quickly to obtain the result: a robot program specific to a robot controller.

RoboDK API - Image 9

RDK = Robolink()

RDK.setRunMode(RUNMODE_MAKE_ROBOTPROG)

Python Online Programming

Python programs can be directly executed on the robot using the same Python code used to simulate the robot (as shown in the Python Simulation section). Online programming allows running a generic program on a specific robot controller using Robot Drivers:

1.Right click a RoboDK API - Image 10Python program

2.Select Run on robot

The program will run on the robot as it the Python program is executed.

RoboDK API - Image 11

RDK = Robolink()

RDK.setRunMode(RUNMODE_RUN_ROBOT)

Troubleshooting Python setup in RoboDK

If you installed RoboDK after installing Python, RoboDK may fail to properly run Python scripts or generate programs. This section shows the steps you should follow to properly set the Python interpreter in RoboDK and run Python scripts without issues.

You should follow these steps if you see an error message such as: “Set the path to the Python interpreter in Tools-Options-Python” or “Failed to run Python script. Set the path to the Python interpreter in: Tools-Options-Python tab”.

Follow these steps to properly setup the Python interpreter path if you already have Python installed:

1.Select the Start Menu on Windows and type python.

2.Right click the Python version you would like to use with RoboDK and select Open file location.

RoboDK API - Image 12

Repeat this procedure on the folder that opens:

3.Right click on Python 3.7 and select Open file location.

RoboDK API - Image 13

4.Select Copy on the path in the path title bar.

RoboDK API - Image 14

Provide the Python path in RoboDK settings:

5.Open RoboDK.

6.Select Tools-Options.

7.Select the Python tab.

8.Paste the path in the Python interpreter box adding /python.exe, as shown in the next image. Using forward slashes or backslashes should both work.

RoboDK API - Image 15

C# API

The RoboDK API for C# is a RoboDK.cs source file that contains the RoboDK class (similar to Python’s Robolink class), the RoboDK.Item class (similar to Python’s Robolink.Item class API), and other tools for robotics such as a Matrix class (RoboDK.Mat) for matrix operations to operate with pose transformations.

C# (pronounced "C sharp") is a programming language developed by Microsoft and designed for building a variety of applications that run on the .NET Framework. C# is simple, powerful, type-safe, and object-oriented. The main section of this document explains the advantages of using the RoboDK API with a widely used programming language such as C# for robot programming.

The RoboDK API for C# is provided with a sample project as shown in the following image (the complete source code is included). It is also possible to use it as a NuGet package to integrate it in any .Net project.

RoboDK API - Image 16

Select Load File to open a RoboDK station or any other file supported by RoboDK. If a robot is loaded, the ROBOT variable will be updated accordingly (same as using Select Robot).

C# Simulation

C# programs are simulated by default when robot commands are used (such as MoveJ, MoveL or setDO). When the sample C# project is started, the simulation mode is also selected by default.

RoboDK API - Image 17

This means the robot movements will be simulated in RoboDK. For example, we can move the robot by steps of 10 mm selecting the buttons on the right (+Tx, -Tx, …), or we can select Run Test Program to run a hexagonal movement around the current location of the robot.

Set any breakpoints to debug your application and inspect robot targets. Robot targets can be defined as joint coordinates or Mat variables (4x4 pose Matrices) and they can be inspected as XYZWPR format to troubleshoot program issues. More information about reference frames in the Reference Frames section.

RoboDK API - Image 18

It is also possible to change the Run Mode to Offline Programming or Online Programming (Run on Robot), as shown in the following sections.


C# OLP

C# programs can be generated offline using the same C# code used to simulate the robot (Offline Programming). Follow these steps to test this feature:

1.Select Offline Programming in the Run Mode section

2.Select Run Test Program or any other combination of movements

3.Select Generate Prog to obtain the vendor-specific robot program

In this case the program is not simulated but quickly executed to obtain the result: a robot program specific to a robot controller. The Run Mode will be changed back to Simulation once the program is generated.

RoboDK API - Image 19


C# Online Programming

C# programs can be directly executed on the robot using the same C# code used for simulation. Online programming allows running a generic program on a specific robot controller using Robot Drivers. Follow these steps to test this feature using the C# sample project:

1.Select Run on Robot in the Run Mode section

2.Select any other commands that will make a robot move

The movements will run on the real robot and the simulator will synchronize the movements with the robot.

RoboDK API - Image 20

RDK = Robolink();

RDK.setRunMode(RUNMODE_RUN_ROBOT);

MATLAB API

MATLAB is a proprietary programming language developed by MathWorks. Among other things, MATLAB allows matrix manipulations, plotting of functions and data and implementation of algorithms. RoboDK is an official MathWorks Connections Program Partner.

The RoboDK API for MATLAB is provided as a group of script files (m-files), available here:

In the installation folder of RoboDK, typically C:/RoboDK/Matlab/.

On MathWorks MATLAB Central.

On the RoboDK API GitHub.

The main section of this document explains the advantages of using the RoboDK API with a widely used programming language such as MATLAB for robot programming.

The RoboDK API for MATLAB includes:

Robolink.m is a class that interfaces with RoboDK. Any object in the RoboDK Station Tree can be retrieved using the Robolink object and it is represented by the RobolinkItem object (same as Python’s Robolink class).

RobolinkItem.m is a class that represents a RoboDK item in the Station Tree. It is possible to perform different operations on that item (same as Python’s Robolink.Item class).

transl.m, rotx.m, roty.m and rotz.m are functions that create pose matrices given an XYZ translation vector or rotations along a specific axis.

Pose_2_XYZRPW.m and XYZRPW_2_Pose.m allow converting poses to XYZ position and RPW Euler angles and vice versa. More information in the Reference Frames section.

The following page presents multiple examples of the RoboDK MATLAB API, such as manipulating items, generating robot programs and controlling the robot:  
https://robodk.com/Matlab-API

Simulink Example

A Simulink project is available as an example. In the simulation, the robot is moved along a set of XYZ coordinates generated arbitrarily.

RoboDK API - Image 21

Command Line Options

This section describes the command line options available when RoboDK is started. Command line options can also be passed using the Command function of the API.

This section shows some relevant commands that can help you customize how RoboDK starts up. Select Tools-Run Script-ShowCommands to display additional commands you can use when starting RoboDK.

The following call represents a generic call to RoboDK with some arguments:

RoboDK.exe -[option1] -[option2] open_fileA -[option3] open_fileB ...

All file formats supported by RoboDK can be provided as arguments. Including the following formats:

RDK    RoboDK station file: This file holds a whole project in one file, including any dependencies (robots, tools, NC files, …).

robot    Robot file: Loading a robot file will also create a reference frame for that robot.

tool      Tool file: Automatically attached to the last robot added.

stl/wrl/step/stp/iges/igs/sld Object (3D geometry): Objects can easily be converted to tools.

apt/gcode/cnc NC program file: RoboDK automatically prepares a milling project (UtilitiesMilling Project).

RDK = Robolink(args='-ADDFRAME "-RENAME=Main Ref " load_object.stl')

The following list shows some of the available command line Options:

-NOSPLASH

Removes the RoboDK splash image on start.

-HIDDEN

Starts RoboDK hidden. You will need to use the API to show RoboDK.

-NEWINSTANCE

Force starting a new instance of RoboDK.

-PORT=20501

Force the API communication through the given port (TCP/IP protocol). Default port is 20500.

-EXIT_LAST_COM

Close RoboDK when there are no more instances communicating with the RoboDK API.

-DEBUG

Creates a RoboDK.debug.txt file in the bin folder that allows debugging the application.

-SKIPINI

Skip custom user settings.

-SKIPMAINT

Skip maintenance renewal popups. One month before the maintenance expires, RoboDK may show a blocking popup on startup to renew the license. This parameter allows you to mute this warning.

-SETTINGS=filepath

Loads the arguments from a text file. Each line of that text file is considered as a one single argument.

-NOSHOW

Hides all windows while RoboDK is loading files and updating programs.

-NO_WINDOWS

Hides all windows that are usually shown automatically when loading an NC file.

-NOUI

Start RoboDK without the User Interface (Window and 3D view). Use this option to run RoboDK in the background using the API. If you show RoboDK you won’t be able to see the 3D view.

-TREE_STATE=-1

Don’t show the station tree.

-TREE_STATE=6

Show the station tree docked on the left side of the window and opaque.

-ADDFRAME

Adds a new reference frame. Any new objects loaded will be placed in this reference frame.

-RESET

Forces that if a new object is loaded it will be placed at the station reference frame (not the last added frame).

-RENAME=Name

Changes the name of the last reference frame or object that was added.

-MOVE=x;y;z;rx;ry;rz

Moves the last reference frame that was added (in mm and degrees).

-UPDATE_APT=YES

Will override any robot machining projects that have the same APT file

-UPDATE_APT=NO

Does not override any robot machining projects (will create duplicate projects if there is a name match).

-UPDATE=file.apt

Loads or updates the APT file and generates the robot program if there are no issues.

-REPLACE_ITEMS=YES

Updates existing tools and objects when new files are loaded and there is a name match.

-REPLACE_ITEMS=NO

Never overrides tools and objects when new files are loaded.

-SETCOLOR=blue

Set the color of the last loaded object (object, tool, robot or mechanism). The color can be a named color or a hexadecimal color (such as #RRGGBBAA, example: #88112288).

-AUTOGEN_MAINPROG=Prog

Generates a main program that calls the programs linked to loaded APT files sequentially.

-SELECTTOOL=#1

Set the first robot tool (or corresponding number) available as the active tool (the tool used when a new program is loaded).

-SELECTTOOL=”tool name”

Select the active tool using a name match.

-ADDCUTTER=length|path/cutter name.stl

Addcutter allows adding the geometry of a cutter with respect to a tool holder. A cutter is treated as a tool in RoboDK, holding the geometry of the cutter. The geometry of the cutter must be an STL file (ASCII or binary) with the origin at the tip of the tool. The length must be given in mm with respect to the tool holder (the positive Z axis of the tool holder must point outside).

-SELECTCUTTER=”cutter name”

Selectcutter has the same effect as SELECTTOOL, cutters are treated as tools.

-SHOW

Shows the RoboDK window. This is automatically done when all files have been loaded and machining projects have been updated.

Using one of the following options will alter the visibility provoked by the -SHOW command.

-QUIT

Exits the program if there are no error messages.

-END

Exits the program even if there are any error messages.