Esempio n. 1
0
        public StringBuilder CIIWriter(Document document, string systemAbbreviation)
        {
            doc   = document;
            key   = systemAbbreviation;
            sbCII = new StringBuilder();
            //Handle CII export parameters
            //Instantiate collector
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            //Get the elements
            collector.OfClass(typeof(PipingSystemType));
            //Select correct systemType
            PipingSystemType sQuery = (from PipingSystemType st in collector
                                       where string.Equals(st.Abbreviation, key)
                                       select st).FirstOrDefault();

            var query = from p in new plst().ListParametersAll
                        where string.Equals(p.Domain, "PIPL") && string.Equals(p.ExportingTo, "CII")
                        select p;

            foreach (pdef p in query.ToList())
            {
                if (string.IsNullOrEmpty(sQuery.get_Parameter(p.Guid).AsString()))
                {
                    continue;
                }
                sbCII.Append("    ");
                sbCII.Append(p.Keyword);
                sbCII.Append(" ");
                sbCII.Append(sQuery.get_Parameter(p.Guid).AsString());
                sbCII.AppendLine();
            }

            return(sbCII);
        }
Esempio n. 2
0
        public static IList <string> GetDistinctPhysicalPipingSystemTypeNames(Document doc)
        {
            FilteredElementCollector   collector         = new FilteredElementCollector(doc);
            HashSet <PipingSystem>     pipingSystems     = collector.OfClass(typeof(PipingSystem)).Cast <PipingSystem>().ToHashSet();
            HashSet <PipingSystemType> pipingSystemTypes = pipingSystems.Select(ps => doc.GetElement(ps.GetTypeId())).Cast <PipingSystemType>().ToHashSet();

            //Following code takes care if PCF_PIPL_EXCL has not been properly imported.
            PipingSystemType pstype = pipingSystemTypes.FirstOrDefault();

            if (pstype == null)
            {
                throw new Exception("No piping systems created yet! Draw some pipes.");
            }

            HashSet <string> abbreviations;

            //Do not allow systems with PCF_PIPL_EXCL if it exists!
            //GUID is defined in PCF_Exporter ParameterList!!!
            //Do not change w/o coordination
            if (pstype.get_Parameter(new Guid("C1C2C9FE-2634-42BA-89D0-5AF699F54D4C")) == null)
            {
                //If parameter doesn't exist, get all systems
                abbreviations = pipingSystemTypes.Select(pst => pst.Abbreviation).ToHashSet();
            }
            else
            {
                //If parameter exists, take only not excluded
                abbreviations = pipingSystemTypes
                                .Where(pst => pst.get_Parameter(new Guid("C1C2C9FE-2634-42BA-89D0-5AF699F54D4C")).AsInteger() == 0) //Filter out EXCLUDED piping systems
                                .Select(pst => pst.Abbreviation).ToHashSet();
            }

            return(abbreviations.Distinct().ToList());
        }
Esempio n. 3
0
        public static StringBuilder CIIWriter(Document doc, string systemAbbreviation)
        {
            StringBuilder sbCII = new StringBuilder();
            //Handle CII export parameters
            //Instantiate collector
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            //Get the elements
            PipingSystemType sQuery = collector.OfClass(typeof(PipingSystemType))
                                      .WherePasses(Shared.Filter.ParameterValueGenericFilter(doc, systemAbbreviation, BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM))
                                      .Cast <PipingSystemType>()
                                      .FirstOrDefault();

            ////Select correct systemType
            //PipingSystemType sQuery = (from PipingSystemType st in collector
            //                           where string.Equals(st.Abbreviation, systemAbbreviation)
            //                           select st).FirstOrDefault();

            var query = from p in new plst().LPAll
                        where string.Equals(p.Domain, "PIPL") && string.Equals(p.ExportingTo, "CII")
                        select p;

            foreach (pdef p in query.ToList())
            {
                if (string.IsNullOrEmpty(sQuery.get_Parameter(p.Guid).AsString()))
                {
                    continue;
                }
                sbCII.AppendLine("    " + p.Keyword + " " + sQuery.get_Parameter(p.Guid).AsString());
            }

            return(sbCII);
        }
