public List <XTreeNode> CreateProjectTree(string projectId) { List <XTreeNode> projectStructure = new List <XTreeNode>(); try { string modelPath = GetFolderPath(projectId) + projectId + ".ifc"; model = IfcStore.Open(modelPath); IfcBuilding ifcBuilding = model.Instances.OfType <IfcBuilding>().FirstOrDefault(); if (ifcBuilding != null) { building = new XPreviewBuilding(ifcBuilding); IfcProject project = model.Instances.OfType <IfcProject>().FirstOrDefault(); if (project != null) { IfcUtils utils = new IfcUtils(); XTreeNode projectNode = utils.CreateProjectHierarchy(project); if (projectNode != null) { projectStructure.Add(projectNode); } } model.Close(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } return(projectStructure); }
public void Execute(UIApplication app) { doc = app.ActiveUIDocument.Document; try { Dictionary <string, byte[]> ifcData = new Dictionary <string, byte[]>(); foreach (Service service in services) { // Skip creation of ifcData generation when this already exists // (checked by ifcexportconfiguration name of the service) // if (ifcData.ContainsKey(service.IfcExportConfiguration)) { continue; } // Export to IFC according to all used Ifc export configurations IFCExportConfigurationsMapCustom configurationsMap = new IFCExportConfigurationsMapCustom(); foreach (IFCExportConfigurationCustom config in configurationsMap.Values) { if (config.Name.Equals(service.IfcExportConfiguration)) { IFCExportOptions IFCOptions = new IFCExportOptions(); //Get the current view Id, or -1 if you want to export the entire model config.ActiveViewId = -1; //Update the IFCExportOptions config.UpdateOptions(IFCOptions, null); string filename = IfcUtils.ExportProjectToIFC(doc, IFCOptions); ifcData.Add(config.Name, File.ReadAllBytes(filename)); File.Delete(filename); } } } BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += new DoWorkEventHandler(bgWorker_DoWork); bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_Completed); bgw.RunWorkerAsync(new Tuple <Document, Dictionary <string, byte[]> >(doc, ifcData)); } catch (Exception e) { MessageBox.Show("Failed to create IFC data to send to services."); } }