示例#1
0
        /// <summary>
        /// Create an MEPSize from Xml
        /// </summary>
        /// <param name="sizeXElement"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        private static MEPSize ParseMEPSizeFromXml(XElement sizeXElement, Autodesk.Revit.DB.Document document)
        {
            XAttribute xaNominal         = sizeXElement.Attribute(XName.Get("nominalDiameter"));
            XAttribute xaInner           = sizeXElement.Attribute(XName.Get("innerDiameter"));
            XAttribute xaOuter           = sizeXElement.Attribute(XName.Get("outerDiameter"));
            XAttribute xaUsedInSizeLists = sizeXElement.Attribute(XName.Get("usedInSizeLists"));
            XAttribute xaUsedInSizing    = sizeXElement.Attribute(XName.Get("usedInSizing"));

            double nominal, inner, outer;
            bool   usedInSizeLists, usedInSizing;
            bool   r1 = double.TryParse(xaNominal.Value, out nominal);
            bool   r2 = double.TryParse(xaInner.Value, out inner);
            bool   r3 = double.TryParse(xaOuter.Value, out outer);
            bool   r4 = bool.TryParse(xaUsedInSizeLists.Value, out usedInSizeLists);
            bool   r5 = bool.TryParse(xaUsedInSizing.Value, out usedInSizing);

            if (!r1 || !r2 || !r3 || !r4 || !r5)
            {
                throw new RoutingPreferenceDataException("Cannot parse MEPSize attributes:" + xaNominal.Value + ", " + xaInner.Value + ", " + xaOuter.Value + ", " + xaUsedInSizeLists.Value + ", " + xaUsedInSizing.Value);
            }

            MEPSize newSize = null;

            try
            {
                newSize = new MEPSize(Convert.ConvertValueToFeet(nominal, document), Convert.ConvertValueToFeet(inner, document), Convert.ConvertValueToFeet(outer, document), usedInSizeLists, usedInSizing);
            }

            catch (Exception)
            {
                throw new RoutingPreferenceDataException("Invalid MEPSize values: " + nominal.ToString() + ", " + inner.ToString() + ", " + outer.ToString());
            }
            return(newSize);
        }
        public static void LoadAllData()
        {
            OpenExcelApp(resourcesPath);
            //load data from excel file if it's not already loaded
            //loading fixtures flow
            if (fixturesFlow == null)
            {
                LoadFromExcel(1);
            }
            //loading materials
            if (materials == null)
            {
                materials = LoadMaterialsFromExcel();
            }
            if (pipeTypes == null)
            {
                LoadBimitPipeTypes();
            }
            //initializing vars
            calculationsSchedule = PipeScheduleType.Create(doc, string.Concat(calculatedSystem.Name, DateTime.Now.ToString("yyyyMMddHHmmss")));
            List <string> matNames = new List <string>(materials.Keys);

            segments = new Dictionary <string, PipeSegment>();
            //creating this here so it doesn't get created multiple times
            FilteredElementCollector materialElementCollector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Materials);

            foreach (string matName in matNames)
            {
                ElementId matId;
                var       existingMat = materialElementCollector.FirstOrDefault(x => string.Compare(x.Name, matName.Remove(0, 5), true) == 0);
                if (null == existingMat)
                {
                    matId = Material.Create(doc, matName.Remove(0, 5));
                }
                else
                {
                    matId = existingMat.Id;
                }

                /*else
                 *  matId = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Materials).FirstOrDefault(x => x.Name == matName).Id;*/
                /*FamilySymbol newPipeType = CreateNewPipeType(standardPipeType, matName, matId);
                 * pipeTypes.Add(newPipeType);*/
                Values         defaultSize = materials[matName][0];
                double         nd          = (defaultSize.intd + defaultSize.extd) / 2;
                MEPSize        size        = new MEPSize(nd / 304.8, defaultSize.intd / 304.8, defaultSize.extd / 304.8, true, true);
                List <MEPSize> sizes       = new List <MEPSize>();
                sizes.Add(size);
                PipeSegment seg = PipeSegment.Create(doc, matId, calculationsSchedule.Id, sizes);
                segments.Add(matName, seg);
            }

            CloseExcelApp();
            dataIsExtracted = true;
        }
