How to Attach a Linesensor and a Wobj to a Mechanism
Henry123
✭
Hi,
I'm trying to attach a wobj and a Linesensor to a Mechanism. Unfortunatly it does not work. Since there is just happing nothing, I don't know where the problem is. Any ideas?
Wobj:
I'm trying to attach a wobj and a Linesensor to a Mechanism. Unfortunatly it does not work. Since there is just happing nothing, I don't know where the problem is. Any ideas?
Wobj:
public override void OnLoad(SmartComponent component)
{
base.OnLoad(component);
Station stn = Project.ActiveProject as Station;
if (stn != null)
{
IEnumerable<ProjectObject> stationobjects = stn.GetAllObjects();
foreach (ProjectObject po in stationobjects)
{
if (po.Name.Contains("wobj_1"))
{
Logger.AddMessage(new LogMessage("Wobj_1 found: " + po.TypeDisplayName));
IAttachableChild wobj = po as IAttachableChild;
for (int i = 0; i < component.GraphicComponents.Count; i++)
{
Mechanism mech = component.GraphicComponents[i] as Mechanism;
if (mech != null)
{
if (mech.Name == "XYZ")
{
Flange[] flange = mech.GetFlanges();
foreach (Flange fl in flange)
{
if (fl.Name == "XYZ_2") fl.Attach(wobj, false);
}
}
}
}
}
}
}
}
LineSensor:
LineSensor:
public override void OnLoad(SmartComponent component)
{
base.OnLoad(component);
foreach (GraphicComponent gc in component.GetGraphicComponents())
{
if (gc.Name.Contains("LineSensor"))
{
Logger.AddMessage(new LogMessage("LineSensor found: " + gc.TypeDisplayName));
IAttachableChild ls = gc as IAttachableChild;
for (int i = 0; i < component.GraphicComponents.Count; i++)
{
Mechanism mech = component.GraphicComponents[i] as Mechanism;
if (mech != null)
{
if (mech.Name == "XYZ")
{
Flange[] flange = mech.GetFlanges();
foreach (Flange fl in flange)
{
if (fl.Name == "XYZ_2") fl.Attach(ls, false);
}
}
}
}
}
}
}
Tagged:
0
Answers
-
I have found the reason why it does not work: The item where the Linesensor and the Wobj shall be attached to is a Library. Its necessary to disconnect it from the library first.
Strange, because I haven't found any suggestion in the API documentation. Just trial and error.
mech.DisconnectFromLibrary()
@ABB: It would be fine to get some kind of message in the Logger if the child can't be attached due to the fact, that the parent is a Library.0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 798 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings