private int ConnectionCheck(Connector con) { int tempInt = 0; ConnectorSet secondary = con.AllRefs; ConnectorSet TempConnectors = null; foreach (Connector f in secondary) { Element tempElem = this._doc.GetElement(f.Owner.Id); Category cat = tempElem.Category; BuiltInCategory enumCat = (BuiltInCategory)cat.Id.IntegerValue; if (enumCat.ToString() == "OST_FabricationDuctwork") { TempConnectors = this.getConnectorSetFromElement(tempElem); } } if (TempConnectors != null) { foreach (Connector connec in TempConnectors) { if (MainForm.CloseEnoughForMe(connec.Origin.X, con.Origin.X) && MainForm.CloseEnoughForMe(connec.Origin.Y, con.Origin.Y) && MainForm.CloseEnoughForMe(connec.Origin.Z, con.Origin.Z)) { tempInt = 1; } } } return(tempInt); }
//Check if the current element is a Tee public static bool TeeDetect(ConnectorSet Connectors) { bool result; int tempInt = 0; foreach (Connector con in Connectors) { if (con.ConnectorType.ToString() != "Curve") { tempInt += 1; } } if (tempInt == 3) { result = true; } else { result = false; } return(result); }
public static List <Connector> ReferenceConnectors(this Connector connector, ConnectorType connectorType = ConnectorType.End) { if (connector == null || !connector.IsConnected || connector.Owner == null) { return(null); } ConnectorSet connectorSet = connector.AllRefs; if (connectorSet == null || connectorSet.Size == 0) { return(null); } List <Connector> result = new List <Connector>(); foreach (Connector connector_Ref in connectorSet) { if (connector_Ref.ConnectorType == connectorType) { if (connector_Ref.Owner == null || connector.Owner.Id != connector_Ref.Owner.Id) { result.Add(connector_Ref); } } } return(result); }
/// <summary> /// Exports a connector instance. Almost verbatim exmaple from Revit 2012 API for Connector Class /// Works only for HVAC and Piping for now /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="connectors">The ConnectorSet object.</param> private static void Export(ExporterIFC exporterIFC, ConnectorSet connectors) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { ISet <Connector> stableSortedConnectors = new SortedSet <Connector>(new ConnectorComparer()); foreach (Connector connector in connectors) { if (connector != null) { stableSortedConnectors.Add(connector); } } foreach (Connector connector in stableSortedConnectors) { try { ProcessConnections(exporterIFC, connector, null); } catch (Exception) { // Log an error here } } tr.Commit(); } }
/// <summary> /// Return the first rectangular connector of the given duct element. /// </summary> static bool GetFirstRectangularConnector( Duct duct, out Connector c1) { c1 = null; ConnectorSet connectors = duct.ConnectorManager.Connectors; if (0 < connectors.Size) { foreach (Connector c in connectors) { if (ConnectorProfileType.Rectangular == c.Shape) { c1 = c; break; } else { Trace.WriteLine("Connector shape: " + c.Shape); } } } return(null != c1); }
public NonBreakInElement(Document doc, IGrouping<int, Element> group) { //Retreive and store the pipe the said elements are connected to: ElementId headPipeId = new ElementId(group.Key); Element refElement = doc.GetElement(headPipeId); HeadPipe = refElement as Pipe; //Populate a list with all connector locations and sort from one end to other Cons pipeCons = mu.GetConnectors(refElement); XYZ referencePoint = pipeCons.Primary.Origin; AllCreationPoints.Add(referencePoint); AllCreationPoints.Add(pipeCons.Secondary.Origin); foreach (Element element in group) { Cons cons = mu.GetConnectors(element); ConnectorSet conSet = cons.Primary.AllRefs; foreach (Connector connector in conSet) { if (connector.ConnectorType == ConnectorType.Curve) { if (connector.Domain == Domain.DomainPiping) { AllCreationPoints.Add(connector.Origin); break; } } } } //var allCons = mu.GetALLConnectorsFromElements(refElement); //var curvePts = allCons.Where(x => x.OfConType(ConnectorType.Curve)).Select(x => x.Origin).ToList(); //AllCreationPoints.AddRange(curvePts); AllCreationPoints = AllCreationPoints.OrderBy(x => x.DistanceTo(referencePoint)).ToList(); }
public static ConnectorSet GetConnectorSet(Element e) { ConnectorSet connectors = null; if (e is FamilyInstance) { MEPModel m = ((FamilyInstance)e).MEPModel; if (null != m && null != m.ConnectorManager) { connectors = m.ConnectorManager.Connectors; } } else if (e is Wire) { connectors = ((Wire)e).ConnectorManager.Connectors; } else { Debug.Assert(e.GetType().IsSubclassOf(typeof(MEPCurve)), "expected all candidate connector provider " + "elements to be either family instances or " + "derived from MEPCurve"); if (e is MEPCurve) { connectors = ((MEPCurve)e).ConnectorManager.Connectors; } } return(connectors); }
/// <summary> /// 获得一个元素所有的Connector /// </summary> /// <param name="ele"></param> /// <returns></returns> public static ConnectorSet GetAllConnectors(Element ele) { ConnectorSet connectors = null; FamilyInstance familyInstance = ele as FamilyInstance; if (familyInstance != null) { MEPModel mEPModel = familyInstance.MEPModel; try { connectors = mEPModel.ConnectorManager.Connectors; } catch (Exception) { TaskDialog.Show("Error", ele.Id + " :没有找到连接点"); connectors = null; } } else { MEPCurve mepCurve = ele as MEPCurve; if (mepCurve != null) { connectors = mepCurve.ConnectorManager.Connectors; } } return(connectors); }
private bool VerifyUnusedConnectors(FamilyInstance fi) { bool hasUnusedElectricalConnector = false; try { MEPModel mepModel = fi.MEPModel; if (null == mepModel) { return(hasUnusedElectricalConnector); } ConnectorManager cm = mepModel.ConnectorManager; ConnectorSet unusedConnectors = cm.UnusedConnectors; if (null == unusedConnectors || unusedConnectors.IsEmpty) { return(hasUnusedElectricalConnector); } foreach (Connector connector in unusedConnectors) { if (connector.Domain == Domain.DomainElectrical) { hasUnusedElectricalConnector = true; break; } } } catch (Exception) { return(hasUnusedElectricalConnector); } return(hasUnusedElectricalConnector); }
public static Connector Connector(this ConnectorManager connectorManager, XYZ xYZ, ConnectorType connectorType = ConnectorType.End, double tolerance = Core.Tolerance.MacroDistance) { if (connectorManager == null || xYZ == null) { return(null); } ConnectorSet connectorSet = connectorManager.Connectors; if (connectorSet == null) { return(null); } double tolerance_Temp = tolerance; #if Revit2017 || Revit2018 || Revit2019 || Revit2020 tolerance_Temp = UnitUtils.ConvertToInternalUnits(tolerance_Temp, DisplayUnitType.DUT_METERS); #else tolerance_Temp = UnitUtils.ConvertToInternalUnits(tolerance_Temp, UnitTypeId.Meters); #endif foreach (Connector connector in connectorSet) { if (connector.ConnectorType == connectorType && connector.Origin.DistanceTo(xYZ) <= tolerance_Temp) { return(connector); } } return(null); }
/// <summary> /// Gets the element's the latest connector. /// </summary> /// <param name="connectors"></param> /// <param name="point"></param> /// <returns></returns> public static Connector GetLatestConnector(ConnectorSet connectors, XYZ point) { Connector result = null; var minDist = 1.0; foreach (Connector connector in connectors) { var curDist = connector.Origin.DistanceTo(point); if (!(curDist < minDist)) { continue; } result = connector; minDist = curDist; } if (result == null) { throw new ArgumentException(nameof(result)); } return(result); }
List <Element> GetConnectElements(Element ele) { List <Element> list = new List <Element>(); try { ConnectorSet connectorSet = MtCommon.GetAllConnectors(ele); if (connectorSet != null && connectorSet.Size != 0) { foreach (Connector item in connectorSet) { if (item.Domain != Domain.DomainElectrical) { Connector connector = MtCommon.GetConnectedConnector(item); if (connector != null) { Element element = connector.Owner; list.Add(element); } } } } else { //模型自身没有连接点 AddListViewErrorData(ele, "模型自身没有连接点"); } } catch (Exception e) { throw new Exception(e.Message); } return(list); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Fetch the Document UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; //required arrays BuiltInCategory biDucts = BuiltInCategory.OST_DuctCurves; ElementId idDucts = doc.Settings.Categories.get_Item(biDucts).Id; ICollection <ElementId> selectedIds = uiDoc.Selection.GetElementIds(); List <Element> eles = new List <Element>(); List <Connector> cons = new List <Connector>(); //check for element number if (selectedIds.Count > 2) { TaskDialog.Show("Wrong input", "You selected more then 2 elements"); return(Result.Succeeded); } //chekc element Category and if its ok foreach (var eleId in selectedIds) { Element ele = doc.GetElement(eleId); if (ele.Category.Id.Equals(idDucts)) { eles.Add(ele); } else { TaskDialog.Show("Wrong input", "Wrong elements category"); return(Result.Succeeded); } } Duct du1 = eles[0] as Duct; Duct du2 = eles[1] as Duct; ConnectorSet cc1 = du1.ConnectorManager.UnusedConnectors; ConnectorSet cc2 = du2.ConnectorManager.UnusedConnectors; foreach (Connector c in cc1) { cons.Add(c); } foreach (Connector c in cc2) { cons.Add(c); } //transaction for creating the transition using (Transaction trans = new Transaction(doc, "Trans1")) { trans.Start(); doc.Create.NewTransitionFitting(cons[0], cons[1]); trans.Commit(); } return(Result.Succeeded); }
private bool HasElectricalConnector(Element e) { if (!(e is FamilyInstance)) { return(false); } FamilyInstance fa = e as FamilyInstance; if (fa.MEPModel.ConnectorManager == null) { return(false); } ConnectorSet cs = fa.MEPModel.ConnectorManager.Connectors; foreach (Connector c in cs) { try { if ((int)c.ElectricalSystemType >= 0) { return(true); } } catch { continue; } } return(false); }
private ConnectorSet getConnectorSetFromElement(Element elem) { ConnectorSet connectors = null; bool flag = elem is FamilyInstance; if (flag) { MEPModel i = ((FamilyInstance)elem).MEPModel; connectors = i.ConnectorManager.Connectors; } else { bool flag2 = elem is FabricationPart; if (flag2) { connectors = ((FabricationPart)elem).ConnectorManager.Connectors; } else { bool flag3 = elem is MEPCurve; if (flag3) { connectors = ((MEPCurve)elem).ConnectorManager.Connectors; } else { Debug.Assert(elem.GetType().IsSubclassOf(typeof(MEPCurve)), "expected all candidate connector provider elements to be either family instances or derived from MEPCurve"); } } } return(connectors); }
// for https://forums.autodesk.com/t5/revit-api-forum/how-to-calculate-the-center-point-of-elbow/m-p/9803893 /// <summary> /// Return elbow connectors. /// Return null if the given element is not a /// family instance with exactly two connectors. /// </summary> List <Connector> GetElbowConnectors(Element e) { List <Connector> cons = null; FamilyInstance fi = e as FamilyInstance; if (null != fi) { MEPModel m = fi.MEPModel; if (null != m) { ConnectorManager cm = m.ConnectorManager; if (null != cm) { ConnectorSet cs = cm.Connectors; if (2 == cs.Size) { cons = new List <Connector>(2); bool first = true; foreach (Connector c in cs) { if (first) { cons[0] = c; } else { cons[1] = c; } } } } } } return(cons); }
private int ConnectionCheck(Connector con) { int tempInt = 0; ConnectorSet secondary = con.AllRefs; ConnectorSet TempConnectors = null; foreach (Connector f in secondary) { Element tempElem = this._doc.GetElement(f.Owner.Id); TempConnectors = this.getConnectorSetFromElement(tempElem); } bool flag = TempConnectors != null; if (flag) { foreach (Connector connec in TempConnectors) { bool flag2 = MainForm.CloseEnoughForMe(connec.Origin.X, con.Origin.X); if (flag2) { bool flag3 = MainForm.CloseEnoughForMe(connec.Origin.Y, con.Origin.Y); if (flag3) { bool flag4 = MainForm.CloseEnoughForMe(connec.Origin.Z, con.Origin.Z); if (flag4) { tempInt = 1; } } } } } return(tempInt); }
/// <summary> /// 遍历读取connectorSet中所有conn,包括conn.AllRef /// </summary> /// <param name="connectorSet"></param> private static void WriteConnectorSet2(ConnectorSet connectorSet) { SortedDictionary <string, List <Connector> > connectors = new SortedDictionary <string, List <Connector> >(); foreach (Connector conn in connectorSet) { string connId = GetConnectorId(conn); if (conn.ConnectorType == ConnectorType.Logical) { foreach (Connector logLinkConn in conn.AllRefs) { connId += GetConnectorId(logLinkConn); } } if (!connectors.ContainsKey(connId)) { connectors.Add(connId, new List <Connector>()); } connectors[connId].Add(conn); } foreach (string key in connectors.Keys) { foreach (Connector conn in connectors[key]) { WriteConnector(conn); Trace.WriteLine("+AllRefs"); Trace.Indent(); WriteConnectorSet(conn.AllRefs); Trace.Unindent(); Trace.WriteLine(""); } } }
/// <summary> /// 获得与该Connector连接的Connectors /// </summary> /// <param name="connector"></param> /// <returns></returns> public static Connector GetConnectedConnector(Connector connector) { Connector connectedConnector = null; try { ConnectorSet allRefs = connector.AllRefs; if (allRefs == null || allRefs.Size == 0) { return(null); } //TaskDialog.Show("Error", "No AllRefs is " + connector.Owner.Id); foreach (Connector conn in allRefs) { if (conn.ConnectorType != ConnectorType.End || conn.Owner.Id.IntegerValue.Equals(connector.Owner.Id.IntegerValue)) { continue; } connectedConnector = conn; break; } } catch (Exception) { TaskDialog.Show("Error", connector.Owner.Id.ToString()); throw; } return(connectedConnector); }
/// <summary> /// Set the correct PipingSystemType for the placed support family. /// </summary> /// <param name="commandData">The usual ExternalCommandData.</param> /// <param name="pipe">The pipe on which the support was placed.</param> /// <param name="support">The support that was placed.</param> private static (Pipe dummyPipe, Connector supportConnector) SetSystemType(ExternalCommandData commandData, Pipe pipe, Element support) { var app = commandData.Application; var uiDoc = app.ActiveUIDocument; var doc = uiDoc.Document; //Get the pipe type from pipe ElementId pipeTypeId = pipe.PipeType.Id; //Get system type from pipe ConnectorSet pipeConnectors = pipe.ConnectorManager.Connectors; Connector pipeConnector = (from Connector c in pipeConnectors where (int)c.ConnectorType == 1 select c).FirstOrDefault(); ElementId pipeSystemType = pipeConnector.MEPSystem.GetTypeId(); //Get the connector from the support Connector connectorToConnect = (from Connector c in ((FamilyInstance)support).MEPModel.ConnectorManager.Connectors select c).FirstOrDefault(); //Create a point in space to connect the pipe XYZ direction = connectorToConnect.CoordinateSystem.BasisZ.Multiply(2); XYZ origin = connectorToConnect.Origin; XYZ pointInSpace = origin.Add(direction); //Create the pipe Pipe dummyPipe = Pipe.Create(doc, pipeTypeId, pipe.ReferenceLevel.Id, connectorToConnect, pointInSpace); //Change the pipe system type to match the picked pipe (it is not always matching) dummyPipe.SetSystemType(pipeSystemType); return(dummyPipe, connectorToConnect); }
// for https://forums.autodesk.com/t5/revit-api-forum/how-to-calculate-the-center-point-of-elbow/m-p/9803893 /// <summary> /// Return elbow connector transforms. /// Return null if the given element is not a /// family instance with exactly two connectors. /// </summary> List <Transform> GetElbowConnectorTransforms(Element e) { List <Transform> xs = null; FamilyInstance fi = e as FamilyInstance; if (null != fi) { MEPModel m = fi.MEPModel; if (null != m) { ConnectorManager cm = m.ConnectorManager; if (null != cm) { ConnectorSet cs = cm.Connectors; if (2 == cs.Size) { xs = new List <Transform>(2); bool first = true; foreach (Connector c in cs) { if (first) { xs[0] = c.CoordinateSystem; } else { xs[1] = c.CoordinateSystem; } } } } } } return(xs); }
private int ConnectionCheck(Connector con) { List <string> categorias = new List <string>(new string[] { "OST_CableTrayFitting", "OST_CableTray", "OST_ConduitFitting", "OST_Conduit", "OST_DuctFitting", "OST_DuctCurves", "OST_DuctAccessory", "OST_FabricationParts", "OST_FabricationPipework", "OST_FabricationHangers", "OST_PipeAccessory", "OST_PipeFitting", "OST_PipeCurves", "OST_FabricationDuctwork" }); int tempInt = 0; ConnectorSet secondary = con.AllRefs; ConnectorSet TempConnectors = null; foreach (Connector f in secondary) { Element tempElem = _doc.GetElement(f.Owner.Id); Category cat = tempElem.Category; BuiltInCategory enumCat = (BuiltInCategory)cat.Id.IntegerValue; if (categorias.Contains(enumCat.ToString())) { TempConnectors = getConnectorSetFromElement(tempElem); foreach (Connector connec in TempConnectors) { if (MainForm.CloseEnoughForMe(connec.Origin.X, con.Origin.X) && MainForm.CloseEnoughForMe(connec.Origin.Y, con.Origin.Y) && MainForm.CloseEnoughForMe(connec.Origin.Z, con.Origin.Z)) { tempInt = 1; } } } } if (TempConnectors != null) { } return(tempInt); }
public static List <ElementId> GetPipelineElementID(Document document, IList <ElementId> elementIds, ElementId origin_elementid) { List <ElementId> lstPipelineids = new List <ElementId>(); lstPipelineids.Add(origin_elementid); while (elementIds.Count > 0) { ElementId rootId = lstPipelineids[lstPipelineids.Count - 1]; //take the last one of pipeline ConnectorSet connectorSet = UIOperation.GetConnectorSet(document, rootId); //get all the connectors of the rootid List <ElementId> lstOtherConnectElementIds = new List <ElementId>(); foreach (Connector c in connectorSet) { ElementId id = UIOperation.GetAnotherIDAtConnector(rootId, c); if (elementIds.Contains(id)) { lstOtherConnectElementIds.Add(id); lstPipelineids.Add(id); elementIds.Remove(id); break; } } if (lstOtherConnectElementIds.Count == 0) { break; } } return(lstPipelineids); }
/// <summary> /// Adds the Ifc handle to the dictionary and connectors. /// </summary> /// <param name="element"> /// The element. /// </param> /// <param name="handle"> /// The Ifc handle. /// </param> public void Register(Element element, IFCAnyHandle handle) { // Keep the "real" MEP objects in Cache for port connection later on (e.g. exclude IfcBuildingElementProxy) // This only affects IFC4 and our use of IfcRelConnectsPortToElement, which is only for IfcDistributionElement. // TODO: Change IfcRelConnectsPortToElement to IfcRelNests for IFC4 only, and remove this check. if (!ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4 && !(IFCAnyHandleUtil.IsSubTypeOf(handle, IFCEntityType.IfcDistributionElement))) { return; } if (m_MEPElementHandleDictionary.ContainsKey(element.Id)) { return; } m_MEPElementHandleDictionary[element.Id] = handle; ConnectorSet connectorts = GetConnectors(element); if (connectorts != null) { MEPConnectors.Add(connectorts); } }
/// <summary> /// Gets a set of all connectors hosted by a single element. /// From http://thebuildingcoder.typepad.com/blog/2010/06/retrieve-mep-elements-and-connectors.html. /// </summary> /// <param name="e">The element that may host connectors</param> /// <returns>A set of connectors</returns> static ConnectorSet GetConnectors(Element e) { ConnectorSet connectors = null; try { if (e is FamilyInstance) { MEPModel m = ((FamilyInstance)e).MEPModel; if (m != null && m.ConnectorManager != null) { connectors = m.ConnectorManager.Connectors; } } else if (e is Wire) { connectors = ((Wire)e).ConnectorManager.Connectors; } else if (e is MEPCurve) { connectors = ((MEPCurve)e).ConnectorManager.Connectors; } } catch { } return(connectors); }
public static ConnectorProfileType ConnectorProfileType(this MEPCurve mEPCurve) { if (mEPCurve == null) { return(Autodesk.Revit.DB.ConnectorProfileType.Invalid); } ConnectorSet connectorSet = mEPCurve?.ConnectorManager?.Connectors; if (connectorSet == null) { return(Autodesk.Revit.DB.ConnectorProfileType.Invalid); } foreach (Connector connector in connectorSet) { ConnectorProfileType result = connector.Shape; if (result != Autodesk.Revit.DB.ConnectorProfileType.Invalid) { return(result); } } return(Autodesk.Revit.DB.ConnectorProfileType.Invalid); }
public static Spatial.Plane Plane(this MEPCurve mEPCurve) { if (mEPCurve == null) { return(null); } ConnectorSet connectorSet = mEPCurve?.ConnectorManager?.Connectors; if (connectorSet == null) { return(null); } foreach (Connector connector in connectorSet) { Transform transform = connector.CoordinateSystem; if (transform == null) { continue; } return(new Spatial.Plane(transform.Origin.ToSAM(), transform.BasisX.ToSAM_Vector3D(true), transform.BasisY.ToSAM_Vector3D(true))); } return(null); }
// // Copied from Revit SDK TraverseSystem example // // (C) Copyright 2003-2010 by Autodesk, Inc. // /// <summary> /// Get the mechanical or piping system /// from the connectors of selected element. /// </summary> /// <param name="connectors">Connectors of selected element</param> /// <returns>The found mechanical or piping system</returns> static public MEPSystem ExtractSystemFromConnectors(ConnectorSet connectors) { MEPSystem system = null; if (connectors == null || connectors.Size == 0) { return(null); } // Get well-connected mechanical or // piping systems from each connector List <MEPSystem> systems = new List <MEPSystem>(); foreach (Connector connector in connectors) { MEPSystem tmpSystem = connector.MEPSystem; if (tmpSystem == null) { continue; } MechanicalSystem ms = tmpSystem as MechanicalSystem; if (ms != null) { if (ms.IsWellConnected) { systems.Add(tmpSystem); } } else { PipingSystem ps = tmpSystem as PipingSystem; if (ps != null && ps.IsWellConnected) { systems.Add(tmpSystem); } } } // If more than one system is found, // get the system contains the most elements int countOfSystem = systems.Count; if (countOfSystem != 0) { int countOfElements = 0; foreach (MEPSystem sys in systems) { if (sys.Elements.Size > countOfElements) { system = sys; countOfElements = sys.Elements.Size; } } } return(system); }
public StringBuilder Export(string pipeLineGroupingKey, HashSet <Element> elements, Document doc) { var pipeList = elements; var sbPipes = new StringBuilder(); var key = pipeLineGroupingKey; foreach (Element element in pipeList) { sbPipes.AppendLine(element.get_Parameter(new plst().PCF_ELEM_TYPE.Guid).AsString()); sbPipes.AppendLine(" COMPONENT-IDENTIFIER " + element.get_Parameter(new plst().PCF_ELEM_COMPID.Guid).AsInteger()); //Write Plant3DIso entries if turned on if (InputVars.ExportToPlant3DIso) { sbPipes.Append(Composer.Plant3DIsoWriter(element, doc)); } Pipe pipe = (Pipe)element; //Get connector set for the pipes ConnectorSet connectorSet = pipe.ConnectorManager.Connectors; //Filter out non-end types of connectors IList <Connector> connectorEnd = (from Connector connector in connectorSet where connector.ConnectorType.ToString().Equals("End") select connector).ToList(); sbPipes.Append(EndWriter.WriteEP1(element, connectorEnd.First())); sbPipes.Append(EndWriter.WriteEP2(element, connectorEnd.Last())); Composer elemParameterComposer = new Composer(); sbPipes.Append(elemParameterComposer.ElemParameterWriter(element)); #region CII export if (InputVars.ExportToCII) { sbPipes.Append(Composer.CIIWriter(doc, key)); } #endregion sbPipes.Append(" UNIQUE-COMPONENT-IDENTIFIER "); sbPipes.Append(element.UniqueId); sbPipes.AppendLine(); } return(sbPipes); //// Clear the output file //System.IO.File.WriteAllBytes(InputVars.OutputDirectoryFilePath + "Pipes.pcf", new byte[0]); //// Write to output file //using (StreamWriter w = File.AppendText(InputVars.OutputDirectoryFilePath + "Pipes.pcf")) //{ // w.Write(sbPipes); // w.Close(); //} }
public static Connector MatchConnector(XYZ pointToMatch, ConnectorSet conSet) { Connector connector = null; connector = (from Connector c in conSet where Util.IsEqual(pointToMatch, c.Origin) select c).FirstOrDefault(); return(connector); }
/// <summary> /// Get the mechanical or piping system from the connectors of selected element /// </summary> /// <param name="connectors">Connectors of selected element</param> /// <returns>The found mechanical or piping system</returns> private static MEPSystem ExtractSystemFromConnectors(ConnectorSet connectors) { MEPSystem system = null; if (connectors == null || connectors.Size == 0) { return null; } // Get well-connected mechanical or piping systems from each connector List<MEPSystem> systems = new List<MEPSystem>(); foreach (Connector connector in connectors) { MEPSystem tmpSystem = connector.MEPSystem; if (tmpSystem == null) { continue; } MechanicalSystem ms = tmpSystem as MechanicalSystem; if (ms != null) { if (ms.IsWellConnected) { systems.Add(tmpSystem); } } else { PipingSystem ps = tmpSystem as PipingSystem; if (ps != null && ps.IsWellConnected) { systems.Add(tmpSystem); } } } // If more than one system is found, get the system contains the most elements int countOfSystem = systems.Count; if (countOfSystem != 0) { int countOfElements = 0; foreach (MEPSystem sys in systems) { if (sys.Elements.Size > countOfElements) { system = sys; countOfElements = sys.Elements.Size; } } } return system; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; Transaction tx = new Transaction( doc, "New Duct System" ); tx.Start(); ConnectorSet connectorSet = new ConnectorSet(); Connector baseConnector = null; ConnectorSetIterator csi; // select a Parallel Fan Powered VAV // and some Supply Diffusers prior to running // this command //ElementSet selection = uidoc.Selection.Elements; // 2014 foreach( ElementId id in uidoc.Selection.GetElementIds() ) // 2015 { Element e = doc.GetElement( id ); if( e is FamilyInstance ) { FamilyInstance fi = e as FamilyInstance; Family family = fi.Symbol.Family; // assume the selected Mechanical Equipment // is the base equipment for new system: if( family.FamilyCategory.Name == "Mechanical Equipment" ) { // find the "Out" and "SupplyAir" connectors // on the base equipment if( null != fi.MEPModel ) { csi = fi.MEPModel.ConnectorManager .Connectors.ForwardIterator(); while( csi.MoveNext() ) { Connector conn = csi.Current as Connector; if( conn.Direction == FlowDirectionType.Out && conn.DuctSystemType == DuctSystemType.SupplyAir ) { baseConnector = conn; break; } } } } else if( family.FamilyCategory.Name == "Air Terminals" ) { // add selected Air Terminals to // connector set for new mechanical system csi = fi.MEPModel.ConnectorManager .Connectors.ForwardIterator(); csi.MoveNext(); connectorSet.Insert( csi.Current as Connector ); } } } // create a new SupplyAir mechanical system MechanicalSystem ductSystem = doc.Create.NewMechanicalSystem( baseConnector, connectorSet, DuctSystemType.SupplyAir ); tx.Commit(); return Result.Succeeded; }
/// <summary> /// Exports a connector instance. Almost verbatim exmaple from Revit 2012 API for Connector Class /// Works only for HVAC and Piping for now /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="connectors">The ConnectorSet object.</param> private static void Export(ExporterIFC exporterIFC, ConnectorSet connectors) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { foreach (Connector connector in connectors) { try { if (connector != null) { if (connector.Domain == Domain.DomainHvac || connector.Domain == Domain.DomainPiping) { if (connector.ConnectorType == ConnectorType.End || connector.ConnectorType == ConnectorType.Curve || connector.ConnectorType == ConnectorType.Physical) { if (connector.IsConnected) { ConnectorSet connectorSet = connector.AllRefs; ConnectorSetIterator csi = connectorSet.ForwardIterator(); while (csi.MoveNext()) { Connector connected = csi.Current as Connector; if (connected != null && connected.Owner != null && connector.Owner != null) { if (connected.Owner.Id != connector.Owner.Id) { // look for physical connections if (connected.ConnectorType == ConnectorType.End || connected.ConnectorType == ConnectorType.Curve || connected.ConnectorType == ConnectorType.Physical) { if (connector.Direction == FlowDirectionType.Out) { AddConnection(exporterIFC, connected, connector, false); } else { bool isBiDirectional = (connector.Direction == FlowDirectionType.Bidirectional); AddConnection(exporterIFC, connector, connected, isBiDirectional); } } } } } } } } } } catch (System.Exception) { // Log an error here } } tr.Commit(); } }
/// <summary> /// Exports a connector instance. Almost verbatim exmaple from Revit 2012 API for Connector Class /// Works only for HVAC and Piping for now /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="connectors">The ConnectorSet object.</param> private static void Export(ExporterIFC exporterIFC, ConnectorSet connectors) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { foreach (Connector connector in connectors) { try { if (connector != null) ProcessConnections(exporterIFC, connector, null); } catch (System.Exception) { // Log an error here } } tr.Commit(); } }