public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Carbo Life Project File (*.clcx)|*.clcx|All files (*.*)|*.*"; var path = openFileDialog.ShowDialog(); if (openFileDialog.FileName != "") { CarboRevitImportSettings importSettings = new CarboRevitImportSettings(); importSettings = importSettings.DeSerializeXML(); //Import the Files CarboLifeRevitImport.ImportElements(app, importSettings, openFileDialog.FileName); } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(Result.Succeeded); }
public CarboRevitImportSettings DeSerializeXML() { string importSettingsPath = PathUtils.getRevitImportSettingspath(); if (File.Exists(importSettingsPath)) { try { XmlSerializer ser = new XmlSerializer(typeof(CarboRevitImportSettings)); CarboRevitImportSettings bufferproject; using (FileStream fs = new FileStream(importSettingsPath, FileMode.Open)) { bufferproject = ser.Deserialize(fs) as CarboRevitImportSettings; } return(bufferproject); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); return(null); } } else { CarboRevitImportSettings newsettings = new CarboRevitImportSettings(); newsettings.SerializeXML(); return(newsettings); } }
public CarboRevitImportSettings DeSerializeXML() { string fileName = "db\\RevitImportSettings.xml"; string myPath = Utils.getAssemblyPath() + "\\" + fileName; if (File.Exists(fileName)) { try { XmlSerializer ser = new XmlSerializer(typeof(CarboRevitImportSettings)); CarboRevitImportSettings bufferproject; using (FileStream fs = new FileStream(myPath, FileMode.Open)) { bufferproject = ser.Deserialize(fs) as CarboRevitImportSettings; } return(bufferproject); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); return(null); } } else { CarboRevitImportSettings newsettings = new CarboRevitImportSettings(); newsettings.SerializeXML(); return(newsettings); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; CarboRevitImportSettings importSettings = new CarboRevitImportSettings(); importSettings = importSettings.DeSerializeXML(); CarboLifeRevitImport.ImportElements(app, importSettings); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; string MyAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string MyAssemblyDir = Path.GetDirectoryName(MyAssemblyPath); CarboProject myProject = new CarboProject(); ICollection <ElementId> selectionList = uidoc.Selection.GetElementIds(); //Get levels List <CarboLevel> levellist = new List <CarboLevel>(); List <Level> levels = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast <Level>().OrderBy(l => l.Elevation).ToList(); foreach (Level lvl in levels) { CarboLevel newlvl = new CarboLevel(); newlvl.Id = lvl.Id.IntegerValue; newlvl.Name = lvl.Name; newlvl.Level = (lvl.Elevation * 304.8); levellist.Add(newlvl); } myProject.carboLevelList = levellist; //Get Settings ImportSettingsWindow importGroupWindow = new ImportSettingsWindow(levellist); importGroupWindow.ShowDialog(); CarboRevitImportSettings importsettings = importGroupWindow.importSettings; if (importGroupWindow.dialogOk == System.Windows.MessageBoxResult.Yes) { //Import the elements } else { return(Result.Succeeded); } //Launch normal Command CarboLifeRevitImport.ImportElements(app, importsettings, ""); return(Result.Succeeded); }
private void SaveSettings() { CarboRevitImportSettings settings = new CarboRevitImportSettings(); settings.MainCategory = cbb_MainGroup.Text; settings.SubCategory = cbb_SecGroup.Text; settings.IncludeDemo = chk_ImportDemolished.IsChecked.Value; settings.CutoffLevel = cbb_Levels.Text; settings.CutoffLevelValue = getCutoffLevel(); settings.IncludeExisting = chk_ImportExisting.IsChecked.Value; settings.SerializeXML(); importSettings = settings; }
private void Window_Loaded(object sender, RoutedEventArgs e) { dialogOk = MessageBoxResult.Cancel; CarboRevitImportSettings settings = new CarboRevitImportSettings(); settings = settings.DeSerializeXML(); importSettings = settings; List <string> categorylist = new List <string>(); categorylist.Add("(Revit) Category"); categorylist.Add("Type Comment"); categorylist.Add("Family Name"); categorylist.Add("Level"); categorylist.Add("CarboLifeCategory"); categorylist.Add(""); foreach (string str in categorylist) { cbb_MainGroup.Items.Add(str); cbb_SecGroup.Items.Add(str); } cbb_MainGroup.Text = "(Revit) Category"; cbb_SecGroup.Text = "Family Name"; //LevelList if (carboLevelList.Count > 0) { foreach (CarboLevel cl in carboLevelList) { cbb_Levels.Items.Add(cl.Name); } cbb_Levels.SelectedIndex = 0; } cbb_MainGroup.Text = settings.MainCategory; cbb_SecGroup.Text = settings.SubCategory; cbb_Levels.Text = settings.CutoffLevel; //txt_SpecialTypes.Text = settings.TypeNameSeparators; chk_ImportDemolished.IsChecked = settings.IncludeDemo; chk_ImportExisting.IsChecked = settings.IncludeExisting; }
public static CarboElement getNewCarboElement(Document doc, Element el, ElementId materialIds, CarboRevitImportSettings settings) { CarboElement newCarboElement = new CarboElement(); try { int setId; string setName; string setImportedMaterialName; string setCategory; string setSubCategory; double setVolume; double setLevel; bool setIsDemolished; bool setIsSubstructure; bool setIsExisting; //int layernr; // Material material = doc.GetElement(materialIds) as Material; //Id: setId = el.Id.IntegerValue; //Name (Type) ElementId elId = el.GetTypeId(); ElementType type = doc.GetElement(elId) as ElementType; setName = type.Name; //MaterialName setImportedMaterialName = doc.GetElement(materialIds).Name.ToString(); //CarboMaterial carboMaterial = new CarboMaterial(setMaterialName); //GetDensity Parameter paramMaterial = el.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM); if (paramMaterial != null) { Material material = doc.GetElement(paramMaterial.AsElementId()) as Material; if (material != null) { PropertySetElement property = doc.GetElement(material.StructuralAssetId) as PropertySetElement; if (property != null) { Parameter paramDensity = property.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_STRUCTURAL_DENSITY); if (paramDensity != null) { double density = paramDensity.AsDouble(); newCarboElement.Density = density; } } } } //Category setCategory = getValueFromList(el, type, settings.MainCategory, doc); //SubCategory setSubCategory = getValueFromList(el, type, settings.SubCategory, doc); //Volume double volumeCubicFt = el.GetMaterialVolume(materialIds); setVolume = Utils.convertToCubicMtrs(volumeCubicFt); newCarboElement.isDemolished = false; Level lvl = doc.GetElement(el.LevelId) as Level; if (lvl != null) { setLevel = Convert.ToDouble((lvl.Elevation) * 304.8); } else { setLevel = 0; } if (setLevel <= settings.CutoffLevelValue) { setIsSubstructure = true; } else { setIsSubstructure = false; } //Get Phasing; Phase elCreatedPhase = doc.GetElement(el.CreatedPhaseId) as Phase; Phase elDemoPhase = doc.GetElement(el.DemolishedPhaseId) as Phase; if (elDemoPhase != null) { setIsDemolished = true; } else { setIsDemolished = false; } if (elCreatedPhase.Name == "Existing") { setIsExisting = true; } else { setIsExisting = false; } //Makepass; //Is existing and retained if (setIsExisting == true && setIsDemolished == false) { if (settings.IncludeExisting == false) { return(null); } } //Is demolished if (setIsDemolished == true) { if (settings.IncludeDemo == false) { return(null); } } //If it passed it is either proposed, or demolished and retained. newCarboElement.Id = setId; newCarboElement.Name = setName; newCarboElement.MaterialName = setImportedMaterialName; newCarboElement.Category = setCategory; newCarboElement.SubCategory = setSubCategory; newCarboElement.Volume = Math.Round(setVolume, 4); //newCarboElement.Material = carboMaterial; //Material removed newCarboElement.Level = Math.Round(setLevel, 3); newCarboElement.isDemolished = setIsDemolished; newCarboElement.isExisting = setIsExisting; newCarboElement.isSubstructure = setIsSubstructure; if (newCarboElement.Volume != 0) { return(newCarboElement); } else { return(null); } } catch { //TaskDialog.Show("Error", ex.Message); return(null); } }
public static void ImportElements(UIApplication app, CarboRevitImportSettings settings, string updatePath) { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; string MyAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string MyAssemblyDir = Path.GetDirectoryName(MyAssemblyPath); bool updateFile = false; if (File.Exists(updatePath)) { updateFile = true; } //Create a new project CarboProject myProject = new CarboProject(); myProject.Name = doc.ProjectInformation.Name.Trim(); myProject.Number = doc.ProjectInformation.Number; ICollection <ElementId> selectionList = uidoc.Selection.GetElementIds(); double area = 0; #region buildQuantitiestable if (selectionList.Count == 0) { //No elements are selected, all elements will be parsed View activeView = doc.ActiveView; FilteredElementCollector coll = new FilteredElementCollector(app.ActiveUIDocument.Document, activeView.Id); coll.WherePasses(new LogicalOrFilter(new ElementIsElementTypeFilter(false), new ElementIsElementTypeFilter(true))); //Now cast them as elements into a container IList <Element> collection = coll.ToElements(); string name = ""; List <string> IdsNotFound = new List <string>(); foreach (Element el in collection) { name = el.Id.ToString(); try { if (CarboRevitUtils.isElementReal(el) == true) { ICollection <ElementId> MaterialIds = el.GetMaterialIds(false); foreach (ElementId materialIds in MaterialIds) { CarboElement carboElement = CarboRevitUtils.getNewCarboElement(doc, el, materialIds, settings); if (carboElement != null) { myProject.AddElement(carboElement); } } //See if is floor(then count area) area += getFloorarea(el); } } catch { IdsNotFound.Add(name); //TaskDialog.Show("Error", ex.Message); } } if (IdsNotFound.Count > 0) { string message = "One or more elements weren't processed, most likely because they didn't contain any volume the element ids of these elements are: "; foreach (string id in IdsNotFound) { message += "\n" + id; } MessageBox.Show(message, "Warning", MessageBoxButton.OK); } } else { try { foreach (ElementId elid in selectionList) { Element el = doc.GetElement(elid); ICollection <ElementId> MaterialIds = el.GetMaterialIds(false); if (CarboRevitUtils.isElementReal(el) == true) { foreach (ElementId materialIds in MaterialIds) { CarboElement carboElement = CarboRevitUtils.getNewCarboElement(doc, el, materialIds, settings); if (carboElement != null) { myProject.AddElement(carboElement); } } //See if is floor(then count area) area += getFloorarea(el); } } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } } #endregion //All element have been mapped, here the code will be split between an update or a new one. if (myProject.getAllElements.Count > 0) { CarboProject projectToOpen = new CarboProject(); if (updateFile == false) { //Create groups from all the individual elements myProject.CreateGroups(); projectToOpen = myProject; } else //upadte an existing file: { CarboProject projectToUpdate = new CarboProject(); CarboProject buffer = new CarboProject(); projectToUpdate = buffer.DeSerializeXML(updatePath); projectToUpdate.Audit(); projectToUpdate.UpdateProject(myProject); projectToUpdate.CalculateProject(); projectToOpen = projectToUpdate; } double areaMSqr = Math.Round((area * (0.3048 * 0.3048)), 2); projectToOpen.Area = areaMSqr; CarboLifeMainWindow carboCalcProgram = new CarboLifeMainWindow(projectToOpen); carboCalcProgram.IsRevit = true; AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); carboCalcProgram.ShowDialog(); //Create a visual if (carboCalcProgram.createHeatmap == true) { CreateHeatMap(app, carboCalcProgram.carboLifeProject); } } else { MessageBox.Show("No elements could be found to be calculated, please make sure you have a 3D view active and the building volume is clearly visible ", "Warning", MessageBoxButton.OK); } //When assembly cant be find bind to current System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { System.Reflection.Assembly ayResult = null; string sShortAssemblyName = args.Name.Split(',')[0]; System.Reflection.Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (System.Reflection.Assembly ayAssembly in ayAssemblies) { if (sShortAssemblyName == ayAssembly.FullName.Split(',')[0]) { ayResult = ayAssembly; break; } } return(ayResult); } }
public static void ImportElements(UIApplication app, CarboRevitImportSettings settings) { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; string MyAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string MyAssemblyDir = Path.GetDirectoryName(MyAssemblyPath); CarboProject myProject = new CarboProject(); myProject.Name = doc.ProjectInformation.Name.Trim(); myProject.Number = doc.ProjectInformation.Number; ICollection <ElementId> selectionList = uidoc.Selection.GetElementIds(); double area = 0; #region buildQuantitiestable if (selectionList.Count == 0) { //No elements are selected: View activeView = doc.ActiveView; FilteredElementCollector coll = new FilteredElementCollector(app.ActiveUIDocument.Document, activeView.Id); coll.WherePasses(new LogicalOrFilter(new ElementIsElementTypeFilter(false), new ElementIsElementTypeFilter(true))); //Now cast them as elements into a container IList <Element> collection = coll.ToElements(); try { foreach (Element el in collection) { if (CarboRevitUtils.isElementReal(el) == true) { ICollection <ElementId> MaterialIds = el.GetMaterialIds(false); foreach (ElementId materialIds in MaterialIds) { CarboElement carboElement = CarboRevitUtils.getNewCarboElement(doc, el, materialIds, settings); if (carboElement != null) { myProject.AddElement(carboElement); } } } //See if is floor(then count area) area += getFloorarea(el); } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } } else { try { foreach (ElementId elid in selectionList) { Element el = doc.GetElement(elid); ICollection <ElementId> MaterialIds = el.GetMaterialIds(false); if (CarboRevitUtils.isElementReal(el) == true) { foreach (ElementId materialIds in MaterialIds) { CarboElement carboElement = CarboRevitUtils.getNewCarboElement(doc, el, materialIds, settings); } //See if is floor(then count area) area += getFloorarea(el); } } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } } #endregion if (myProject.getAllElements.Count > 0) { myProject.CreateGroups(); double areaMSqr = Math.Round((area * (0.3048 * 0.3048)), 2); myProject.Area = areaMSqr; CarboLifeMainWindow carboCalcProgram = new CarboLifeMainWindow(myProject); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); carboCalcProgram.ShowDialog(); } //When assembly cant be find bind to current System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { System.Reflection.Assembly ayResult = null; string sShortAssemblyName = args.Name.Split(',')[0]; System.Reflection.Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (System.Reflection.Assembly ayAssembly in ayAssemblies) { if (sShortAssemblyName == ayAssembly.FullName.Split(',')[0]) { ayResult = ayAssembly; break; } } return(ayResult); } }