Add In Problem "NullReferenceExeption" .NET excption on Robot Studio SDK

right now I am trying to program an ADD-IN for Robot Studio. As described under the link : "", I use Visual Studio an have the Robot Studio SDK installed. 

If i use the first example "Creating a Robot Studio add-in" ( it works out pretty well. After putting the .dll and .rsaddin files in the appropriatet folder, I can display a text file in Robot Studio. So Robot Studio basically recognizes my programed ADD-IN an is able to execute it. :blush: 

My next attempt is to create a simple robot via an ADD-IN. So I oriented myself to the example "Creating a Robot with Custom parts".

I used parts of the given example source code. When i try to activate the Add in i get a "NullReferenceException" Error-Message from Robot Studio: 

When I proceed the source code step by step - at the line 37 - of creating a "new Part()" for the basePart, the new part becomes null/zero and that is the Point where the source jumps into the "catch" and an Error appears. 

The description of the Class "Part" says: "A Part is a container for bodies, and can hold zero or more bodies. A part also contains an orientation." 
I am confused because the error comes before I can assign something to the "new Part()" and the descriptions also says zero is okay,.. :neutral: 

I Hope somebody has an idea or can Help me,.. I would be incredibly thankful !!!!!! :smiley:


Complete source:

using System;
using System.Collections.Generic;
using System.Text;
//Hinzugefügt - Verweise - add - .NEt und System.AddIn
using System.IO;
using ABB.Robotics;
using ABB.Robotics.RobotStudio.Controllers;
using ABB.Robotics.Math;
using ABB.Robotics.RobotStudio;
using ABB.Robotics.RobotStudio.Environment;
using ABB.Robotics.RobotStudio.Stations;
using ABB.Robotics.RobotStudio.Stations.Forms;
// Die XXXXXX.rsaddin muss in den Addin File von Robot Studio   kopiert werden
//  C:\Program Files (x86)\Common Files\ABB Industrial IT\Robotics IT\RobotStudio\AddIns
namespace RobotStudioEmptyAddin1
    public class Class1
        public static void AddinMain()
            Logger.AddMessage(new LogMessage("Dies ist ein Test-Addin für RobotStudio"));
        private static void BaueEinenRobbi()
            Project.UndoContext.BeginUndoStep("Create A Robot");
            Station station_1 = Project.ActiveProject as Station;

            Part basePart = new Part();
            Body baseBody = Body.CreateSolidBox(new Matrix4(new Vector3(0, 0, 0)), new Vector3(0.3, 0.3, 0.3));

            Part linkPart_1 = new Part();
            Body linkBody_1 = Body.CreateSolidCylinder(new Matrix4(new Vector3(0, 0, 0)), 0.05, 0.5);

            //Shape an die richtige Stelle verschieben:
            linkBody_1.Transform.RX = Globals.DegToRad(-90);
            linkBody_1.Transform.Translation = new Vector3(0.15, 0, 0.35);
            Part linkPart_2 = new Part();
            Body linkBody_2_torus = Body.CreateSolidTorus(new Matrix4(new Vector3(0, 0, 0)), 0.1, 0.05);

            //Shape an die richtige Stelle verschieben:
            linkBody_2_torus.Transform.RY = Globals.DegToRad(90);
            linkBody_2_torus.Transform.RZ = Globals.DegToRad(90);
            linkBody_2_torus.Transform.Translation = new Vector3(0.15, 0.5, 0.35);
            Body linkBody_2_cone = Body.CreateSolidCone(new Matrix4(new Vector3(0.15, 0.5, 0.45)), 0.03, 0.1);

            MechanismBuilder mb = new MechanismBuilder(MechanismType.Robot);
            mb.ModelName = "Mein Robbi";
            mb.Name = "Mein Roboter";

             mb.AddLink("Base", basePart);
             mb.AddLink("Link1", linkPart_1);
             mb.AddLink("Link2", linkPart_2);
             mb.BaseLink = "Base";

            //Gelenke einfügen
            mb.AddJoint("Joint", "Base", "Link1", new Vector3(0, 0, 0), new Vector3(0, 1, 0), JointType.Prismatic, true);
            mb.AddJoint("Joint2", "Link1", "Link2", new Vector3(0.15, 0.5, 0.35), new Vector3(0.15, 0.6, 0.35), JointType.Rotational, true);
            mb.SetJointLimit("Joint1", -0.13, 0.2);
            mb.SetJointLimit("Joint2", -Math.PI, Math.PI);
            mb.BaseFrame = Matrix4.Identity;

            double[] homeJointPos = { 0, 0 };
            Matrix4[] calPos = { Matrix4.Identity };

            int[] jointMask = { 1, 1, 0, 0, 0, 0 };

            Mechanism mech = mb.CompileMechanism();

            GraphicComponentLibrary gcl = mech.MoveDefinitionToLibrary();

            string userProjPath = (string)Options.GetValue("RobotStudio", "Directories.UserProjects");

            if (userProjPath != null)
                gcl.SaveAs(userProjPath + "\\Libaries\\myRobot_TEST.rslib");
                // gcl.SaveAs(userProjPath(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "myRobot_TEST.rslib"));


  • DenisFR
    DenisFR FRANCE ✭✭✭
    Test removing end ().
    <div>Part basePart = new Part;</div>

  • Sebastian_Hu
    Sebastian_Hu Germany

    Hi Denis, many thanks for your response.

    For a "new" Expression, alwalys (), [], or {} is requiered, isn´t it ? . I tried to leave it away but then i get the Compiler Error : CS1526.

    Maybe you or someone else has another idea?

    However, THANK YOU for the quick response :)

  • DenisFR
    DenisFR FRANCE ✭✭✭
    You're right.
    Look at this code how I manage it:
    I forgot following lines...
  • Sebastian_Hu
    Sebastian_Hu Germany
    Hi Denis, wow ! thank you for your Code !
    i tried it the way you did, and many different ways i can find on the Documentation for Development Center,... but it still doesn´t want to work :( , still null and still jumps into the catch. Picture shows the last try on making a new Part:

    While you kindly tried to find a solution to my Problem, I tried a bit further and tried to implement a CAD-file to Robot Studio. There the same Error :" .NET exception:NullReferenceExeption" appeared. Although I did not create a new part, I am confused. So I searched for similarities in both Codes. Maybe i was looking on the wrong place? and the Problem appears much earlier? The Problem in both is that Line 37 the Station is Null. So I Added the "private static Station NewStation()" to create a new Station - this works pretty well and the If-Clause (Line 38 to 41) doesn´t "activate" any more…. 

    But then, in Line 46 it runs in the Catch again … :( 
     Could it be a more fundamental problem ? 

    I am incredibly grateful for your help and hope you have some patience with me,.... 

  • DenisFR
    DenisFR FRANCE ✭✭✭
    Did you test to change line 37 with:
    Station station = Station.ActiveStation;

  • Sebastian_Hu
    Sebastian_Hu Germany
    Unfortunately that does not change anything…
    If I let him through until the "catch" comes - this error appears,... but he should not even get into the catch, shouldn´t he ?

  • DenisFR
    DenisFR FRANCE ✭✭✭
    Here, it's Part.Load who trig error.
    Can you open the file directly with RS?
  • Sebastian_Hu
    Sebastian_Hu Germany

    Hi, sorry for late answer. I´ve got some internal appointments.

    Yes, i am able to upload the file directly in Rs,... and that´s why my guess was that it´s a more fundamental problem,... everthing I try in RS to create or reload does not work, with the exception of the logger for displaying text messages.... Do you think it could have something tio do with the NET Framework?

    Thanks for your Time and Help !

  • DenisFR
    DenisFR FRANCE ✭✭✭
    I cannot reproduce your issue.
    Maybe you can send me your project, so I can test it.
  • Sebastian_Hu
    Sebastian_Hu Germany

    Hey,... I have no idea what the problem was,... but I deinstalled everything (RS,SDK,Net...) and reinstalled it,.. and know it works perfekt ! :)

    I am so happy about that,... thank you, for your help !!!!!!!!!! know I am going to try to create a Controller for the selfmade Roboter, an let it move around.

    Do you already created a Controller and linked it with a Roboter via SDK ?


Sign In or Register to comment.