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