You can use conn. AllRefs; to find the connector to connect.
[TransactionAttribute (Autodesk. Revit. Attributes. TransactionMode. Manual)]
CmdConnected: IExternalCommand
{
Result Execute (ExternalCommandData commandData, messages, ElementSet elements)
{
UIApplication app = commandData. Application;
Document doc = app. ActiveUIDocument. Document;
Selection sel = app. ActiveUIDocument. Selection;
Transaction ts = Transaction (doc ,);
Ts. Start ();
Reference refDuct = sel. PickObject (ObjectType. Element ,);
Duct duct = doc. GetElement (refDuct) Duct;
ConnectorSetIterator csi = duct. ConnectorManager. Connectors. ForwardIterator ();
(Csi. MoveNext ())
{
Connector conn = csi. Current Connector;
(Conn. IsConnected = ){
ConnectorSet connectorSet = conn. AllRefs; ConnectorSetIterator csiChild = connectorSet. ForwardIterator ();
(CsiChild. MoveNext ())
{
Connector connected = csiChild. Current Connector;
(! = Connected & connected. Owner. UniqueId! = Conn. Owner. UniqueId)
{
(Connected. ConnectorType = ConnectorType. End |
Connected. ConnectorType = ConnectorType. Curve |
Connected. ConnectorType = ConnectorType. Physical)
{
(Connected. Owner FamilyInstance)
{
TaskDialog. Show (, connected. Owner. Name );
}
}
}
}
}
}
Ts. Commit ();
Result. Succeeded;
}
} Url: http://greatverve.cnblogs.com/p/revit-mep-api-AllRefs.html