private Duct createVAVConnection(Objects.Edge edge, ElementId ductType, ElementId system, IList <Objects.Node> nodes, IList <MEPCurve> curves, IList <FamilyInstance> vavs, IList <FamilyInstance> fittings) { Objects.Node n1 = nodes.Single(n => n.Id == edge.Node1); Objects.Node n2 = nodes.Single(n => n.Id == edge.Node2); Objects.Node vavNode = n1; if (n1.NodeType != Objects.Node.NodeTypeEnum.Vav) { vavNode = n2; } Objects.Node corrNode = n1; if (n1.NodeType != Objects.Node.NodeTypeEnum.Other) { corrNode = n2; } // find the nearest VAV to vavNode; // determine if we need to shift the connector on the corridor var fi = isFittingAtPoint(corrNode.Location, fittings, 0.1); MEPCurve toConnect = null; if (fi != null) { MEPController.MoveFittingAway(fi, edge.Diameter, out toConnect); } Duct d = MEPController.MakeDuct(_uiDoc.Document, vavNode.Location, corrNode.Location, ductType, system, edge.Diameter, 0.0); Connector tap = MEPController.GetNearestConnector(d, corrNode.Location); if (toConnect == null) { toConnect = findNearestCurve(corrNode.Location, curves, 0.05); } FamilyInstance fi2 = MEPController.MakeTakeOff(tap, toConnect); if (fi2 != null) { fittings.Add(fi2); } // connect to the Vav try { FamilyInstance fiVav = findNearest(vavs, vavNode.Location); Connector vavConn = MEPController.GetProperConnector(fiVav, FlowDirectionType.In, DuctSystemType.SupplyAir); Connector vavEnd = MEPController.GetNearestConnector(d, vavNode.Location); MEPController.Connect(vavConn, vavEnd); } catch { } return(d); }
public void DrawSolution(Objects.Solution sol, IList <Objects.Node> nodes, ElementId system, ElementId ductType) { Transaction t = null; if (_uiDoc.Document.IsModifiable == false) { t = new Transaction(_uiDoc.Document, "Create Ductwork"); t.Start(); } Utilities.AVFUtility.Clear(_uiDoc); // start with the corridor IList <Objects.Edge> corrEdges = sol.GetCorridorEdges(nodes); List <Duct> corrDucts = new List <Duct>(); List <Duct> allDucts = new List <Duct>(); SubTransaction st = new SubTransaction(_uiDoc.Document); st.Start(); foreach (var edge in corrEdges) { Objects.Node n1 = nodes.Single(n => n.Id == edge.Node1); Objects.Node n2 = nodes.Single(n => n.Id == edge.Node2); Duct d = MEPController.MakeDuct(_uiDoc.Document, n1.Location, n2.Location, ductType, system, edge.Diameter, 0.0); corrDucts.Add(d); allDucts.Add(d); } st.Commit(); _uiDoc.Document.Regenerate(); IList <FamilyInstance> fittings = MEPController.JoinDucts(corrDucts); IList <Objects.Edge> vavEdges = sol.GetVAVEdges(nodes); IList <MEPCurve> crvDucts = corrDucts.Cast <MEPCurve>().ToList(); var vavInstances = GetAllVAVs(); foreach (var edge in vavEdges) { //Objects.Node n1 = nodes.Single(n => n.Id == edge.Node1); //Objects.Node n2 = nodes.Single(n => n.Id == edge.Node2); //MEPController.MakeDuct(_uiDoc.Document, n1.Location, n2.Location, ductType, system, edge.Diameter, 0.0); Duct d = createVAVConnection(edge, ductType, system, nodes, crvDucts, vavInstances, fittings); } IList <Objects.Edge> shaftEdges = sol.GetShaftEdges(nodes); foreach (var edge in shaftEdges) { Objects.Node n1 = nodes.Single(n => n.Id == edge.Node1); Objects.Node n2 = nodes.Single(n => n.Id == edge.Node2); MEPController.MakeDuct(_uiDoc.Document, n1.Location, n2.Location, ductType, system, edge.Diameter, 0.0); } if (t != null) { t.Commit(); } }