RobotStudio event

creating target in RS

Options
I am trying to create a tag in RS using C# i have used below code

Code:

Station station = Project.ActiveProject as Station;

// Add target.
station.ActiveTask.Targets.Add(P5);

Error:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

station was null.

Could someone support me to fix this?

Thanks!
Sugumar V

Answers

  • graemepaulin
    Options
    I am not a C# programmer - looking at what the error is you may not have a station open in RobotStudio?

    The other thing is you would get a RAPID error if you created a Robtarget just called P5 - it needs to have all the data a Robtarget requires eg position (x,y,z), orientation (Q1,Q2,Q3,Q4), etc
  • DenisFR
    DenisFR ✭✭✭
    Options
    Hello,
    You can stop your debugger just before the line and look if your station is well initialized and your P5.