Esempio n. 4
0
        /// <summary>
        /// 根据pipingSystemTypeName获取对应的管道系统
        /// </summary>
        /// <param name="pipingSystemTypeName"></param>
        /// <returns></returns>
        public PipingSystemType SelectPipingSystemType(string pipingSystemTypeName)
        {
            FilteredElementCollector collector        = new FilteredElementCollector(doc);
            PipingSystemType         pipingSystemType = collector.OfClass(typeof(PipingSystemType)).
                                                        Cast <PipingSystemType>().
                                                        First(x => x.Name == pipingSystemTypeName);

            return(pipingSystemType);
        }
        public StringBuilder Export(string pipeLineGroupingKey, Document doc)
        {
            key = pipeLineGroupingKey;

            try
            {
                //Instantiate collector
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                //Get the elements
                collector.OfClass(typeof(PipingSystemType));
                //Select correct systemType
                PipingSystemType sQuery = (from PipingSystemType st in collector
                                           where string.Equals(st.Abbreviation, key)
                                           select st).FirstOrDefault();

                sbPipeline = new StringBuilder();

                IEnumerable <pdef> query = from p in new plst().ListParametersAll
                                           where string.Equals(p.Domain, "PIPL") && !string.Equals(p.ExportingTo, "CII")
                                           select p;

                sbPipeline.Append("PIPELINE-REFERENCE ");
                sbPipeline.Append(key);
                sbPipeline.AppendLine();

                foreach (pdef p in query)
                {
                    if (string.IsNullOrEmpty(sQuery.get_Parameter(p.Guid).AsString()))
                    {
                        continue;
                    }
                    sbPipeline.Append("    ");
                    sbPipeline.Append(p.Keyword);
                    sbPipeline.Append(" ");
                    sbPipeline.Append(sQuery.get_Parameter(p.Guid).AsString());
                    sbPipeline.AppendLine();
                }
            }
            catch (Exception e)
            {
                Util.ErrorMsg(e.Message);
            }

            return(sbPipeline);

            //Debug
            //// Clear the output file
            //System.IO.File.WriteAllBytes(InputVars.OutputDirectoryFilePath + "Pipes.pcf", new byte[0]);

            //// Write to output file
            //using (StreamWriter w = File.AppendText(InputVars.OutputDirectoryFilePath + "Pipes.pcf"))
            //{
            //    w.Write(sbPipes);
            //    w.Close();
            //}
        }
Esempio n. 6
0
        public static void CreateInitialElementList(ElementCollection collection, string[] source)
        {
            int iterationCounter = -1;

            //Holds current pipeline reference
            string curPipelineReference = "PRE-PIPELINE";

            foreach (string line in source)
            {
                //Count iterations
                iterationCounter++;

                //Logic test for Type or Property
                if (!line.StartsWith("    "))
                {
                    //Make a new Element
                    ElementSymbol CurElementSymbol = new ElementSymbol();
                    //Get the keyword from the parsed line
                    CurElementSymbol.ElementType = GetElementKeyword(line);
                    //Get the element position in the file
                    CurElementSymbol.Position = iterationCounter;
                    //Set the correct pipeline reference
                    //Add here if other top levet types needed that is on the same level as PIPELINE-REFERENCE
                    switch (CurElementSymbol.ElementType)
                    {
                    case "PIPELINE-REFERENCE":
                        curPipelineReference = GetRestOfTheLine(line);
                        break;

                    case "MATERIALS":
                        curPipelineReference = "MATERIALS";
                        break;
                    }
                    CurElementSymbol.PipelineReference = curPipelineReference;

                    //Get the PipingSystemType based on the reference
                    //Instantiate collector
                    FilteredElementCollector collector = new FilteredElementCollector(pif._doc);

                    ElementParameterFilter filter = Filter.ParameterValueFilter(curPipelineReference, BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM);
                    //Get the elements
                    PipingSystemType sQuery = collector.OfClass(typeof(PipingSystemType)).WherePasses(filter).Cast <PipingSystemType>().FirstOrDefault();

                    if (sQuery != null)
                    {
                        CurElementSymbol.PipingSystemType = sQuery;
                    }

                    //Add the extracted element to the collection
                    collection.Elements.Add(CurElementSymbol);
                    collection.Position.Add(iterationCounter);
                }
            }
        }
