Beispiel #1
0
        /***************************************************/

        public static Autodesk.Revit.DB.Plumbing.PipeType ToRevitElementType(this oM.MEP.System.SectionProperties.PipeSectionProperty property, Document document, IEnumerable <BuiltInCategory> categories = null, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (property == null || document == null)
            {
                return(null);
            }

            Autodesk.Revit.DB.Plumbing.PipeType elementType = refObjects.GetValue <Autodesk.Revit.DB.Plumbing.PipeType>(document, property.BHoM_Guid);
            if (elementType != null)
            {
                return(elementType);
            }

            settings = settings.DefaultIfNull();

            elementType = property.ElementType(document, categories, settings) as Autodesk.Revit.DB.Plumbing.PipeType;
            if (elementType != null)
            {
                return(elementType);
            }

            List <Autodesk.Revit.DB.Plumbing.PipeType> pipeTypes = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Plumbing.PipeType)).Cast <Autodesk.Revit.DB.Plumbing.PipeType>().ToList();

            if (property.SectionProfile.ElementProfile is BH.oM.Spatial.ShapeProfiles.TubeProfile)
            {
                elementType = pipeTypes.FirstOrDefault(x => x.FamilyName == "Pipe Types");
            }

            if (elementType != null)
            {
                BH.Engine.Reflection.Compute.RecordNote($"Pipe is being pushed as the first type available in the Revit model, in this case {elementType.Name}.");
            }
            else
            {
                return(null);
            }

            // Copy parameters from BHoM object to Revit element
            elementType.CopyParameters(property, settings);

            refObjects.AddOrReplace(property, elementType);
            return(elementType);
        }
Beispiel #2
0
        /// <summary>
        /// Initialize a Pipe element
        /// </summary>
        /// <param name="pipeType">Type of the pipe.</param>
        /// <param name="pipingSystemType">Type of the piping system.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="level">The level.</param>
        private void InitObject(Autodesk.Revit.DB.Plumbing.PipeType pipeType, Autodesk.Revit.DB.Plumbing.PipingSystemType pipingSystemType, XYZ start, XYZ end,
                                Autodesk.Revit.DB.Level level)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.MEPCurve>(DocumentManager.Instance.CurrentDBDocument);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetMEPCurve(oldFam);
                InternalSetMEPCurveType(pipeType);
                InternalSetPosition(start, end);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            Autodesk.Revit.DB.MEPCurve fi;

            if (DocumentManager.Instance.CurrentDBDocument.IsFamilyDocument)
            {
                fi = null;
            }
            else
            {
                fi = Autodesk.Revit.DB.Plumbing.Pipe.Create(DocumentManager.Instance.CurrentDBDocument, pipingSystemType.Id, pipeType.Id, level.Id, start, end);
            }

            InternalSetMEPCurve(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Pipe"/> class.
 /// </summary>
 /// <param name="pipeType">Type of the pipe.</param>
 /// <param name="systemType">Type of the system.</param>
 /// <param name="start">The start.</param>
 /// <param name="end">The end.</param>
 /// <param name="level">The level.</param>
 internal Pipe(Autodesk.Revit.DB.Plumbing.PipeType pipeType, Autodesk.Revit.DB.Plumbing.PipingSystemType systemType, XYZ start, XYZ end,
               Autodesk.Revit.DB.Level level)
 {
     InitObject(pipeType, systemType, start, end, level);
 }
Beispiel #4
0
        /***************************************************/
        /****              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);
        }