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); }
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); }
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(); //} }
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()); }
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); }
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(); //} }