# How to Attach a Linesensor and a Wobj to a Mechanism

**URL:** <https://tech-community.robotics.abb.com/t/how-to-attach-a-linesensor-and-a-wobj-to-a-mechanism/11137>\
**Category:** Developer Tools\
**Tags:** attacher\
**Created:** [May 31, 2023, 4:16pm UTC](https://tech-community.robotics.abb.com/t/how-to-attach-a-linesensor-and-a-wobj-to-a-mechanism/11137 "2023-05-31T16:16:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henry123](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@Henry123](https://tech-community.robotics.abb.com/u/Henry123)\
**Post date:** [May 31, 2023, 4:16pm UTC](https://tech-community.robotics.abb.com/t/how-to-attach-a-linesensor-and-a-wobj-to-a-mechanism/11137/1 "2023-05-31T16:16:27Z")

</div>

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:

public override void OnLoad(SmartComponent component)  
{  
base.OnLoad(component);  
Station stn = Project.ActiveProject as Station;  
if (stn != null)  
{  
IEnumerable 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:

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);  
}  
}  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Henry123](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@Henry123](https://tech-community.robotics.abb.com/u/Henry123)\
**Post date:** [June 1, 2023, 1:28pm UTC](https://tech-community.robotics.abb.com/t/how-to-attach-a-linesensor-and-a-wobj-to-a-mechanism/11137/2 "2023-06-01T13:28:25Z")

</div>

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.
