public static BH.oM.MEP.System.SectionProperties.PipeSectionProperty PipeSectionProperty(this Autodesk.Revit.DB.Plumbing.Pipe pipe, RevitSettings settings = null) { settings = settings.DefaultIfNull(); IProfile profile = pipe.Profile(settings); double liningThickness = pipe.LookupParameterDouble(BuiltInParameter.RBS_REFERENCE_LINING_THICKNESS); // Extract the lining thk from Duct element if (liningThickness == double.NaN) { liningThickness = 0; } double insulationThickness = pipe.LookupParameterDouble(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS); // Extract the lining thk from Duct element if (insulationThickness == double.NaN) { insulationThickness = 0; } SectionProfile sectionProfile = BH.Engine.MEP.Create.SectionProfile((TubeProfile)profile, liningThickness, insulationThickness); PipeSectionProperty result = BH.Engine.MEP.Create.PipeSectionProperty(sectionProfile); return(result); }
public static BH.oM.MEP.System.Pipe Pipe(Line line, double flowRate = 0, PipeSectionProperty sectionProperty = null) { if (line == null) { BH.Engine.Reflection.Compute.RecordError("Cannot create a pipe from an empty line."); return(null); } return(new BH.oM.MEP.System.Pipe { StartPoint = line.Start, EndPoint = line.End, SectionProperty = sectionProperty, }); }
public static PipeSectionProperty PipeSectionProperty(SectionProfile sectionProfile, Material pipeMaterial = null, Material insulationMaterial = null, string name = "") { if (sectionProfile == null) { BH.Engine.Reflection.Compute.RecordError("Cannot create a pipe section property with a null section profile."); return(null); } double elementSolidArea = sectionProfile.ElementProfile.Area(); double elementVoidArea = sectionProfile.ElementProfile.VoidArea(); double liningSolidArea = 0; double liningVoidArea = double.NaN; double insulationSolidArea = 0; double insulationVoidArea = double.NaN; if (sectionProfile.LiningProfile != null) { liningSolidArea = sectionProfile.LiningProfile.Area(); liningVoidArea = sectionProfile.LiningProfile.VoidArea(); } if (sectionProfile.InsulationProfile != null) { insulationSolidArea = sectionProfile.InsulationProfile.Area(); insulationVoidArea = sectionProfile.InsulationProfile.VoidArea(); } PipeSectionProperty property = new PipeSectionProperty(sectionProfile, elementSolidArea, liningSolidArea, insulationSolidArea, elementVoidArea, liningVoidArea, insulationVoidArea); property.PipeMaterial = pipeMaterial; property.InsulationMaterial = insulationMaterial; property.Name = name; if (property == null) { BH.Engine.Reflection.Compute.RecordError("Insufficient information to create a PipeSectionProperty. Please ensure you have all required inputs."); } return(property); }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static Autodesk.Revit.DB.Plumbing.Pipe ToRevitPipe(this oM.MEP.System.Pipe pipe, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { if (document == null) { return(null); } // Check valid pipe object if (pipe == null) { return(null); } // Construct Revit Pipe Autodesk.Revit.DB.Plumbing.Pipe revitPipe = refObjects.GetValue <Autodesk.Revit.DB.Plumbing.Pipe>(document, pipe.BHoM_Guid); if (revitPipe != null) { return(revitPipe); } // Settings settings = settings.DefaultIfNull(); // Pipe type Autodesk.Revit.DB.Plumbing.PipeType pipeType = pipe.SectionProperty.ToRevitElementType(document, new List <BuiltInCategory> { BuiltInCategory.OST_PipingSystem }, settings, refObjects) as Autodesk.Revit.DB.Plumbing.PipeType; if (pipeType == null) { BH.Engine.Reflection.Compute.RecordError("No valid family has been found in the Revit model. Pipe creation requires the presence of the default Pipe Family Type."); return(null); } // End points XYZ start = pipe.StartPoint.ToRevit(); XYZ end = pipe.EndPoint.ToRevit(); // Level Level level = document.LevelBelow(Math.Min(start.Z, end.Z), settings); if (level == null) { return(null); } // Default system used for now // TODO: in the future you could look for the existing connectors and check if any of them overlaps with start/end of this pipe - if so, use it in Pipe.Create. // hacky/heavy way of getting all connectors in the link below - however, i would rather filter the connecting elements out by type/bounding box first for performance reasons // https://thebuildingcoder.typepad.com/blog/2010/06/retrieve-mep-elements-and-connectors.html Autodesk.Revit.DB.Plumbing.PipingSystemType pst = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Plumbing.PipingSystemType)).OfType <Autodesk.Revit.DB.Plumbing.PipingSystemType>().FirstOrDefault(); if (pst == null) { BH.Engine.Reflection.Compute.RecordError("No valid PipingSystemType can be found in the Revit model. Creating a revit Pipe requires a PipingSystemType."); return(null); } BH.Engine.Reflection.Compute.RecordWarning("Pipe creation will utilise the first available PipingSystemType from the Revit model."); SectionProfile sectionProfile = pipe.SectionProperty.SectionProfile; if (sectionProfile == null) { BH.Engine.Reflection.Compute.RecordError("Pipe creation requires a SectionProfile. \n No elements created."); return(null); } PipeSectionProperty pipeSectionProperty = pipe.SectionProperty; // Create Revit Pipe revitPipe = Autodesk.Revit.DB.Plumbing.Pipe.Create(document, pst.Id, pipeType.Id, level.Id, start, end); if (revitPipe == null) { BH.Engine.Reflection.Compute.RecordError("No Revit Pipe has been created. Please check inputs prior to push attempt."); return(null); } // Copy parameters from BHoM object to Revit element revitPipe.CopyParameters(pipe, settings); double flowRate = pipe.FlowRate; revitPipe.SetParameter(BuiltInParameter.RBS_PIPE_FLOW_PARAM, flowRate); // Get first available pipeLiningType from document Autodesk.Revit.DB.Plumbing.PipeInsulationType pit = null; if (sectionProfile.InsulationProfile != null) { pit = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Plumbing.PipeInsulationType)).FirstOrDefault() as Autodesk.Revit.DB.Plumbing.PipeInsulationType; if (pit == null) { BH.Engine.Reflection.Compute.RecordError("Any pipe insulation type needs to be present in the Revit model in order to push pipes with insulation.\n" + "Pipe has been created but no insulation has been applied."); } } // Round Pipe if (sectionProfile.ElementProfile is TubeProfile) { TubeProfile elementProfile = sectionProfile.ElementProfile as TubeProfile; // Set Element Diameter double diameter = elementProfile.Diameter; revitPipe.SetParameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM, diameter); // Outer and Inner Diameters double outDiameter = elementProfile.Diameter; double inDiameter = (((outDiameter / 2) - elementProfile.Thickness) * 2); revitPipe.SetParameter(BuiltInParameter.RBS_PIPE_OUTER_DIAMETER, outDiameter); revitPipe.SetParameter(BuiltInParameter.RBS_PIPE_INNER_DIAM_PARAM, inDiameter); // Set InsulationProfile if (pit != null) { TubeProfile insulationProfile = sectionProfile.InsulationProfile as TubeProfile; double insulationThickness = insulationProfile.Thickness; // Create pipe Insulation Autodesk.Revit.DB.Plumbing.PipeInsulation pIn = Autodesk.Revit.DB.Plumbing.PipeInsulation.Create(document, revitPipe.Id, pit.Id, insulationThickness); } } refObjects.AddOrReplace(pipe, revitPipe); return(revitPipe); }