Esempio n. 7
0
 public static string MEPSystemAbbreviation(this Connector con, Document doc, bool ignoreMepSystemNull = false)
 {
     if (con.MEPSystem != null)
     {
         MEPSystem        ps  = con.MEPSystem;
         PipingSystemType pst = (PipingSystemType)doc.GetElement(ps.GetTypeId());
         return(pst.Abbreviation);
     }
     else if (ignoreMepSystemNull)
     {
         return("");
     }
     else
     {
         throw new Exception($"A connector at element {con.Owner.Id.IntegerValue} has MEPSystem = null!");
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Constructor, initialize all the fields of this class.
        /// </summary>
        /// <param name="data">Revit ExternalCommandData from external command entrance</param>
        public Resolver(ExternalCommandData data)
        {
            m_rvtDoc   = data.Application.ActiveUIDocument.Document;
            m_rvtApp   = data.Application.Application;
            m_detector = new Detector(m_rvtDoc);

            FilteredElementCollector collector = new FilteredElementCollector(m_rvtDoc);
            var pipingSystemTypes = collector.OfClass(typeof(PipingSystemType)).ToElements();

            foreach (PipingSystemType pipingSystemType in pipingSystemTypes)
            {
                if (pipingSystemType.SystemClassification == MEPSystemClassification.SupplyHydronic ||
                    pipingSystemType.SystemClassification == MEPSystemClassification.ReturnHydronic)
                {
                    m_pipingSystemType = pipingSystemType;
                    break;
                }
            }
        }
Esempio n. 9
0
            public static bool Recognization(Pipe pipe)
            {
                _pipe = pipe;
                try
                {
                    _diameter = pipe.Diameter * 12;
                }
                catch
                {
                    _abandonWriter.WriteAbandonment(pipe, AbandonmentTable.Pipe_NonCircular);
                    return(false);
                }
                _length = pipe.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
                _level  = _doc.GetElement(pipe.get_Parameter(BuiltInParameter.RBS_START_LEVEL_PARAM).AsElementId()) as Level;
                _offset = pipe.get_Parameter(BuiltInParameter.RBS_START_OFFSET_PARAM).AsDouble();
                bool isFound;

                _floor = _myLevel.GetFloor(out isFound, _level, _offset) - 1;
                if (_floor == MyLevel.GetLevelNum() || _floor < 0)
                {
                    _abandonWriter.WriteAbandonment(pipe, AbandonmentTable.LevelOutOfRoof);
                    return(false);
                }
                SDC sdc = _addiInfo.sdc;

                _material = ((Material)_doc.GetElement(pipe.get_Parameter(BuiltInParameter.RBS_PIPE_MATERIAL_PARAM).AsElementId())).MaterialCategory;
                _pipeType = PipeType.Unknown;
                try
                {
                    PipingSystem     pipingSys     = pipe.MEPSystem as PipingSystem;
                    PipingSystemType pipingSysType = _doc.GetElement(pipingSys.GetTypeId()) as PipingSystemType;
                    FluidType        fluidType     = _doc.GetElement(pipingSysType.FluidType) as FluidType;
                    String           pstName       = pipingSysType.Name;

                    if (pstName.Contains("冷水"))
                    {
                        _pipeType = PipeType.ColdWater;
                    }
                    if (pstName.Contains("热水"))
                    {
                        _pipeType = PipeType.HotWater;
                    }
                    if (pstName.Contains("卫生"))
                    {
                        _pipeType = PipeType.SanitaryWater;
                    }
                    if (pstName.Contains("冷却"))
                    {
                        _pipeType = PipeType.ChilledWater;
                    }
                    if (pstName.Contains("蒸汽"))
                    {
                        _pipeType = PipeType.Steam;
                    }
                    if (pstName.Contains("消防"))
                    {
                        _pipeType = PipeType.FireSprinkler;
                    }

                    if (_pipeType == PipeType.Unknown)
                    {
                        double temperature = pipingSysType.FluidTemperature - 273.15;
                        if (5 < temperature && temperature < 15)
                        {
                            _pipeType = PipeType.ColdWater;
                        }
                        else if (30 < temperature && temperature < 100)
                        {
                            _pipeType = PipeType.HotWater;
                        }
                        else if (temperature <= 5)
                        {
                            _pipeType = PipeType.ChilledWater;
                        }
                        else if (100 <= temperature)
                        {
                            _pipeType = PipeType.Steam;
                        }
                        else
                        {
                            _abandonWriter.WriteAbandonment(pipe, AbandonmentTable.Pipe_TypeUnknown);
                            return(false);
                        }
                    }
                }
                catch
                {
                    _abandonWriter.WriteAbandonment(pipe, AbandonmentTable.Pipe_TypeUnknown);
                    return(false);
                }
                if (_pipeType != PipeType.ColdWater && !IsValidMaterial(_material))
                {
                    _abandonWriter.WriteAbandonment(_pipe, AbandonmentTable.Pipe_MatlOOR);
                    return(false);
                }

                return(true);
            }
Esempio n. 10
0
        internal Result ExecuteMyCommand(UIApplication uiApp)
        {
            Document doc = uiApp.ActiveUIDocument.Document;

            FilteredElementCollector collector = new FilteredElementCollector(doc);

            #region Pipeline schedule export

            //Collect piping systems
            collector.OfClass(typeof(PipingSystem));

            //Group all elements by their Family and Type
            IOrderedEnumerable <Element> orderedCollector            = collector.OrderBy(e => e.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString());
            IEnumerable <IGrouping <string, Element> > elementGroups = from e in orderedCollector group e by e.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString();

            xel.Application excel = new xel.Application();
            if (null == excel)
            {
                BuildingCoderUtilities.ErrorMsg("Failed to get or start Excel.");
                return(Result.Failed);
            }
            excel.Visible = true;

            xel.Workbook  workbook = excel.Workbooks.Add(Missing.Value);
            xel.Worksheet worksheet;
            worksheet      = excel.ActiveSheet as xel.Worksheet;
            worksheet.Name = "PCF Export - pipelines";

            worksheet.Columns.ColumnWidth = 20;

            worksheet.Cells[1, 1] = "Family and Type";

            //Change domain for query
            string curDomain = "PIPL", curUsage = "U";

            var query = from p in new plst().LPAll
                        where p.Domain == curDomain && p.Usage == curUsage
                        select p;

            worksheet.Range["A1", BuildingCoderUtilities.GetColumnName(query.Count()) + "1"].Font.Bold = true;

            //Export family and type names to first column and parameter values
            int row = 2, col = 2;
            foreach (IGrouping <string, Element> gp in elementGroups)
            {
                worksheet.Cells[row, 1] = gp.Key;
                foreach (var p in query.ToList())
                {
                    if (row == 2)
                    {
                        worksheet.Cells[1, col] = p.Name;           //Fill out top row only in the first iteration
                    }
                    ElementId        id = gp.First().GetTypeId();
                    PipingSystemType ps = (PipingSystemType)doc.GetElement(id); //SystemType parameters can only be read from type elements
                    worksheet.Cells[row, col] = ps.get_Parameter(p.Guid).AsString();
                    col++;                                                      //Increment column
                }
                row++; col = 2;                                                 //Increment row and reset column
            }

            #endregion

            #region Element schedule export

            //Define a collector (Pipe OR FamInst) AND (Fitting OR Accessory OR Pipe).
            //This is to eliminate FamilySymbols from collector which would throw an exception later on.
            collector = Shared.Filter.GetElementsWithConnectors(doc);

            //Group all elements by their Family and Type
            orderedCollector =
                collector.OrderBy(e => e.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString());
            elementGroups = from e in orderedCollector
                            group e by e.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString();


            excel.Sheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            worksheet      = excel.ActiveSheet as xel.Worksheet;
            worksheet.Name = "PCF Export - elements";

            worksheet.Columns.ColumnWidth = 20;

            worksheet.Cells[1, 1] = "Family and Type";

            //Query parameters
            curDomain = "ELEM";

            //Formatting must occur here, because it depends on query
            worksheet.Range["A1", BuildingCoderUtilities.GetColumnName(query.Count()) + "1"].Font.Bold = true;

            //Export family and type names to first column and parameter values
            row = 2; col = 2;
            foreach (IGrouping <string, Element> gp in elementGroups)
            {
                worksheet.Cells[row, 1] = gp.Key;
                foreach (var p in query)
                {
                    if (row == 2)
                    {
                        worksheet.Cells[1, col] = p.Name;           //Fill out top row only in the first iteration
                    }
                    worksheet.Cells[row, col] = gp.First().get_Parameter(p.Guid).AsString();
                    col++;      //Increment column
                }
                row++; col = 2; //Increment row and reset column
            }

            #endregion

            collector.Dispose();
            return(Result.Succeeded);
        }
Esempio n. 11
0
        public StringBuilder Export(string key, Document doc)
        {
            StringBuilder sbPipeline = new StringBuilder();

            try
            {
                //Instantiate collector
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                //Get the elements
                collector.OfClass(typeof(PipingSystemType));
                //Select correct systemType
                PipingSystemType pipingSystemType = (from PipingSystemType st in collector
                                                     where string.Equals(st.Abbreviation, key)
                                                     select st).FirstOrDefault();

                IEnumerable <pdef> query = from p in Plst.LPAll
                                           where string.Equals(p.Domain, "PIPL") &&
                                           !string.Equals(p.ExportingTo, "CII") &&
                                           !string.Equals(p.ExportingTo, "LDT")
                                           select p;

                sbPipeline.Append("PIPELINE-REFERENCE ");
                sbPipeline.Append(key);
                sbPipeline.AppendLine();

                if (PCF_Functions.InputVars.ExportToIsogen)
                {
                    ////Facilitate export to Isogen
                    ////This is where PipeSystemAbbreviation is stored
                    //sbPipeline.Append("    ");
                    //sbPipeline.Append("Attribute10");
                    //sbPipeline.Append(" ");
                    //sbPipeline.Append(key);
                    //sbPipeline.AppendLine();

                    string LDTPath = mySettings.Default.LDTPath;
                    if (!string.IsNullOrEmpty(LDTPath) && File.Exists(LDTPath))
                    {
                        var dataSet = Shared.DataHandler.ImportExcelToDataSet(LDTPath, "YES");
                        var data    = Shared.DataHandler.ReadDataTable(dataSet.Tables, "Pipelines");

                        string sysAbbr = pipingSystemType.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).AsString();
                        string parName = "";
                        string projId  = iv.PCF_PROJECT_IDENTIFIER;

                        //EnumerableRowCollection<string> ldtQuery = from row in data.AsEnumerable()
                        //                                           where row.Field<string>("PCF_PROJID") == projId &&
                        //                                                 row.Field<string>("LINE_NAME") == sysAbbr
                        //                                           select row.Field<string>(parName);

                        //var lineId = pipingSystemType.get_Parameter(Plst.PCF_PIPL_LINEID.Guid).AsString();

                        var LdtPars = Plst.LPAll.Where(x => x.ExportingTo == "LDT");
                        foreach (pdef par in LdtPars)
                        {
                            parName = par.Name;

                            int rowIndex = data.Rows.IndexOf(data.Select(
                                                                 $"PCF_PROJID = '{projId}' AND LINE_NAME = '{sysAbbr}'")[0]);

                            string value = Convert.ToString(data.Rows[rowIndex][parName]);
                            //string value = ldtQuery.FirstOrDefault();

                            if (!string.IsNullOrEmpty(value))
                            {
                                sbPipeline.Append("    ");
                                sbPipeline.Append(par.Keyword);
                                sbPipeline.Append(" ");
                                sbPipeline.Append(value);
                                sbPipeline.AppendLine();
                            }
                        }
                    }
                }

                foreach (pdef p in query)
                {
                    if (string.IsNullOrEmpty(pipingSystemType.get_Parameter(p.Guid).AsString()))
                    {
                        continue;
                    }
                    sbPipeline.Append("    ");
                    sbPipeline.Append(p.Keyword);
                    sbPipeline.Append(" ");
                    sbPipeline.Append(pipingSystemType.get_Parameter(p.Guid).AsString());
                    sbPipeline.AppendLine();
                }
            }
            catch (Exception e)
            {
                BuildingCoderUtilities.ErrorMsg(e.Message);
            }

            return(sbPipeline);

            //Debug
            //// Clear the output file
            //System.IO.File.WriteAllBytes(InputVars.OutputDirectoryFilePath + "Pipes.pcf", new byte[0]);

            //// Write to output file
            //using (StreamWriter w = File.AppendText(InputVars.OutputDirectoryFilePath + "Pipes.pcf"))
            //{
            //    w.Write(sbPipes);
            //    w.Close();
            //}
        }