/* adds the Excel column to match the Etabs Object. * Sets the feilds into a object that holds all the information from the excel row. */ public void CaseSwitch(int Column, object cellValue, EtabObject Etabs_Object) { try { switch (Column) { case 1: Etabs_Object._SectionName = Convert.ToString(cellValue); break; case 2: Etabs_Object._LabelNumber = Convert.ToString(cellValue); break; case 3: Etabs_Object.Set_Start_X(Convert.ToDouble(cellValue)); break; case 4: Etabs_Object.Set_Start_Y(Convert.ToDouble(cellValue)); break; case 5: Etabs_Object.Set_Start_Z(Convert.ToDouble(cellValue)); break; case 6: Etabs_Object.Set_End_X(Convert.ToDouble(cellValue)); break; case 7: Etabs_Object.Set_End_Y(Convert.ToDouble(cellValue)); break; case 8: Etabs_Object.Set_End_Z(Convert.ToDouble(cellValue)); break; case 9: Etabs_Object.Set_UniqueID(Convert.ToInt32(cellValue)); break; case 10: Etabs_Object._SectionType = Convert.ToString(cellValue); break; } } catch { } }
public List <EtabObject> Get_ExcelFileToList(string path) { List <EtabObject> EtabsList = new List <EtabObject>(); try { // Gets Excel file using a file path var package = new ExcelPackage(new FileInfo(path)); ExcelWorksheet workSheet = package.Workbook.Worksheets[1]; var start = workSheet.Dimension.Start; var end = workSheet.Dimension.End; /* Gets cell values from a row moving left to each column * then moving to the next row. */ for (int row = 2; row <= end.Row; row++) { EtabObject Etabs_Object = new EtabObject(); for (int col = start.Column; col <= end.Column; col++) { object cellValue = workSheet.Cells[row, col].Text; CaseSwitch(col, cellValue, Etabs_Object); } EtabsList.Add(Etabs_Object); } // Close the Excel file. package.Stream.Close(); } catch (Exception ex) { MessageBox.Show("Cannot open " + path + " for reading. Exception raised - " + ex.Message); } return(EtabsList); }
public void changeType(Document doc, RevitObject revitObject, EtabObject etabObject, List <FamilySymbol> structuralTypeList) { string _typeName = etabObject._SectionName; FamilySymbol symbol = structuralTypeList.Find(x => x.Name == etabObject._SectionName); // Check to see if element type exist in the project if (symbol == null) { // if element doesn't exist in project method will try to load family. symbol = loadFamily(doc, etabObject); } // Transaction to change the element type Transaction trans = new Transaction(doc, "Edit Type"); trans.Start(); try { FamilyInstance revitFamilyInstance = revitObject.Get_FamilyInstance(); revitFamilyInstance.Symbol = symbol; } catch { } trans.Commit(); }
public FamilySymbol loadFamily(Document doc, EtabObject etabObject) { string returnFamilyPath; // test to see if Etab object is a column if (etabObject._LabelNumber.Contains("C")) { ColumnDictionary().TryGetValue(etabObject._SectionType, out returnFamilyPath); // Retrive file name from dictionary using the appriviation _family_path = returnFamilyPath; } // test to see if Etab object is a beam if (etabObject._LabelNumber.Contains("B")) { FramingDictionary().TryGetValue(etabObject._SectionType, out returnFamilyPath); // Retrive file name from dictionary using the appriviation _family_path = returnFamilyPath; } FamilySymbol familySymbol = null; // Empty Family Symbol which will return the loaded family // Transaction to load a family and list all its types using (Transaction tx = new Transaction(doc)) { tx.Start("Load Family"); Family family = null; string symbName = null; try { if (doc.LoadFamily(_family_path, new FamilyLoadingOverwriteOption(), out family)) { foreach (ElementId fsids in family.GetFamilySymbolIds()) { ElementType elemtype = doc.GetElement(fsids) as ElementType; FamilySymbol symb = elemtype as FamilySymbol; // test to see if family symbol is the same type as Etabs Object. if (symb.Name == etabObject._SectionName) { symbName = symb.Name; } } } } catch { } tx.RollBack(); // Roll back to only select the type that we want. // Transaction to load the the family type. Transaction transNew = new Transaction(doc, "RealLoading"); transNew.Start(); List <string> notconverted = new List <string>(); try { if (!doc.LoadFamilySymbol(_family_path, symbName, new FamilyLoadingOverwriteOption(), out familySymbol)) { notconverted.Add(symbName); } } catch { } transNew.Commit(); } return(familySymbol); }