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;
        }
Example #2
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;
        }