public static List <IBHoMObject> FromRevit(this Autodesk.Revit.DB.Plumbing.Pipe pipe, Discipline discipline, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { switch (discipline) { case Discipline.Architecture: case Discipline.Physical: case Discipline.Environmental: return(new List <IBHoMObject>(pipe.PipeFromRevit(settings, refObjects))); default: return(null); } }
public static IProfile Profile(this Autodesk.Revit.DB.Plumbing.Pipe pipe, RevitSettings settings = null) { settings = settings.DefaultIfNull(); List <ICurve> edges = new List <ICurve>(); double diameter = pipe.Diameter.ToSI(UnitType.UT_PipeSize); // Thickness double outsideDiameter = pipe.LookupParameterDouble(BuiltInParameter.RBS_PIPE_OUTER_DIAMETER); double insideDiameter = pipe.LookupParameterDouble(BuiltInParameter.RBS_PIPE_INNER_DIAM_PARAM); double thickness = (outsideDiameter - insideDiameter) / 2; return(BH.Engine.Spatial.Create.TubeProfile(diameter, thickness)); }
public static List <BH.oM.MEP.System.Pipe> PipeFromRevit(this Autodesk.Revit.DB.Plumbing.Pipe revitPipe, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); // Reuse a BHoM duct from refObjects if it has been converted before List <BH.oM.MEP.System.Pipe> bhomPipes = refObjects.GetValues <BH.oM.MEP.System.Pipe>(revitPipe.Id); if (bhomPipes != null) { return(bhomPipes); } else { bhomPipes = new List <BH.oM.MEP.System.Pipe>(); } List <BH.oM.Geometry.Line> queried = Query.LocationCurveMEP(revitPipe, settings); // Flow rate double flowRate = revitPipe.LookupParameterDouble(BuiltInParameter.RBS_PIPE_FLOW_PARAM); // Flow rate // Pipe section property BH.oM.MEP.System.SectionProperties.PipeSectionProperty sectionProperty = revitPipe.PipeSectionProperty(settings); for (int i = 0; i < queried.Count; i++) { BH.oM.Geometry.Line segment = queried[i]; BH.oM.MEP.System.Pipe thisSegment = new Pipe { StartPoint = segment.StartPoint(), EndPoint = segment.EndPoint(), FlowRate = flowRate, SectionProperty = sectionProperty }; //Set identifiers, parameters & custom data thisSegment.SetIdentifiers(revitPipe); thisSegment.CopyParameters(revitPipe, settings.ParameterSettings); thisSegment.SetProperties(revitPipe, settings.ParameterSettings); bhomPipes.Add(thisSegment); } refObjects.AddOrReplace(revitPipe.Id, bhomPipes); return(bhomPipes); }
public bool CanConvertToSpeckle(object @object) { return(@object switch { DB.DetailCurve _ => true, DB.DirectShape _ => true, DB.FamilyInstance _ => true, DB.Floor _ => true, DB.Level _ => true, DB.View _ => true, DB.ModelCurve _ => true, DB.Opening _ => true, DB.RoofBase _ => true, DB.Area _ => true, DB.Architecture.Room _ => true, DB.Architecture.TopographySurface _ => true, DB.Wall _ => true, DB.Mechanical.Duct _ => true, DB.Mechanical.Space _ => true, DB.Plumbing.Pipe _ => true, DB.Electrical.Wire _ => true, DB.CurtainGridLine _ => true, //these should be handled by curtain walls DB.Architecture.BuildingPad _ => true, DB.Architecture.Stairs _ => true, DB.Architecture.StairsRun _ => true, DB.Architecture.StairsLanding _ => true, DB.Architecture.Railing _ => true, DB.Architecture.TopRail _ => true, DB.Ceiling _ => true, DB.PointCloudInstance _ => true, DB.Group _ => true, DB.ProjectInfo _ => true, DB.ElementType _ => true, DB.Grid _ => true, DB.ReferencePoint _ => true, DB.Structure.AnalyticalModelStick _ => true, DB.Structure.AnalyticalModelSurface _ => true, DB.Structure.BoundaryConditions _ => true, _ => (@object as Element).IsElementSupported() });
public static IEnumerable <IBHoMObject> FromRevit(this Autodesk.Revit.DB.Plumbing.Pipe pipe, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { IEnumerable <IElement1D> result = null; switch (discipline) { case Discipline.Architecture: case Discipline.Physical: case Discipline.Environmental: result = new List <IElement1D>(pipe.PipeFromRevit(settings, refObjects)); break; } if (result != null && transform?.IsIdentity == false) { TransformMatrix bHoMTransform = transform.FromRevit(); result = result.Select(x => x.ITransform(bHoMTransform)); } return(result?.Cast <IBHoMObject>().ToList()); }
public BuiltElements.Pipe PipeToSpeckle(DB.Plumbing.Pipe revitPipe) { // geometry var baseGeometry = LocationToSpeckle(revitPipe); if (!(baseGeometry is Line baseLine)) { throw new Speckle.Core.Logging.SpeckleException("Only line based Pipes are currently supported."); } // speckle pipe var specklePipe = new RevitPipe { baseCurve = baseLine, family = revitPipe.PipeType.FamilyName, type = revitPipe.PipeType.Name, systemName = revitPipe.MEPSystem.Name, systemType = GetParamValue <string>(revitPipe, BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM), diameter = GetParamValue <double>(revitPipe, BuiltInParameter.RBS_PIPE_DIAMETER_PARAM), length = GetParamValue <double>(revitPipe, BuiltInParameter.CURVE_ELEM_LENGTH), level = ConvertAndCacheLevel(revitPipe, BuiltInParameter.RBS_START_LEVEL_PARAM), displayMesh = GetElementMesh(revitPipe) }; GetAllRevitParamsAndIds(specklePipe, revitPipe, new List <string> { "RBS_SYSTEM_CLASSIFICATION_PARAM", "RBS_PIPING_SYSTEM_TYPE_PARAM", "RBS_SYSTEM_NAME_PARAM", "RBS_PIPE_DIAMETER_PARAM", "CURVE_ELEM_LENGTH", "RBS_START_LEVEL_PARAM", }); //Report.Log($"Converted Pipe {revitPipe.Id}"); return(specklePipe); }
/// <summary> /// Initialize a Pipe element /// </summary> /// <param name="instance">The instance.</param> private void InitObject(Autodesk.Revit.DB.Plumbing.Pipe instance) { Autodesk.Revit.DB.MEPCurve fi = instance as Autodesk.Revit.DB.MEPCurve; InternalSetMEPCurve(fi); }
/// <summary> /// Initializes a new instance of the <see cref="Pipe"/> class. /// </summary> /// <param name="instance">The instance.</param> protected Pipe(Autodesk.Revit.DB.Plumbing.Pipe instance) { SafeInit(() => InitObject(instance)); }
public static Dictionary <string, object> ByPolyCurve(Revit.Elements.Element pipeType, Revit.Elements.Element pipingSystemType, PolyCurve polyCurve, Revit.Elements.Level level, double maxLength, Featureline featureline) { Utils.Log(string.Format("Pipe.ByPolyCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); var totalTransformInverse = totalTransform.Inverse(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = pipingSystemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var l = level.InternalElement as Autodesk.Revit.DB.Level; double length = polyCurve.Length; int subdivisions = Convert.ToInt32(Math.Ceiling(length / maxLength)); IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); points.Add(polyCurve.StartPoint); foreach (Autodesk.DesignScript.Geometry.Point p in polyCurve.PointsAtEqualChordLength(subdivisions)) { points.Add(p); } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); IList <ElementId> ids = new List <ElementId>(); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); Autodesk.DesignScript.Geometry.Point start = null; Autodesk.DesignScript.Geometry.Point end = null; Autodesk.DesignScript.Geometry.Point sp = null; Autodesk.DesignScript.Geometry.Point ep = null; Autodesk.DesignScript.Geometry.Curve curve = null; for (int i = 0; i < points.Count - 1; ++i) { start = points[i].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = points[i + 1].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); Autodesk.Revit.DB.Plumbing.Pipe p = Autodesk.Revit.DB.Plumbing.Pipe.CreatePlaceholder(DocumentManager.Instance.CurrentDBDocument, oSystemType.Id, oType.Id, l.Id, s, e); ids.Add(p.Id); } var pipeIds = Autodesk.Revit.DB.Plumbing.PlumbingUtils.ConvertPipePlaceholders(DocumentManager.Instance.CurrentDBDocument, ids); TransactionManager.Instance.TransactionTaskDone(); DocumentManager.Instance.CurrentDBDocument.Regenerate(); Pipe[] pipes = GetPipesByIds(pipeIds); foreach (Pipe pipe in pipes) { curve = pipe.Location.Transform(totalTransformInverse) as Autodesk.DesignScript.Geometry.Curve; sp = curve.StartPoint; ep = curve.EndPoint; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(sp.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(sp.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(sp.Z, 3)); var soe = featureline.GetStationOffsetElevationByPoint(sp); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round((double)soe["Elevation"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); soe = featureline.GetStationOffsetElevationByPoint(ep); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round((double)soe["Elevation"], 3)); } IList <Fitting> fittings = new List <Fitting>(); for (int i = 0; i < pipes.Length - 1; ++i) { Fitting fitting = null; try { fitting = Fitting.Elbow(pipes[i], pipes[i + 1]); } catch { } fittings.Add(fitting); } if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } if (sp != null) { sp.Dispose(); } if (ep != null) { ep.Dispose(); } if (curve != null) { curve.Dispose(); } foreach (var item in points) { if (item != null) { item.Dispose(); } } points.Clear(); Utils.Log(string.Format("Pipe.ByPolyCurve completed.", "")); return(new Dictionary <string, object>() { { "Pipes", pipes }, { "Fittings", fittings } }); }
/// <summary> /// Initialize a Pipe element. /// </summary> /// <param name="instance">The instance.</param> private void InitPipe(Autodesk.Revit.DB.Plumbing.Pipe instance) { InternalSetMEPCurve(instance); }
/// <summary> /// Initializes a new instance of the <see cref="PipePlaceHolder"/> class. /// </summary> /// <param name="instance">The instance.</param> protected PipePlaceHolder(Autodesk.Revit.DB.Plumbing.Pipe instance) { SafeInit(() => InitPipe(instance)); }
//在打开的工作簿中全部更新一次数据 public void UpdataInOpenWorkBook(Document doc, string workBookFullName, string workSheetName, int startRow, int startCol) { List <ArrayList> exportInformation = new List <ArrayList>(); //获取项目中所有管道和管道附件 FilteredElementCollector plumbingCollector = new FilteredElementCollector(doc); ElementIsElementTypeFilter filter1 = new ElementIsElementTypeFilter(true); List <ElementFilter> filterSet = new List <ElementFilter>(); filterSet.Add(new ElementCategoryFilter(BuiltInCategory.OST_PipeCurves)); filterSet.Add(new ElementCategoryFilter(BuiltInCategory.OST_PipeAccessory)); LogicalOrFilter orFilter = new LogicalOrFilter(filterSet); plumbingCollector.WherePasses(new LogicalAndFilter(filter1, orFilter)).ToElements(); int num = 0; //获得用于创建Excel的数据 foreach (Element elem in plumbingCollector) { switch ((BuiltInCategory)elem.Category.Id.IntegerValue) { case BuiltInCategory.OST_PipeCurves: Autodesk.Revit.DB.Plumbing.Pipe p = elem as Autodesk.Revit.DB.Plumbing.Pipe; //识别所有有缩写的管道 if (p.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM).AsString() != "") { num += 1; exportInformation.Add(new Command.PipeCalculation(doc, p).PipeCalcInformation()); } break; case BuiltInCategory.OST_PipeAccessory: FamilyInstance pa = elem as FamilyInstance; //识别阀门 if (pa.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString().Contains("阀")) { num += 1; exportInformation.Add(new Command.PipeCalculation(doc, pa).PipeCalcInformation()); } break; } } var excelApp = Marshal.GetActiveObject("Excel.Application") as ExcelCom.Application; if (excelApp != null) { bool workBookIsOpen = false; bool hasWorkSheet = false; //查找工作簿 for (int i = 0; i < excelApp.Workbooks.Count; i++) { var workBook = excelApp.Workbooks[i + 1] as ExcelCom.Workbook; //Autodesk.Revit.UI.TaskDialog.Show("goodwish", workBook.FullName + "\n" + workBookFullName); if (workBook != null && workBook.FullName == workBookFullName) { //Autodesk.Revit.UI.TaskDialog.Show("goodwish", "ishere"); workBookIsOpen = true; //查找工作表 for (int j = 0; j < workBook.Worksheets.Count; j++) { var workSheet = excelApp.Worksheets[j + 1] as ExcelCom.Worksheet; if (workSheet != null && workSheet.Name == workSheetName) { //获得最后一行 int lastRow = workSheet.UsedRange.Rows.Count + startRow - 1; //清空数据 var range = workSheet.Range[workSheet.Cells[startRow + 1, startCol], workSheet.Cells[lastRow, startCol + 8]] as ExcelCom.Range; range.Value2 = null; //输入数据 for (int k = 0; k < exportInformation.Count; k++) { var arrayList = exportInformation[k]; for (int l = 0; l < arrayList.Count; l++) { workSheet.Cells[k + startRow + 1, l + startCol].Value = arrayList[l]; } } break; } } //工作簿中没有目标工作表 if (hasWorkSheet == false) { //to do } break; } } //工作表未打开 if (workBookIsOpen == false) { //to do } } }
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 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); }