示例#3
0
        /// <summary>
        /// Create Xml from an MEPSize
        /// </summary>
        /// <param name="size"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        private static XElement CreateXmlFromMEPSize(MEPSize size, Autodesk.Revit.DB.Document document)
        {
            XElement xMEPSize = new XElement(XName.Get("MEPSize"));

            xMEPSize.Add(new XAttribute(XName.Get("innerDiameter"), (Convert.ConvertValueDocumentUnits(size.InnerDiameter, document)).ToString()));
            xMEPSize.Add(new XAttribute(XName.Get("nominalDiameter"), (Convert.ConvertValueDocumentUnits(size.NominalDiameter, document)).ToString()));
            xMEPSize.Add(new XAttribute(XName.Get("outerDiameter"), (Convert.ConvertValueDocumentUnits(size.OuterDiameter, document)).ToString()));
            xMEPSize.Add(new XAttribute(XName.Get("usedInSizeLists"), size.UsedInSizeLists));
            xMEPSize.Add(new XAttribute(XName.Get("usedInSizing"), size.UsedInSizing));
            return(xMEPSize);
        }
示例#4
0
        /// <summary>
        /// Create a PipeSegment from XML
        /// </summary>
        /// <param name="segmentXElement"></param>
        private void ParsePipeSegmentFromXML(XElement segmentXElement)
        {
            XAttribute xaMaterial  = segmentXElement.Attribute(XName.Get("materialName"));
            XAttribute xaSchedule  = segmentXElement.Attribute(XName.Get("pipeScheduleTypeName"));
            XAttribute xaRoughness = segmentXElement.Attribute(XName.Get("roughness"));

            ElementId materialId = GetMaterialByName(xaMaterial.Value); //There is nothing in the xml schema for creating new materials -- any material specified must already exist in the document.

            if (materialId == ElementId.InvalidElementId)
            {
                throw new RoutingPreferenceDataException("Cannot find Material: " + xaMaterial.Value + " in: " + segmentXElement.ToString());
            }
            ElementId scheduleId = GetPipeScheduleTypeByName(xaSchedule.Value);

            double roughness;
            bool   r1 = double.TryParse(xaRoughness.Value, out roughness);

            if (!r1)
            {
                throw new RoutingPreferenceDataException("Invalid roughness value: " + xaRoughness.Value + " in: " + segmentXElement.ToString());
            }

            if (roughness <= 0)
            {
                throw new RoutingPreferenceDataException("Invalid roughness value: " + xaRoughness.Value + " in: " + segmentXElement.ToString());
            }

            if (scheduleId == ElementId.InvalidElementId)
            {
                throw new RoutingPreferenceDataException("Cannot find Schedule: " + xaSchedule.Value + " in: " + segmentXElement.ToString()); //we will not create new schedules.
            }

            ElementId existingPipeSegmentId = GetSegmentByIds(materialId, scheduleId);

            if (existingPipeSegmentId != ElementId.InvalidElementId)
            {
                return; //Segment found, no need to create.
            }
            ICollection <MEPSize> sizes = new List <MEPSize>();

            foreach (XNode sizeNode in segmentXElement.Nodes())
            {
                if (sizeNode is XElement)
                {
                    MEPSize newSize = ParseMEPSizeFromXml(sizeNode as XElement, m_document);
                    sizes.Add(newSize);
                }
            }
            PipeSegment pipeSegment = PipeSegment.Create(m_document, materialId, scheduleId, sizes);

            pipeSegment.Roughness = Convert.ConvertValueToFeet(roughness, m_document);

            return;
        }
        //Set the sizes of a pipe
        public static void SetPipeSize(Pipe pipe, double nominalDiameter, double innerDiameter, double outerDiameter, string materialName)
        {
            //get the correspondent segment : material + schedule Type

            MEPSize size = new MEPSize(nominalDiameter / 304.8, innerDiameter / 304.8, outerDiameter / 304.8, true, true);

            try { segments[materialName].AddSize(size); }
            catch { }
            if (pipe.get_Parameter(BuiltInParameter.RBS_PIPE_SEGMENT_PARAM).Set(segments[materialName].Id))
            {
                pipe.get_Parameter(BuiltInParameter.RBS_PIPE_SEGMENT_PARAM).Set(segments[materialName].Id);
            }

            pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).SetValueString(nominalDiameter.ToString());
        }