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 : "http://developercenter.robotstudio.com/robotstudio/api_reference?url=html/4ffca351-267a-4b49-a512-81638c3b21bf.htm", I use Visual Studio an have the Robot Studio SDK installed.
If i use the first example "Creating a Robot Studio add-in" (http://developercenter.robotstudio.com/robotstudio/api_reference?url=html/4ffca351-267a-4b49-a512-81638c3b21bf.htm) 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.
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".
(http://developercenter.robotstudio.com/robotstudio/api_reference?url=html/4ffca351-267a-4b49-a512-81638c3b21bf.htm)
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,..
I Hope somebody has an idea or can Help me,.. I would be incredibly thankful !!!!!!
.rsaddin
Complete source:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ABB.Robotics;
using ABB.Robotics.RobotStudio.Controllers;
using ABB.Robotics.RobotStudio;
using ABB.Robotics.RobotStudio.Environment;
using ABB.Robotics.RobotStudio.Stations;
using ABB.Robotics.RobotStudio.Stations.Forms;
// C:\Program Files (x86)\Common Files\ABB Industrial IT\Robotics IT\RobotStudio\AddIns
{
public class Class1
{
public static void AddinMain()
{
Logger.AddMessage(new LogMessage("Dies ist ein Test-Addin für RobotStudio"));
BaueEinenRobbi();
}
private static void BaueEinenRobbi()
{
Project.UndoContext.BeginUndoStep("Create A Robot");
{
Station station_1 = Project.ActiveProject as Station;
Body baseBody = Body.CreateSolidBox(new Matrix4(new Vector3(0, 0, 0)), new Vector3(0.3, 0.3, 0.3));
basePart.Bodies.Add(baseBody);
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);
linkPart_1.Bodies.Add(linkBody_1);
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);
linkPart_2.Bodies.Add(linkBody_2_torus);
linkPart_2.Bodies.Add(linkBody_2_cone);
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.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.SetSyncJointPosition(homeJointPos);
mb.SetCalibrationPosition(calPos);
mb.SetJointMask(jointMask);
string userProjPath = (string)Options.GetValue("RobotStudio", "Directories.UserProjects");
if (userProjPath != null)
{
gcl.SaveAs(userProjPath + "\\Libaries\\myRobot_TEST.rslib");
}
else
{
// gcl.SaveAs(userProjPath(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "myRobot_TEST.rslib"));
}
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
Comments
-
Hello,Test removing end ().
<div>Part basePart = new Part;</div>
0 -
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
0 -
You're right.Look at this code how I manage it:I forgot following lines...
1 -
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,....
0 -
Did you test to change line 37 with:
Station station = Station.ActiveStation;
0 -
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 ?
0 -
Here, it's Part.Load who trig error.Can you open the file directly with RS?0
-
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 !
0 -
Sorry,I cannot reproduce your issue.Maybe you can send me your project, so I can test it.1
-
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 ?
THANKS
0
Categories
- All Categories
- 5.5K RobotStudio
- 392 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 307 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 3 RobotStudio AR Viewer
- 779 RAPID Programming
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings