API: Delete RsToolData

Hi!

I want to delete a RsToolData from my Task:

if (mechRobot.Task.DataDeclarations.Contains(myTool.Name))
mechRobot.Task.DataDeclarations..Remove(myTool);

This is the error I get:

System.ArgumentException: Object must have same parent.

in
ABB.Robotics.RobotStudio.Stations.RsDataDeclarationCollection.Remove(RsDataDeclaration dataDeclaration)

in RSAddinTest.Class1.loadScene(Object sender, ExecuteCommandEventArgs e)

Can anyone please tell me why this does not work?

Best Regards, Matthias

Hi

This may give you some help how to delete RsToolData

public void Macro_DelTool()

{

Station stn = Project.ActiveProject as Station;

if (stn == null) return;

if (stn.ActiveTask.DataDeclarations.Contains(“myNewTool”))

{

RsDataDeclaration tool = stn.ActiveTask.DataDeclarations[“myNewTool”];

stn.ActiveTask.DataDeclarations.Remove(tool);

}

}

And the reason is that you have RsToolData in the remove method and not a RsDataDeclaration