private void Button_Click_2(object sender, RoutedEventArgs e) { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; var path = openFileDialog.ShowDialog(); if (openFileDialog.FileName != "") { CarboProject newProject = new CarboProject(); CarboProject buffer = new CarboProject(); newProject = buffer.DeSerializeXML(openFileDialog.FileName); CarboLifeUI.UI.CarboLifeMainWindow CarboApp = new CarboLifeUI.UI.CarboLifeMainWindow(newProject); CarboApp.Show(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Mnu_openDataBase_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Save First?", "Warning", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; var path = openFileDialog.ShowDialog(); if (openFileDialog.FileName != "") { CarboProject newProject = new CarboProject(); CarboProject buffer = new CarboProject(); carboLifeProject = buffer.DeSerializeXML(openFileDialog.FileName); carboLifeProject.Audit(); tab_Main.Visibility = Visibility.Hidden; tab_Main.Visibility = Visibility.Visible; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btn_Open_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Carbo Life Project File (*.clcx)|*.clcx|All files (*.*)|*.*"; var path = openFileDialog.ShowDialog(); if (openFileDialog.FileName != "") { CarboProject newProject = new CarboProject(); CarboProject buffer = new CarboProject(); newProject = buffer.DeSerializeXML(openFileDialog.FileName); newProject.justSaved = true; Dispatcher.BeginInvoke(new Action(() => OpenProject(newProject)), DispatcherPriority.ContextIdle, null); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private CarboProject openNewProject() { CarboProject result = null; try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Carbo Life Project File (*.clcx)|*.clcx|Carbo Life Project File (*.xml)| *.xml|All files (*.*)|*.*"; var path = openFileDialog.ShowDialog(); if (openFileDialog.FileName != "") { CarboProject buffer = new CarboProject(); result = buffer.DeSerializeXML(openFileDialog.FileName); result.Audit(); result.CalculateProject(); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } return(result); }
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); } }
private void Mnu_openDataBase_Click(object sender, RoutedEventArgs e) { bool fileSaved = false; //This bit is a verification code, to make sure the user is given the opportunity to save teh work before continuing: if (carboLifeProject.justSaved == false) { MessageBoxResult result = MessageBox.Show("Do you want to save your project first?", "Warning", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { if (carboLifeProject.filePath == "") { fileSaved = SaveFileAs(); } else { fileSaved = SaveFile(carboLifeProject.filePath); } } else if (result == MessageBoxResult.No) { //The user didnt want to save fileSaved = true; } else { //the user cancels fileSaved = false; } } else { //The file was already saved fileSaved = true; } // //the file is either saved, or used didnt want to save: if (fileSaved == true) { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Carbo Life Project File (*.clcx)|*.clcx|All files (*.*)|*.*"; var path = openFileDialog.ShowDialog(); if (openFileDialog.FileName != "") { CarboProject newProject = new CarboProject(); CarboProject buffer = new CarboProject(); carboLifeProject = buffer.DeSerializeXML(openFileDialog.FileName); carboLifeProject.Audit(); carboLifeProject.CalculateProject(); tab_Main.Visibility = Visibility.Hidden; tab_Main.Visibility = Visibility.Visible; carboLifeProject.justSaved = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }