RobotStudio event

creating target in RS

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

  • 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 ✭✭✭
    Hello,
    You can stop your debugger just before the line and look if your station is well initialized and your P5.
  • Thanks for the information!

    I am not able to access the active station from robot studio (using Robot Studio 2023).

    when i run and execute the code Active station is null.

    but i have the active station in Rbot studio running.

    so, could someone suggest the reason for this error in the code!

    Thanks!

  • Do you have a virtual controller running in your station?
  • sugumar_venkatesan
    edited June 10
    I have tried with both virtual controller running and stopped, but the result is the same for both the caes(Active station = null).