/// <summary> /// Updates the IFCExportOptions with the settings in this configuration. /// </summary> /// <param name="uidoc">UIDocument from which the options are created (some settings are document dependent)</param> /// <param name="options">The IFCExportOptions to update.</param> /// <param name="filterViewId">The id of the view that will be used to select which elements to export.</param> internal void UpdateOptions(ElementId filterViewId, Document doc, ref IFCExportOptions options) { if (null == options || null == doc || null == options) { return; } options.FileVersion = IFCFVersion; options.SpaceBoundaryLevel = SpaceBoundaries; options.ExportBaseQuantities = ExportBaseQuantities; options.WallAndColumnSplitting = SplitWallsAndColumns; options.FilterViewId = VisibleElementsOfCurrentView ? filterViewId : ElementId.InvalidElementId; options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString()); options.AddOption("ExportIFCCommonPropertySets", ExportIFCCommonPropertySets.ToString()); options.AddOption("ExportAnnotations", Export2DElements.ToString()); options.AddOption("Use2DRoomBoundaryForVolume", Use2DRoomBoundaryForVolume.ToString()); options.AddOption("UseFamilyAndTypeNameForReference", UseFamilyAndTypeNameForReference.ToString()); options.AddOption("ExportVisibleElementsInView", VisibleElementsOfCurrentView.ToString()); options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString()); options.AddOption("UseActiveViewGeometry", UseActiveViewGeometry.ToString()); options.AddOption("ExportSpecificSchedules", ExportSpecificSchedules.ToString()); options.AddOption("ExportBoundingBox", ExportBoundingBox.ToString()); options.AddOption("ExportSolidModelRep", ExportSolidModelRep.ToString()); options.AddOption("ExportSchedulesAsPsets", ExportSchedulesAsPsets.ToString()); options.AddOption("ExportUserDefinedPsets", ExportUserDefinedPsets.ToString()); options.AddOption("ExportUserDefinedParameterMapping", ExportUserDefinedParameterMapping.ToString()); options.AddOption("ExportLinkedFiles", ExportLinkedFiles.ToString()); options.AddOption("IncludeSiteElevation", IncludeSiteElevation.ToString()); options.AddOption("TessellationLevelOfDetail", TessellationLevelOfDetail.ToString(CultureInfo.InvariantCulture)); options.AddOption("ActiveViewId", ActiveViewId.ToString()); options.AddOption("StoreIFCGUID", StoreIFCGUID.ToString()); // The active phase may not be valid if we are exporting multiple projects. However, if projects share a template that defines the phases, // then the ActivePhaseId would likely be valid for all. There is some small chance that the ActivePhaseId would be a valid, but different, phase // in different projects, but that is unlikely enough that it seems worth warning against it but allowing the better functionality in general. if (ValidatePhase(ActivePhaseId, doc)) { options.AddOption("ActivePhase", ActivePhaseId.ToString()); } options.AddOption("FileType", IFCFileType.ToString()); //string uiVersion = IFCUISettings.GetAssemblyVersion(); //options.AddOption("AlternateUIVersion", uiVersion); options.AddOption("ConfigName", Name); // Add config name into the option for use in the exporter options.AddOption("ExportUserDefinedPsetsFileName", ExportUserDefinedPsetsFileName); options.AddOption("ExportUserDefinedParameterMappingFileName", ExportUserDefinedParameterMappingFileName); options.AddOption("ExportRoomsInView", ExportRoomsInView.ToString()); }
public void Execute(UIApplication uiapp) { try { ICollection <ElementId> elementIds = uiapp.ActiveUIDocument.Selection.GetElementIds(); string path = Path.GetTempPath(); Document document = uiapp.ActiveUIDocument.Document; if (elementIds.Count == 0) { mBrowser.mPropertyGrid.SelectedObject = null; return; } string ids = string.Join(";", elementIds.ToList().ConvertAll(x => x.ToString())); IFCExportOptions options = new IFCExportOptions(); options.AddOption("ElementsForExport", ids); string fileName = Path.GetFileNameWithoutExtension(document.PathName) + ".ifc"; Transaction transaction = new Transaction(document, "Export IFC"); transaction.Start(); document.Export(path, fileName, options); transaction.RollBack(); DatabaseIfc db = new DatabaseIfc(Path.Combine(path, fileName)); List <IfcElement> elements = db.Context.Extract <IfcElement>(); IEnumerable <object> properties = elements.ConvertAll(x => new ObjectIfcProperties(x)); mBrowser.mPropertyGrid.SelectedObjects = properties.ToArray(); } finally { } return; }
public void Execute(UIApplication uiapp) { try { ICollection <ElementId> elementIds = uiapp.ActiveUIDocument.Selection.GetElementIds(); string path = Path.GetTempPath(); Document document = uiapp.ActiveUIDocument.Document; if (document.IsFamilyDocument || elementIds.Count == 0) { mBrowser.mBrowserControl.propertyGrid.SelectedObject = null; return; } string ids = string.Join(";", elementIds.ToList().ConvertAll(x => x.ToString())); IFCExportOptions options = new IFCExportOptions(); options.AddOption("ElementsForExport", ids); string fileName = Path.GetFileNameWithoutExtension(document.PathName) + ".ifc"; Transaction transaction = new Transaction(document, "Export IFC"); transaction.Start(); document.Export(path, fileName, options); transaction.RollBack(); DatabaseIfc db = new DatabaseIfc(Path.Combine(path, fileName)); List <IfcElement> elements = db.Context.Extract <IfcElement>(); if (elements.Count > 0) { IEnumerable <object> properties = elements.ConvertAll(x => new ElementIfcProperties(x)); IfcElementType type = elements[0].RelatingType as IfcElementType; if (type != null) { foreach (IfcElement e in elements) { IfcElementType t = e.RelatingType as IfcElementType; if (t == null || type.Index != t.Index) { type = null; break; } } } mBrowser.mBrowserControl.propertyGrid.SelectedObjects = properties.ToArray(); mBrowser.mBrowserControl.ElementType = type; } } finally { } return; }
/// <summary> /// Updates the IFCExportOptions with the settings in this configuration. /// </summary> /// <param name="options">The IFCExportOptions to update.</param> /// <param name="filterViewId">The filter view.</param> public void UpdateOptions(IFCExportOptions options, ElementId filterViewId) { options.FileVersion = IFCVersion; options.SpaceBoundaryLevel = SpaceBoundaries; options.ExportBaseQuantities = ExportBaseQuantities; options.WallAndColumnSplitting = SplitWallsAndColumns; if (VisibleElementsOfCurrentView) { options.FilterViewId = filterViewId; } else { options.FilterViewId = ElementId.InvalidElementId; } options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString()); options.AddOption("ExportAnnotations", Export2DElements.ToString()); options.AddOption("Use2DRoomBoundaryForVolume", Use2DRoomBoundaryForVolume.ToString()); options.AddOption("UseFamilyAndTypeNameForReference", UseFamilyAndTypeNameForReference.ToString()); options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString()); options.AddOption("FileType", IFCFileType.ToString()); }
public void ExportLinkedDocuments(Autodesk.Revit.DB.Document document, string fileName, Dictionary <ElementId, string> linksGUIDsCache, IFCExportOptions exportOptions) { // get the extension int index = fileName.LastIndexOf('.'); if (index <= 0) { return; } string sExtension = fileName.Substring(index); fileName = fileName.Substring(0, index); // get all the revit link instances FilteredElementCollector collector = new FilteredElementCollector(document); ElementFilter elementFilter = new ElementClassFilter(typeof(RevitLinkInstance)); List <RevitLinkInstance> rvtLinkInstances = collector.WherePasses(elementFilter).Cast <RevitLinkInstance>().ToList(); IDictionary <String, int> rvtLinkNamesDict = new Dictionary <String, int>(); IDictionary <String, List <RevitLinkInstance> > rvtLinkNamesToInstancesDict = new Dictionary <String, List <RevitLinkInstance> >(); try { // get the link types foreach (RevitLinkInstance rvtLinkInstance in rvtLinkInstances) { // get the instance if (rvtLinkInstance == null) { continue; } // check the cache if (linksGUIDsCache.Keys.Contains(rvtLinkInstance.Id) == false) { continue; } // get the link document Document linkDocument = rvtLinkInstance.GetLinkDocument(); if (linkDocument == null) { continue; } // get the link file path and name String linkPathName = ""; Parameter originalFileNameParam = linkDocument.ProjectInformation.get_Parameter("Original IFC File Name"); if (originalFileNameParam != null && originalFileNameParam.StorageType == StorageType.String) { linkPathName = originalFileNameParam.AsString(); } else { linkPathName = linkDocument.PathName; } // get the link file name String linkFileName = ""; index = linkPathName.LastIndexOf("\\"); if (index > 0) { linkFileName = linkPathName.Substring(index + 1); } else { linkFileName = linkDocument.Title; } // remove the extension index = linkFileName.LastIndexOf('.'); if (index > 0) { linkFileName = linkFileName.Substring(0, index); } // add to names count dictionary if (!rvtLinkNamesDict.Keys.Contains(linkFileName)) { rvtLinkNamesDict.Add(linkFileName, 0); } rvtLinkNamesDict[linkFileName]++; // add to names instances dictionary if (!rvtLinkNamesToInstancesDict.Keys.Contains(linkPathName)) { rvtLinkNamesToInstancesDict.Add(linkPathName, new List <RevitLinkInstance>()); } rvtLinkNamesToInstancesDict[linkPathName].Add(rvtLinkInstance); } } catch { } // get the link instances // We will keep track of the instances we can't export. // Reasons we can't export: // 1. The path for the linked instance doesn't exist. // 2. Couldn't create a temporary document for exporting the linked instance. // 3. The document for the linked instance can't be found. // 4. The linked instance is mirrored, non-conformal, or scaled. IList <string> pathDoesntExist = new List <string>(); IList <string> noTempDoc = new List <string>(); IList <ElementId> cantFindDoc = new List <ElementId>(); IList <ElementId> nonConformalInst = new List <ElementId>(); IList <ElementId> scaledInst = new List <ElementId>(); IList <ElementId> instHasReflection = new List <ElementId>(); foreach (String linkPathName in rvtLinkNamesToInstancesDict.Keys) { // get the name of the copy String linkPathNameCopy = System.IO.Path.GetTempPath(); index = linkPathName.LastIndexOf("\\"); if (index > 0) { linkPathNameCopy += linkPathName.Substring(index + 1); } else { linkPathNameCopy += linkPathName; } index = linkPathNameCopy.LastIndexOf('.'); if (index <= 0) { index = linkPathNameCopy.Length; } linkPathNameCopy = linkPathNameCopy.Insert(index, " - Copy"); int i = 1; while (File.Exists(linkPathNameCopy)) { linkPathNameCopy = linkPathNameCopy.Insert(index, "(" + (++i).ToString() + ")"); } // copy the file File.Copy(linkPathName, linkPathNameCopy); if (!File.Exists(linkPathNameCopy)) { pathDoesntExist.Add(linkPathName); continue; } // open the document Document documentCopy = null; try { if ((linkPathName.Length >= 4 && linkPathName.Substring(linkPathName.Length - 4).ToLower() == ".ifc") || (linkPathName.Length >= 7 && linkPathName.Substring(linkPathName.Length - 7).ToLower() == ".ifcxml") || (linkPathName.Length >= 7 && linkPathName.Substring(linkPathName.Length - 7).ToLower() == ".ifczip")) { documentCopy = document.Application.OpenIFCDocument(linkPathNameCopy); } else { documentCopy = document.Application.OpenDocumentFile(linkPathNameCopy); } } catch { documentCopy = null; } if (documentCopy == null) { noTempDoc.Add(linkPathName); continue; } // get the link document unit scale DisplayUnitType dutLink = documentCopy.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits; double lengthScaleFactorLink = UnitUtils.ConvertFromInternalUnits(1.0, dutLink); // get the link instances List <RevitLinkInstance> currRvtLinkInstances = rvtLinkNamesToInstancesDict[linkPathName]; IList <string> serTransforms = new List <string>(); IList <string> linkFileNames = new List <string>(); foreach (RevitLinkInstance currRvtLinkInstance in currRvtLinkInstances) { // Nothing to report if the element itself is null. if (currRvtLinkInstance == null) { continue; } // get the link document Document linkDocument = currRvtLinkInstance.GetLinkDocument(); if (linkDocument == null) { cantFindDoc.Add(currRvtLinkInstance.Id); continue; } // get the link transform Transform tr = currRvtLinkInstance.GetTransform(); // We can't handle non-conformal, scaled, or mirrored transforms. if (!tr.IsConformal) { nonConformalInst.Add(currRvtLinkInstance.Id); continue; } if (tr.HasReflection) { instHasReflection.Add(currRvtLinkInstance.Id); continue; } if (!MathUtil.IsAlmostEqual(tr.Determinant, 1.0)) { scaledInst.Add(currRvtLinkInstance.Id); continue; } // get the link file path and name String linkFileName = ""; index = linkPathName.LastIndexOf("\\"); if (index > 0) { linkFileName = linkPathName.Substring(index + 1); } else { linkFileName = linkDocument.Title; } // remove the extension index = linkFileName.LastIndexOf('.'); if (index > 0) { linkFileName = linkFileName.Substring(0, index); } //if link was an IFC file then make a different formating to the file name if ((linkPathName.Length >= 4 && linkPathName.Substring(linkPathName.Length - 4).ToLower() == ".ifc") || (linkPathName.Length >= 7 && linkPathName.Substring(linkPathName.Length - 7).ToLower() == ".ifcxml") || (linkPathName.Length >= 7 && linkPathName.Substring(linkPathName.Length - 7).ToLower() == ".ifczip")) { String fName = fileName; //get output path and add to the new file name index = fName.LastIndexOf("\\"); if (index > 0) { fName = fName.Substring(0, index + 1); } else { fName = ""; } //construct IFC file name linkFileName = fName + linkFileName + "-"; //add guid linkFileName += linksGUIDsCache[currRvtLinkInstance.Id]; } else { // check if there are multiple instances with the same name bool bMultiple = (rvtLinkNamesDict[linkFileName] > 1); // add the path linkFileName = fileName + "-" + linkFileName; // add the guid if (bMultiple) { linkFileName += "-"; linkFileName += linksGUIDsCache[currRvtLinkInstance.Id]; } } // add the extension linkFileName += sExtension; linkFileNames.Add(linkFileName); // scale the transform origin tr.Origin *= lengthScaleFactorLink; // serialize transform serTransforms.Add(SerializeTransform(tr)); } // IFC export requires an open transaction, although no changes should be made Transaction transaction = new Transaction(documentCopy, "Export IFC Link"); transaction.Start(); FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions(); failureOptions.SetClearAfterRollback(false); transaction.SetFailureHandlingOptions(failureOptions); // export try { int numLinkInstancesToExport = linkFileNames.Count; exportOptions.AddOption("NumberOfExportedLinkInstances", numLinkInstancesToExport.ToString()); for (int ii = 0; ii < numLinkInstancesToExport; ii++) { string optionName = (ii == 0) ? "ExportLinkInstanceTransform" : "ExportLinkInstanceTransform" + (ii + 1).ToString(); exportOptions.AddOption(optionName, serTransforms[ii]); // Don't pass in file name for the first link instance. if (ii == 0) { continue; } optionName = "ExportLinkInstanceFileName" + (ii + 1).ToString(); exportOptions.AddOption(optionName, linkFileNames[ii]); } // Pass in the first value; the rest will be in the options. String path_ = Path.GetDirectoryName(linkFileNames[0]); String fileName_ = Path.GetFileName(linkFileNames[0]); bool result = documentCopy.Export(path_, fileName_, exportOptions); // pass in the options here } catch { } // rollback the transaction transaction.RollBack(); // close the document documentCopy.Close(false); // delete the copy try { File.Delete(linkPathNameCopy); } catch { } // Show user errors, if any. int numBadInstances = pathDoesntExist.Count + noTempDoc.Count + cantFindDoc.Count + nonConformalInst.Count + scaledInst.Count + instHasReflection.Count; if (numBadInstances > 0) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = string.Format(Properties.Resources.LinkInstanceExportErrorMain, numBadInstances); taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; taskDialog.TitleAutoPrefix = false; string expandedContent = ""; AddExpandedStringContent(ref expandedContent, Properties.Resources.LinkInstanceExportErrorPath, pathDoesntExist); AddExpandedStringContent(ref expandedContent, Properties.Resources.LinkInstanceExportCantCreateDoc, noTempDoc); AddExpandedElementIdContent(ref expandedContent, Properties.Resources.LinkInstanceExportCantFindDoc, cantFindDoc); AddExpandedElementIdContent(ref expandedContent, Properties.Resources.LinkInstanceExportNonConformal, nonConformalInst); AddExpandedElementIdContent(ref expandedContent, Properties.Resources.LinkInstanceExportScaled, scaledInst); AddExpandedElementIdContent(ref expandedContent, Properties.Resources.LinkInstanceExportHasReflection, instHasReflection); taskDialog.ExpandedContent = expandedContent; TaskDialogResult result = taskDialog.Show(); } } } }
/// <summary> /// Implementation of the command binding event for the IFC export command. /// </summary> /// <param name="sender">The event sender (Revit UIApplication).</param> /// <param name="args">The arguments (command binding).</param> public void OnIFCExport(object sender, CommandEventArgs args) { try { // Prepare basic objects UIApplication uiApp = sender as UIApplication; UIDocument uiDoc = uiApp.ActiveUIDocument; Document doc = uiDoc.Document; TheDocument = doc; IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap(); configurationsMap.Add(IFCExportConfiguration.GetInSession()); configurationsMap.AddBuiltInConfigurations(); configurationsMap.AddSavedConfigurations(); String mruSelection = null; if (m_mruConfiguration != null && configurationsMap.HasName(m_mruConfiguration)) { mruSelection = m_mruConfiguration; } PotentiallyUpdatedConfigurations = false; IFCExport mainWindow = new IFCExport(doc, configurationsMap, mruSelection); mainWindow.ShowDialog(); // If user chose to continue if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings) { // change options IFCExportConfiguration selectedConfig = mainWindow.GetSelectedConfiguration(); // Prepare the export options IFCExportOptions exportOptions = new IFCExportOptions(); selectedConfig.UpdateOptions(exportOptions, uiDoc.ActiveView.Id); // prompt for the file name SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.AddExtension = true; String defaultDirectory = m_mruExportPath != null ? m_mruExportPath : null; if (defaultDirectory == null) { String revitFilePath = doc.PathName; if (!String.IsNullOrEmpty(revitFilePath)) { defaultDirectory = Path.GetDirectoryName(revitFilePath); } } if (defaultDirectory == null) { defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } String defaultFileName = doc.Title; if (String.IsNullOrEmpty(defaultFileName)) { defaultFileName = "Project"; } else { defaultFileName = Path.GetFileNameWithoutExtension(defaultFileName); } String defaultExtension = mainWindow.GetFileExtension(); fileDialog.FileName = defaultFileName; fileDialog.DefaultExt = defaultExtension; fileDialog.Filter = mainWindow.GetFileFilter(); fileDialog.InitialDirectory = defaultDirectory; bool?fileDialogResult = fileDialog.ShowDialog(); // If user chose to continue if (fileDialogResult.HasValue && fileDialogResult.Value) { // Prompt the user for the file location and path String fullName = fileDialog.FileName; String path = Path.GetDirectoryName(fullName); String fileName = Path.GetFileName(fullName); // Call this before the Export IFC transaction starts, as it has its own transaction. IFCClassificationMgr.DeleteObsoleteSchemas(doc); // IFC export requires an open transaction, although no changes should be made Transaction transaction = new Transaction(doc, "Export IFC"); transaction.Start(); FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions(); failureOptions.SetClearAfterRollback(false); transaction.SetFailureHandlingOptions(failureOptions); // There is no UI option for this, but these two options can be useful for debugging/investigating // issues in specific file export. The first one supports export of only one element //exportOptions.AddOption("SingleElement", "174245"); // The second one supports export only of a list of elements //exportOptions.AddOption("ElementsForExport", "174245;205427"); bool result = doc.Export(path, fileName, exportOptions); // pass in the options here if (!result) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = Properties.Resources.IFCExportProcessError; taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; TaskDialogResult taskDialogResult = taskDialog.Show(); } } // This option should be rarely used, and is only for consistency with old files. As such, it is set by environment variable only. String use2009GUID = Environment.GetEnvironmentVariable("Assign2009GUIDToBuildingStoriesOnIFCExport"); bool use2009BuildingStoreyGUIDs = (use2009GUID != null && use2009GUID == "1"); // Cache for links guids Dictionary <ElementId, string> linksGUIDsCache = new Dictionary <ElementId, string>(); if (selectedConfig.ExportLinkedFiles == true) { Autodesk.Revit.DB.FilteredElementCollector collector = new FilteredElementCollector(doc); collector.WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_RvtLinks); System.Collections.Generic.ICollection <ElementId> rvtLinkInstanceIds = collector.ToElementIds(); foreach (ElementId linkId in rvtLinkInstanceIds) { Element linkInstance = doc.GetElement(linkId); if (linkInstance == null) { continue; } Parameter parameter = linkInstance.get_Parameter(BuiltInParameter.IFC_GUID); if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.String) { String sGUID = parameter.AsString(), sGUIDlower = sGUID.ToLower(); foreach (KeyValuePair <ElementId, string> value in linksGUIDsCache) { if (value.Value.ToLower().IndexOf(sGUIDlower) == 0) { sGUID += "-"; } } linksGUIDsCache.Add(linkInstance.Id, sGUID); } } } // Roll back the transaction started earlier, unless certain options are set. if (use2009BuildingStoreyGUIDs || selectedConfig.StoreIFCGUID) { transaction.Commit(); } else { transaction.RollBack(); } // Export links if (selectedConfig.ExportLinkedFiles == true) { exportOptions.AddOption("ExportingLinks", true.ToString()); ExportLinkedDocuments(doc, fullName, linksGUIDsCache, exportOptions); exportOptions.AddOption("ExportingLinks", false.ToString()); } // Remember last successful export location m_mruExportPath = path; } } // The cancel button should cancel the export, not any "OK"ed setup changes. if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings || mainWindow.Result == IFCExportResult.Cancel) { if (PotentiallyUpdatedConfigurations) { configurationsMap = mainWindow.GetModifiedConfigurations(); configurationsMap.UpdateSavedConfigurations(); } // Remember last selected configuration m_mruConfiguration = mainWindow.GetSelectedConfiguration().Name; } } catch (Exception e) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = Properties.Resources.IFCExportProcessError; taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; taskDialog.ExpandedContent = e.ToString(); TaskDialogResult result = taskDialog.Show(); } } }
public void ExportLinkedDocuments(Autodesk.Revit.DB.Document document, string fileName, Dictionary<ElementId, string> linksGUIDsCache, IFCExportOptions exportOptions) { // get the extension int index = fileName.LastIndexOf('.'); if (index <= 0) return; string sExtension = fileName.Substring(index); fileName = fileName.Substring(0, index); // get all the revit link instances FilteredElementCollector collector = new FilteredElementCollector(document); ElementFilter elementFilter = new ElementClassFilter(typeof(RevitLinkInstance)); List<RevitLinkInstance> rvtLinkInstances = collector.WherePasses(elementFilter).Cast<RevitLinkInstance>().ToList(); IDictionary<String, int> rvtLinkNamesDict = new Dictionary<String, int>(); IDictionary<String, List<RevitLinkInstance>> rvtLinkNamesToInstancesDict = new Dictionary<String, List<RevitLinkInstance>>(); try { // get the link types foreach (RevitLinkInstance rvtLinkInstance in rvtLinkInstances) { // get the instance if (rvtLinkInstance == null) continue; // check the cache if (linksGUIDsCache.Keys.Contains(rvtLinkInstance.Id) == false) continue; // get the link document Document linkDocument = rvtLinkInstance.GetLinkDocument(); if (linkDocument == null) continue; // get the link file path and name String linkPathName = ""; Parameter originalFileNameParam = linkDocument.ProjectInformation.LookupParameter("Original IFC File Name"); if (originalFileNameParam != null && originalFileNameParam.StorageType == StorageType.String) linkPathName = originalFileNameParam.AsString(); else linkPathName = linkDocument.PathName; // get the link file name String linkFileName = ""; index = linkPathName.LastIndexOf("\\"); if (index > 0) linkFileName = linkPathName.Substring(index + 1); else linkFileName = linkDocument.Title; // remove the extension index = linkFileName.LastIndexOf('.'); if (index > 0) linkFileName = linkFileName.Substring(0, index); // add to names count dictionary if (!rvtLinkNamesDict.Keys.Contains(linkFileName)) rvtLinkNamesDict.Add(linkFileName, 0); rvtLinkNamesDict[linkFileName]++; // add to names instances dictionary if (!rvtLinkNamesToInstancesDict.Keys.Contains(linkPathName)) rvtLinkNamesToInstancesDict.Add(linkPathName, new List<RevitLinkInstance>()); rvtLinkNamesToInstancesDict[linkPathName].Add(rvtLinkInstance); } } catch { } // get the link instances // We will keep track of the instances we can't export. // Reasons we can't export: // 1. The path for the linked instance doesn't exist. // 2. Couldn't create a temporary document for exporting the linked instance. // 3. The document for the linked instance can't be found. // 4. The linked instance is mirrored, non-conformal, or scaled. IList<string> pathDoesntExist = new List<string>(); IList<string> noTempDoc = new List<string>(); IList<ElementId> cantFindDoc = new List<ElementId>(); IList<ElementId> nonConformalInst = new List<ElementId>(); IList<ElementId> scaledInst = new List<ElementId>(); IList<ElementId> instHasReflection = new List<ElementId>(); foreach (String linkPathName in rvtLinkNamesToInstancesDict.Keys) { // get the name of the copy String linkPathNameCopy = System.IO.Path.GetTempPath(); index = linkPathName.LastIndexOf("\\"); if (index > 0) linkPathNameCopy += linkPathName.Substring(index + 1); else linkPathNameCopy += linkPathName; index = linkPathNameCopy.LastIndexOf('.'); if (index <= 0) index = linkPathNameCopy.Length; linkPathNameCopy = linkPathNameCopy.Insert(index, " - Copy"); int i = 1; while (File.Exists(linkPathNameCopy)) linkPathNameCopy = linkPathNameCopy.Insert(index, "(" + (++i).ToString() + ")"); // copy the file File.Copy(linkPathName, linkPathNameCopy); if (!File.Exists(linkPathNameCopy)) { pathDoesntExist.Add(linkPathName); continue; } // open the document Document documentCopy = null; try { if ((linkPathName.Length >= 4 && linkPathName.Substring(linkPathName.Length - 4).ToLower() == ".ifc") || (linkPathName.Length >= 7 && linkPathName.Substring(linkPathName.Length - 7).ToLower() == ".ifcxml") || (linkPathName.Length >= 7 && linkPathName.Substring(linkPathName.Length - 7).ToLower() == ".ifczip")) documentCopy = document.Application.OpenIFCDocument(linkPathNameCopy); else documentCopy = document.Application.OpenDocumentFile(linkPathNameCopy); } catch { documentCopy = null; } if (documentCopy == null) { noTempDoc.Add(linkPathName); continue; } // get the link document unit scale DisplayUnitType dutLink = documentCopy.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits; double lengthScaleFactorLink = UnitUtils.ConvertFromInternalUnits(1.0, dutLink); // get the link instances List<RevitLinkInstance> currRvtLinkInstances = rvtLinkNamesToInstancesDict[linkPathName]; IList<string> serTransforms = new List<string>(); IList<string> linkFileNames = new List<string>(); foreach (RevitLinkInstance currRvtLinkInstance in currRvtLinkInstances) { // Nothing to report if the element itself is null. if (currRvtLinkInstance == null) continue; // get the link document Document linkDocument = currRvtLinkInstance.GetLinkDocument(); if (linkDocument == null) { cantFindDoc.Add(currRvtLinkInstance.Id); continue; } // get the link transform Transform tr = currRvtLinkInstance.GetTransform(); // We can't handle non-conformal, scaled, or mirrored transforms. if (!tr.IsConformal) { nonConformalInst.Add(currRvtLinkInstance.Id); continue; } if (tr.HasReflection) { instHasReflection.Add(currRvtLinkInstance.Id); continue; } if (!MathUtil.IsAlmostEqual(tr.Determinant, 1.0)) { scaledInst.Add(currRvtLinkInstance.Id); continue; } // get the link file path and name String linkFileName = ""; index = linkPathName.LastIndexOf("\\"); if (index > 0) linkFileName = linkPathName.Substring(index + 1); else linkFileName = linkDocument.Title; // remove the extension index = linkFileName.LastIndexOf('.'); if (index > 0) linkFileName = linkFileName.Substring(0, index); //if link was an IFC file then make a different formating to the file name if ((linkPathName.Length >= 4 && linkPathName.Substring(linkPathName.Length - 4).ToLower() == ".ifc") || (linkPathName.Length >= 7 && linkPathName.Substring(linkPathName.Length - 7).ToLower() == ".ifcxml") || (linkPathName.Length >= 7 && linkPathName.Substring(linkPathName.Length - 7).ToLower() == ".ifczip")) { String fName = fileName; //get output path and add to the new file name index = fName.LastIndexOf("\\"); if (index > 0) fName = fName.Substring(0, index + 1); else fName = ""; //construct IFC file name linkFileName = fName + linkFileName + "-"; //add guid linkFileName += linksGUIDsCache[currRvtLinkInstance.Id]; } else { // check if there are multiple instances with the same name bool bMultiple = (rvtLinkNamesDict[linkFileName] > 1); // add the path linkFileName = fileName + "-" + linkFileName; // add the guid if (bMultiple) { linkFileName += "-"; linkFileName += linksGUIDsCache[currRvtLinkInstance.Id]; } } // add the extension linkFileName += sExtension; linkFileNames.Add(linkFileName); // scale the transform origin tr.Origin *= lengthScaleFactorLink; // serialize transform serTransforms.Add(SerializeTransform(tr)); } // IFC export requires an open transaction, although no changes should be made Transaction transaction = new Transaction(documentCopy, "Export IFC Link"); transaction.Start(); FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions(); failureOptions.SetClearAfterRollback(false); transaction.SetFailureHandlingOptions(failureOptions); // export try { int numLinkInstancesToExport = linkFileNames.Count; exportOptions.AddOption("NumberOfExportedLinkInstances", numLinkInstancesToExport.ToString()); for (int ii = 0; ii < numLinkInstancesToExport; ii++) { string optionName = (ii == 0) ? "ExportLinkInstanceTransform" : "ExportLinkInstanceTransform" + (ii + 1).ToString(); exportOptions.AddOption(optionName, serTransforms[ii]); // Don't pass in file name for the first link instance. if (ii == 0) continue; optionName = "ExportLinkInstanceFileName" + (ii + 1).ToString(); exportOptions.AddOption(optionName, linkFileNames[ii]); } // Pass in the first value; the rest will be in the options. String path_ = Path.GetDirectoryName(linkFileNames[0]); String fileName_ = Path.GetFileName(linkFileNames[0]); bool result = documentCopy.Export(path_, fileName_, exportOptions); // pass in the options here } catch { } // rollback the transaction transaction.RollBack(); // close the document documentCopy.Close(false); // delete the copy try { File.Delete(linkPathNameCopy); } catch { } // Show user errors, if any. int numBadInstances = pathDoesntExist.Count + noTempDoc.Count + cantFindDoc.Count + nonConformalInst.Count + scaledInst.Count + instHasReflection.Count; if (numBadInstances > 0) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = string.Format(Properties.Resources.LinkInstanceExportErrorMain, numBadInstances); taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; taskDialog.TitleAutoPrefix = false; string expandedContent = ""; AddExpandedStringContent(ref expandedContent, Properties.Resources.LinkInstanceExportErrorPath, pathDoesntExist); AddExpandedStringContent(ref expandedContent, Properties.Resources.LinkInstanceExportCantCreateDoc, noTempDoc); AddExpandedElementIdContent(ref expandedContent, Properties.Resources.LinkInstanceExportCantFindDoc, cantFindDoc); AddExpandedElementIdContent(ref expandedContent, Properties.Resources.LinkInstanceExportNonConformal, nonConformalInst); AddExpandedElementIdContent(ref expandedContent, Properties.Resources.LinkInstanceExportScaled, scaledInst); AddExpandedElementIdContent(ref expandedContent, Properties.Resources.LinkInstanceExportHasReflection, instHasReflection); taskDialog.ExpandedContent = expandedContent; TaskDialogResult result = taskDialog.Show(); } } } }
/// <summary> /// Implementation of the command binding event for the IFC export command. /// </summary> /// <param name="sender">The event sender (Revit UIApplication).</param> /// <param name="args">The arguments (command binding).</param> public void OnIFCExport(object sender, CommandEventArgs args) { try { // Prepare basic objects UIApplication uiApp = sender as UIApplication; UIDocument uiDoc = uiApp.ActiveUIDocument; Document activeDoc = uiDoc.Document; TheDocument = activeDoc; // Note that when exporting multiple documents, we are still going to use the configurations from the // active document. IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap(); configurationsMap.Add(IFCExportConfiguration.GetInSession()); configurationsMap.AddBuiltInConfigurations(); configurationsMap.AddSavedConfigurations(); String mruSelection = null; if (m_mruConfiguration != null && configurationsMap.HasName(m_mruConfiguration)) mruSelection = m_mruConfiguration; PotentiallyUpdatedConfigurations = false; IFCExport mainWindow = new IFCExport(uiApp, configurationsMap, mruSelection); mainWindow.ShowDialog(); // If user chose to continue if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings) { int docsToExport = mainWindow.DocumentsToExport.Count; // This shouldn't happen, but just to be safe. if (docsToExport == 0) return; bool multipleFiles = docsToExport > 1; // prompt for the file name SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.AddExtension = true; String defaultDirectory = m_mruExportPath != null ? m_mruExportPath : null; if (defaultDirectory == null) { String revitFilePath = TheDocument.PathName; if (!String.IsNullOrEmpty(revitFilePath)) { defaultDirectory = Path.GetDirectoryName(revitFilePath); } } if (defaultDirectory == null) defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string defaultExt = mainWindow.GetFileExtension(); fileDialog.FileName = multipleFiles ? Properties.Resources.MultipleFiles : GenerateFileNameFromDocument(mainWindow.DocumentsToExport[0], null); fileDialog.DefaultExt = defaultExt; fileDialog.Filter = mainWindow.GetFileFilter(); fileDialog.InitialDirectory = defaultDirectory; bool? fileDialogResult = fileDialog.ShowDialog(); // If user chooses to continue if (fileDialogResult.HasValue && fileDialogResult.Value) { // change options IFCExportConfiguration selectedConfig = mainWindow.GetSelectedConfiguration(); // Prompt the user for the file location and path String fullName = fileDialog.FileName; String path = Path.GetDirectoryName(fullName); String fileName = multipleFiles ? string.Empty : Path.GetFileName(fullName); // This option should be rarely used, and is only for consistency with old files. As such, it is set by environment variable only. String use2009GUID = Environment.GetEnvironmentVariable("Assign2009GUIDToBuildingStoriesOnIFCExport"); bool use2009BuildingStoreyGUIDs = (use2009GUID != null && use2009GUID == "1"); string unsuccesfulExports = string.Empty; // In rare occasions, there may be two projects loaded into Revit with the same name. This isn't supposed to be allowed, but can happen if, // e.g., a user creates a new project, exports it to IFC, and then calls Open IFC. In this case, if we export both projects, we will overwrite // one of the exports. Prevent that by keeping track of the exported file names. ISet<string> exportedFileNames = new HashSet<string>(); foreach (Document document in mainWindow.DocumentsToExport) { TheDocument = document; // Call this before the Export IFC transaction starts, as it has its own transaction. IFCClassificationMgr.DeleteObsoleteSchemas(document); Transaction transaction = new Transaction(document, "Export IFC"); transaction.Start(); FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions(); failureOptions.SetClearAfterRollback(false); transaction.SetFailureHandlingOptions(failureOptions); // Normally the transaction will be rolled back, but there are cases where we do update the document. // There is no UI option for this, but these two options can be useful for debugging/investigating // issues in specific file export. The first one supports export of only one element //exportOptions.AddOption("SingleElement", "174245"); // The second one supports export only of a list of elements //exportOptions.AddOption("ElementsForExport", "174245;205427"); if (multipleFiles) { fileName = GenerateFileNameFromDocument(document, exportedFileNames) + "." + defaultExt; fullName = path + "\\" + fileName; } // Prepare the export options IFCExportOptions exportOptions = new IFCExportOptions(); ElementId activeViewId = GenerateActiveViewIdFromDocument(document); selectedConfig.UpdateOptions(exportOptions, activeViewId); selectedConfig.ActiveViewId = selectedConfig.UseActiveViewGeometry ? activeViewId.IntegerValue : -1; bool result = document.Export(path, fileName, exportOptions); Dictionary<ElementId, string> linksGUIDsCache = new Dictionary<ElementId, string>(); if (result) { // Cache for links guids if (selectedConfig.ExportLinkedFiles == true) { Autodesk.Revit.DB.FilteredElementCollector collector = new FilteredElementCollector(document); collector.WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_RvtLinks); System.Collections.Generic.ICollection<ElementId> rvtLinkInstanceIds = collector.ToElementIds(); foreach (ElementId linkId in rvtLinkInstanceIds) { Element linkInstance = document.GetElement(linkId); if (linkInstance == null) continue; Parameter parameter = linkInstance.get_Parameter(BuiltInParameter.IFC_GUID); if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.String) { String sGUID = parameter.AsString(), sGUIDlower = sGUID.ToLower(); foreach (KeyValuePair<ElementId, string> value in linksGUIDsCache) if (value.Value.ToLower().IndexOf(sGUIDlower) == 0) sGUID += "-"; linksGUIDsCache.Add(linkInstance.Id, sGUID); } } } } else { unsuccesfulExports += fullName + "\n"; } // Roll back the transaction started earlier, unless certain options are set. if (result && (use2009BuildingStoreyGUIDs || selectedConfig.StoreIFCGUID)) transaction.Commit(); else transaction.RollBack(); // Export links if (selectedConfig.ExportLinkedFiles == true) { exportOptions.AddOption("ExportingLinks", true.ToString()); ExportLinkedDocuments(document, fullName, linksGUIDsCache, exportOptions); exportOptions.AddOption("ExportingLinks", false.ToString()); } } if (!string.IsNullOrWhiteSpace(unsuccesfulExports)) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = string.Format(Properties.Resources.IFCExportProcessError, unsuccesfulExports); taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; TaskDialogResult taskDialogResult = taskDialog.Show(); } } // Remember last successful export location m_mruExportPath = path; } } // The cancel button should cancel the export, not any "OK"ed setup changes. if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings || mainWindow.Result == IFCExportResult.Cancel) { if (PotentiallyUpdatedConfigurations) { configurationsMap = mainWindow.GetModifiedConfigurations(); configurationsMap.UpdateSavedConfigurations(); } // Remember last selected configuration m_mruConfiguration = mainWindow.GetSelectedConfiguration().Name; } } catch (Exception e) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = Properties.Resources.IFCExportProcessGenericError; taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; taskDialog.ExpandedContent = e.ToString(); TaskDialogResult result = taskDialog.Show(); } } }
/// <summary> /// Updates the IFCExportOptions with the settings in this configuration. /// </summary> /// <param name="options">The IFCExportOptions to update.</param> /// <param name="filterViewId">The id of the view that will be used to select which elements to export.</param> public void UpdateOptions(IFCExportOptions options, ElementId filterViewId) { JavaScriptSerializer ser = new JavaScriptSerializer(); foreach (var prop in GetType().GetProperties()) { switch (prop.Name) { case "Name": options.AddOption("ConfigName", Name); // Add config name into the option for use in the exporter break; case "IFCVersion": options.FileVersion = IFCVersion; break; case "ActivePhaseId": if (IFCPhaseAttributes.Validate(ActivePhaseId)) { options.AddOption(prop.Name, ActivePhaseId.ToString()); } break; case "SpaceBoundaries": options.SpaceBoundaryLevel = SpaceBoundaries; break; case "SplitWallsAndColumns": options.WallAndColumnSplitting = SplitWallsAndColumns; break; case "ExportBaseQuantities": options.ExportBaseQuantities = ExportBaseQuantities; break; case "ProjectAddress": string projectAddrJsonString = ser.Serialize(ProjectAddress); options.AddOption(prop.Name, projectAddrJsonString); break; case "ClassificationSettings": string classificationJsonStr = ser.Serialize(ClassificationSettings); options.AddOption(prop.Name, classificationJsonStr); break; default: var propVal = prop.GetValue(this, null); if (propVal != null) { options.AddOption(prop.Name, propVal.ToString()); } break; } } options.FilterViewId = VisibleElementsOfCurrentView ? filterViewId : ElementId.InvalidElementId; string uiVersion = IFCUISettings.GetAssemblyVersion(); options.AddOption("AlternateUIVersion", uiVersion); }
/// <summary> /// Updates the IFCExportOptions with the settings in this configuration. /// </summary> /// <param name="options">The IFCExportOptions to update.</param> /// <param name="filterViewId">The filter view.</param> public void UpdateOptions(IFCExportOptions options, ElementId filterViewId) { options.FileVersion = IFCVersion; options.SpaceBoundaryLevel = SpaceBoundaries; options.ExportBaseQuantities = ExportBaseQuantities; options.WallAndColumnSplitting = SplitWallsAndColumns; if (VisibleElementsOfCurrentView) options.FilterViewId = filterViewId; else options.FilterViewId = ElementId.InvalidElementId; options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString()); options.AddOption("ExportAnnotations", Export2DElements.ToString()); options.AddOption("Use2DRoomBoundaryForVolume",Use2DRoomBoundaryForVolume.ToString()); options.AddOption("UseFamilyAndTypeNameForReference",UseFamilyAndTypeNameForReference.ToString()); options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString()); options.AddOption("FileType", IFCFileType.ToString()); }
/// <summary> /// Implementation of the command binding event for the IFC export command. /// </summary> /// <param name="sender">The event sender (Revit UIApplication).</param> /// <param name="args">The arguments (command binding).</param> public void OnIFCExport(object sender, CommandEventArgs args) { try { // Prepare basic objects UIApplication uiApp = sender as UIApplication; UIDocument uiDoc = uiApp.ActiveUIDocument; Document doc = uiDoc.Document; TheDocument = doc; IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap(); configurationsMap.Add(IFCExportConfiguration.GetInSession()); configurationsMap.AddBuiltInConfigurations(); configurationsMap.AddSavedConfigurations(); String mruSelection = null; if (m_mruConfiguration != null && configurationsMap.HasName(m_mruConfiguration)) mruSelection = m_mruConfiguration; PotentiallyUpdatedConfigurations = false; IFCExport mainWindow = new IFCExport(doc, configurationsMap, mruSelection); mainWindow.ShowDialog(); // If user chose to continue if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings) { // change options IFCExportConfiguration selectedConfig = mainWindow.GetSelectedConfiguration(); // Prepare the export options IFCExportOptions exportOptions = new IFCExportOptions(); selectedConfig.UpdateOptions(exportOptions, uiDoc.ActiveView.Id); // prompt for the file name SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.AddExtension = true; String defaultDirectory = m_mruExportPath != null ? m_mruExportPath : null; if (defaultDirectory == null) { String revitFilePath = doc.PathName; if (!String.IsNullOrEmpty(revitFilePath)) { defaultDirectory = Path.GetDirectoryName(revitFilePath); } } if (defaultDirectory == null) { defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } String defaultFileName = doc.Title; if (String.IsNullOrEmpty(defaultFileName)) { defaultFileName = "Project"; } else { defaultFileName = Path.GetFileNameWithoutExtension(defaultFileName); } String defaultExtension = mainWindow.GetFileExtension(); fileDialog.FileName = defaultFileName; fileDialog.DefaultExt = defaultExtension; fileDialog.Filter = mainWindow.GetFileFilter(); fileDialog.InitialDirectory = defaultDirectory; bool? fileDialogResult = fileDialog.ShowDialog(); // If user chose to continue if (fileDialogResult.HasValue && fileDialogResult.Value) { // Prompt the user for the file location and path String fullName = fileDialog.FileName; String path = Path.GetDirectoryName(fullName); String fileName = Path.GetFileName(fullName); // Call this before the Export IFC transaction starts, as it has its own transaction. IFCClassificationMgr.DeleteObsoleteSchemas(doc); // IFC export requires an open transaction, although no changes should be made Transaction transaction = new Transaction(doc, "Export IFC"); transaction.Start(); FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions(); failureOptions.SetClearAfterRollback(false); transaction.SetFailureHandlingOptions(failureOptions); // There is no UI option for this, but these two options can be useful for debugging/investigating // issues in specific file export. The first one supports export of only one element //exportOptions.AddOption("SingleElement", "174245"); // The second one supports export only of a list of elements //exportOptions.AddOption("ElementsForExport", "174245;205427"); bool result = doc.Export(path, fileName, exportOptions); // pass in the options here if (!result) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = Properties.Resources.IFCExportProcessError; taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; TaskDialogResult taskDialogResult = taskDialog.Show(); } } // This option should be rarely used, and is only for consistency with old files. As such, it is set by environment variable only. String use2009GUID = Environment.GetEnvironmentVariable("Assign2009GUIDToBuildingStoriesOnIFCExport"); bool use2009BuildingStoreyGUIDs = (use2009GUID != null && use2009GUID == "1"); // Cache for links guids Dictionary<ElementId, string> linksGUIDsCache = new Dictionary<ElementId, string>(); if (selectedConfig.ExportLinkedFiles == true) { Autodesk.Revit.DB.FilteredElementCollector collector = new FilteredElementCollector(doc); collector.WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_RvtLinks); System.Collections.Generic.ICollection<ElementId> rvtLinkInstanceIds = collector.ToElementIds(); foreach (ElementId linkId in rvtLinkInstanceIds) { Element linkInstance = doc.GetElement(linkId); if (linkInstance == null) continue; Parameter parameter = linkInstance.get_Parameter(BuiltInParameter.IFC_GUID); if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.String) { String sGUID = parameter.AsString(), sGUIDlower = sGUID.ToLower(); foreach (KeyValuePair<ElementId, string> value in linksGUIDsCache) if (value.Value.ToLower().IndexOf(sGUIDlower) == 0) sGUID += "-"; linksGUIDsCache.Add(linkInstance.Id, sGUID); } } } // Roll back the transaction started earlier, unless certain options are set. if (use2009BuildingStoreyGUIDs || selectedConfig.StoreIFCGUID) transaction.Commit(); else transaction.RollBack(); // Export links if (selectedConfig.ExportLinkedFiles == true) { exportOptions.AddOption("ExportingLinks", true.ToString()); ExportLinkedDocuments(doc, fullName, linksGUIDsCache, exportOptions); exportOptions.AddOption("ExportingLinks", false.ToString()); } // Remember last successful export location m_mruExportPath = path; } } // The cancel button should cancel the export, not any "OK"ed setup changes. if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings || mainWindow.Result == IFCExportResult.Cancel) { if (PotentiallyUpdatedConfigurations) { configurationsMap = mainWindow.GetModifiedConfigurations(); configurationsMap.UpdateSavedConfigurations(); } // Remember last selected configuration m_mruConfiguration = mainWindow.GetSelectedConfiguration().Name; } } catch (Exception e) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = Properties.Resources.IFCExportProcessError; taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; taskDialog.ExpandedContent = e.ToString(); TaskDialogResult result = taskDialog.Show(); } } }
/// <summary> /// Updates the IFCExportOptions with the settings in this configuration. /// </summary> /// <param name="options">The IFCExportOptions to update.</param> /// <param name="filterViewId">The filter view.</param> public void UpdateOptions(IFCExportOptions options, ElementId filterViewId) { options.FileVersion = IFCVersion; options.SpaceBoundaryLevel = SpaceBoundaries; options.ExportBaseQuantities = ExportBaseQuantities; options.WallAndColumnSplitting = SplitWallsAndColumns; if (VisibleElementsOfCurrentView) options.FilterViewId = filterViewId; else options.FilterViewId = ElementId.InvalidElementId; options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString()); options.AddOption("ExportIFCCommonPropertySets", ExportIFCCommonPropertySets.ToString()); options.AddOption("ExportAnnotations", Export2DElements.ToString()); options.AddOption("Use2DRoomBoundaryForVolume",Use2DRoomBoundaryForVolume.ToString()); options.AddOption("UseFamilyAndTypeNameForReference",UseFamilyAndTypeNameForReference.ToString()); options.AddOption("ExportVisibleElementsInView", VisibleElementsOfCurrentView.ToString()); options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString()); options.AddOption("ExportBoundingBox", ExportBoundingBox.ToString()); options.AddOption("ExportSolidModelRep", ExportSolidModelRep.ToString()); options.AddOption("ExportSchedulesAsPsets", ExportSchedulesAsPsets.ToString()); options.AddOption("ExportUserDefinedPsets", ExportUserDefinedPsets.ToString()); options.AddOption("ExportLinkedFiles", ExportLinkedFiles.ToString()); options.AddOption("IncludeSiteElevation", IncludeSiteElevation.ToString()); options.AddOption("UseCoarseTessellation", UseCoarseTessellation.ToString()); options.AddOption("StoreIFCGUID", StoreIFCGUID.ToString()); options.AddOption("ActivePhase", ActivePhaseId.ToString()); options.AddOption("FileType", IFCFileType.ToString()); string uiVersion = IFCUISettings.GetAssemblyVersion(); options.AddOption("AlternateUIVersion", uiVersion); options.AddOption("ConfigName", Name); // Add config name into the option for use in the exporter options.AddOption("ExportUserDefinedPsetsFileName", ExportUserDefinedPsetsFileName); }
/// <summary> /// Updates the IFCExportOptions with the settings in this configuration. /// </summary> /// <param name="options">The IFCExportOptions to update.</param> /// <param name="filterViewId">The id of the view that will be used to select which elements to export.</param> public void UpdateOptions(IFCExportOptions options, ElementId filterViewId) { options.FileVersion = IFCVersion; options.SpaceBoundaryLevel = SpaceBoundaries; options.ExportBaseQuantities = ExportBaseQuantities; options.WallAndColumnSplitting = SplitWallsAndColumns; options.FilterViewId = VisibleElementsOfCurrentView ? filterViewId : ElementId.InvalidElementId; options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString()); options.AddOption("ExportIFCCommonPropertySets", ExportIFCCommonPropertySets.ToString()); options.AddOption("ExportAnnotations", Export2DElements.ToString()); options.AddOption("Use2DRoomBoundaryForVolume",Use2DRoomBoundaryForVolume.ToString()); options.AddOption("UseFamilyAndTypeNameForReference",UseFamilyAndTypeNameForReference.ToString()); options.AddOption("ExportVisibleElementsInView", VisibleElementsOfCurrentView.ToString()); options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString()); options.AddOption("UseActiveViewGeometry", UseActiveViewGeometry.ToString()); options.AddOption("ExportSpecificSchedules", ExportSpecificSchedules.ToString()); options.AddOption("ExportBoundingBox", ExportBoundingBox.ToString()); options.AddOption("ExportSolidModelRep", ExportSolidModelRep.ToString()); options.AddOption("ExportSchedulesAsPsets", ExportSchedulesAsPsets.ToString()); options.AddOption("ExportUserDefinedPsets", ExportUserDefinedPsets.ToString()); options.AddOption("ExportLinkedFiles", ExportLinkedFiles.ToString()); options.AddOption("IncludeSiteElevation", IncludeSiteElevation.ToString()); options.AddOption("TessellationLevelOfDetail", TessellationLevelOfDetail.ToString()); options.AddOption("ActiveViewId", ActiveViewId.ToString()); options.AddOption("StoreIFCGUID", StoreIFCGUID.ToString()); // The active phase may not be valid if we are exporting multiple projects. However, if projects share a template that defines the phases, // then the ActivePhaseId would likely be valid for all. There is some small chance that the ActivePhaseId would be a valid, but different, phase // in different projects, but that is unlikely enough that it seems worth warning against it but allowing the better functionality in general. if (IFCPhaseAttributes.Validate(ActivePhaseId)) options.AddOption("ActivePhase", ActivePhaseId.ToString()); options.AddOption("FileType", IFCFileType.ToString()); string uiVersion = IFCUISettings.GetAssemblyVersion(); options.AddOption("AlternateUIVersion", uiVersion); options.AddOption("ConfigName", Name); // Add config name into the option for use in the exporter options.AddOption("ExportUserDefinedPsetsFileName", ExportUserDefinedPsetsFileName); options.AddOption("ExportRoomsInView", ExportRoomsInView.ToString()); }
private static void ExportProjectToIFC(Document doc, string path) { IFCExportOptions ifcOptions = new IFCExportOptions(); { ifcOptions.FileVersion = IFCVersion.IFC2x3; ifcOptions.WallAndColumnSplitting = false; ifcOptions.SpaceBoundaryLevel = 1; ifcOptions.ExportBaseQuantities = false; ifcOptions.AddOption("ExportInternalRevitPropertySets", "false"); ifcOptions.AddOption("ExportIFCCommonPropertySets", "true"); ifcOptions.AddOption("ExportAnnotations", "false"); ifcOptions.AddOption("Use2DRoomBoundaryForVolume", "false"); ifcOptions.AddOption("UseFamilyAndTypeNameForReference", "false"); ifcOptions.AddOption("ExportVisibleElementsInView", "false"); ifcOptions.AddOption("ExportPartsAsBuildingElements", "false"); ifcOptions.AddOption("UseActiveViewGeometry", "false"); ifcOptions.AddOption("ExportSpecificSchedules", "false"); ifcOptions.AddOption("ExportBoundingBox", "false"); ifcOptions.AddOption("ExportSolidModelRep", "false"); ifcOptions.AddOption("ExportSchedulesAsPsets", "false"); ifcOptions.AddOption("ExportUserDefinedPsets", "false"); ifcOptions.AddOption("ExportUserDefinedParameterMapping", "false"); ifcOptions.AddOption("ExportLinkedFiles", "false"); ifcOptions.AddOption("IncludeSiteElevation", "false"); ifcOptions.AddOption("TessellationLevelOfDetail", "0.5"); ifcOptions.AddOption("StoreIFCGUID", "true"); } /* // get the revit form and set its cursor to busy * System.Windows.Forms.Control form = System.Windows.Forms.Control.FromHandle(Process.GetCurrentProcess().MainWindowHandle); * if (null != form) form.Cursor = Cursors.WaitCursor; * * //RevitStatusText.Set("Exporting Revit Project to IFC"); * Application.DoEvents(); */ Transaction trans = new Transaction(doc, "export model"); trans.Start(); // revit doesn't allow the export to run in a different thread doc.Export(path, "tmp.ifc", ifcOptions); trans.Commit(); }
/// <summary> /// Updates the IFCExportOptions with the settings in this configuration. /// </summary> /// <param name="options">The IFCExportOptions to update.</param> /// <param name="filterViewId">The filter view.</param> public void UpdateOptions(IFCExportOptions options, ElementId filterViewId) { options.FileVersion = IFCVersion; options.SpaceBoundaryLevel = SpaceBoundaries; options.ExportBaseQuantities = ExportBaseQuantities; options.WallAndColumnSplitting = SplitWallsAndColumns; if (VisibleElementsOfCurrentView) options.FilterViewId = filterViewId; else options.FilterViewId = ElementId.InvalidElementId; options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString()); options.AddOption("ExportIFCCommonPropertySets", ExportIFCCommonPropertySets.ToString()); options.AddOption("ExportAnnotations", Export2DElements.ToString()); options.AddOption("Use2DRoomBoundaryForVolume",Use2DRoomBoundaryForVolume.ToString()); options.AddOption("UseFamilyAndTypeNameForReference",UseFamilyAndTypeNameForReference.ToString()); options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString()); options.AddOption("ExportSurfaceStyles", ExportSurfaceStyles.ToString()); options.AddOption("ExportAdvancedSweptSolids", ExportAdvancedSweptSolids.ToString()); options.AddOption("ExportBoundingBox", ExportBoundingBox.ToString()); options.AddOption("FileType", IFCFileType.ToString()); string uiVersion = IFCUISettings.GetAssemblyVersion(); options.AddOption("AlternateUIVersion", uiVersion); options.AddOption("ConfigName", Name); // Add config name into the option for use in the exporter }
/// <summary> /// Updates the IFCExportOptions with the settings in this configuration. /// </summary> /// <param name="options">The IFCExportOptions to update.</param> /// <param name="filterViewId">The id of the view that will be used to select which elements to export.</param> public void UpdateOptions(IFCExportOptions options, ElementId filterViewId) { options.FileVersion = IFCVersion; options.AddOption("ExchangeRequirement", ExchangeRequirement.ToString()); options.SpaceBoundaryLevel = SpaceBoundaries; options.ExportBaseQuantities = ExportBaseQuantities; options.WallAndColumnSplitting = SplitWallsAndColumns; options.FilterViewId = VisibleElementsOfCurrentView ? filterViewId : ElementId.InvalidElementId; options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString()); options.AddOption("ExportIFCCommonPropertySets", ExportIFCCommonPropertySets.ToString()); options.AddOption("ExportAnnotations", Export2DElements.ToString()); options.AddOption("Use2DRoomBoundaryForVolume", Use2DRoomBoundaryForVolume.ToString()); options.AddOption("UseFamilyAndTypeNameForReference", UseFamilyAndTypeNameForReference.ToString()); options.AddOption("ExportAllPhases", ExportAllPhases.ToString()); options.AddOption("ExportVisibleElementsInView", VisibleElementsOfCurrentView.ToString()); options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString()); options.AddOption("UseActiveViewGeometry", UseActiveViewGeometry.ToString()); options.AddOption("ExportSpecificSchedules", ExportSpecificSchedules.ToString()); options.AddOption("ExportBoundingBox", ExportBoundingBox.ToString()); options.AddOption("ExportSolidModelRep", ExportSolidModelRep.ToString()); options.AddOption("ExportSchedulesAsPsets", ExportSchedulesAsPsets.ToString()); options.AddOption("ExportUserDefinedPsets", ExportUserDefinedPsets.ToString()); options.AddOption("ExportUserDefinedParameterMapping", ExportUserDefinedParameterMapping.ToString()); options.AddOption("ExportLinkedFiles", ExportLinkedFiles.ToString()); options.AddOption("IncludeSiteElevation", IncludeSiteElevation.ToString()); options.AddOption("SitePlacement", SitePlacement.ToString()); options.AddOption("TessellationLevelOfDetail", TessellationLevelOfDetail.ToString()); options.AddOption("UseOnlyTriangulation", UseOnlyTriangulation.ToString()); options.AddOption("ActiveViewId", ActiveViewId.ToString()); options.AddOption("StoreIFCGUID", StoreIFCGUID.ToString()); // The active phase may not be valid if we are exporting multiple projects. However, if projects share a template that defines the phases, // then the ActivePhaseId would likely be valid for all. There is some small chance that the ActivePhaseId would be a valid, but different, phase // in different projects, but that is unlikely enough that it seems worth warning against it but allowing the better functionality in general. if (IFCPhaseAttributes.Validate(ActivePhaseId)) { options.AddOption("ActivePhase", ActivePhaseId.ToString()); } options.AddOption("FileType", IFCFileType.ToString()); string uiVersion = IFCUISettings.GetAssemblyVersion(); options.AddOption("AlternateUIVersion", uiVersion); options.AddOption("ConfigName", Name); // Add config name into the option for use in the exporter options.AddOption("ExportUserDefinedPsetsFileName", ExportUserDefinedPsetsFileName); options.AddOption("ExportUserDefinedParameterMappingFileName", ExportUserDefinedParameterMappingFileName); options.AddOption("ExportRoomsInView", ExportRoomsInView.ToString()); options.AddOption("ExcludeFilter", ExcludeFilter.ToString()); options.AddOption("COBieCompanyInfo", COBieCompanyInfo); options.AddOption("COBieProjectInfo", COBieProjectInfo); options.AddOption("IncludeSteelElements", IncludeSteelElements.ToString()); options.AddOption("UseTypeNameOnlyForIfcType", UseTypeNameOnlyForIfcType.ToString()); options.AddOption("UseVisibleRevitNameAsEntityName", UseVisibleRevitNameAsEntityName.ToString()); options.AddOption("ExportAllPhases", ExportAllPhases.ToString()); // Add CRS information options.AddOption("GeoRefCRSName", GeoRefCRSName != null? GeoRefCRSName : ""); options.AddOption("GeoRefCRSDesc", GeoRefCRSDesc != null ? GeoRefCRSDesc : ""); options.AddOption("GeoRefEPSGCode", GeoRefEPSGCode != null ? GeoRefEPSGCode : ""); options.AddOption("GeoRefGeodeticDatum", GeoRefGeodeticDatum != null ? GeoRefGeodeticDatum : ""); options.AddOption("GeoRefMapUnit", GeoRefMapUnit != null ? GeoRefMapUnit : ""); }
/// <summary> /// Updates the IFCExportOptions with the settings in this configuration. /// </summary> /// <param name="options">The IFCExportOptions to update.</param> /// <param name="filterViewId">The filter view.</param> public void UpdateOptions(IFCExportOptions options, ElementId filterViewId) { options.FileVersion = IFCVersion; options.SpaceBoundaryLevel = SpaceBoundaries; options.ExportBaseQuantities = ExportBaseQuantities; options.WallAndColumnSplitting = SplitWallsAndColumns; if (VisibleElementsOfCurrentView) { options.FilterViewId = filterViewId; } else { options.FilterViewId = ElementId.InvalidElementId; } options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString()); options.AddOption("ExportIFCCommonPropertySets", ExportIFCCommonPropertySets.ToString()); options.AddOption("ExportAnnotations", Export2DElements.ToString()); options.AddOption("Use2DRoomBoundaryForVolume", Use2DRoomBoundaryForVolume.ToString()); options.AddOption("UseFamilyAndTypeNameForReference", UseFamilyAndTypeNameForReference.ToString()); options.AddOption("ExportVisibleElementsInView", VisibleElementsOfCurrentView.ToString()); options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString()); options.AddOption("ExportBoundingBox", ExportBoundingBox.ToString()); options.AddOption("ExportSolidModelRep", ExportSolidModelRep.ToString()); options.AddOption("ExportSchedulesAsPsets", ExportSchedulesAsPsets.ToString()); options.AddOption("ExportUserDefinedPsets", ExportUserDefinedPsets.ToString()); options.AddOption("ExportLinkedFiles", ExportLinkedFiles.ToString()); options.AddOption("IncludeSiteElevation", IncludeSiteElevation.ToString()); options.AddOption("UseCoarseTessellation", UseCoarseTessellation.ToString()); options.AddOption("TessellationLevelOfDetail", TessellationLevelOfDetail.ToString()); options.AddOption("StoreIFCGUID", StoreIFCGUID.ToString()); options.AddOption("ActivePhase", ActivePhaseId.ToString()); options.AddOption("FileType", IFCFileType.ToString()); string uiVersion = IFCUISettings.GetAssemblyVersion(); options.AddOption("AlternateUIVersion", uiVersion); options.AddOption("ConfigName", Name); // Add config name into the option for use in the exporter options.AddOption("ExportUserDefinedPsetsFileName", ExportUserDefinedPsetsFileName); options.AddOption("ExportRoomsInView", ExportRoomsInView.ToString()); }
/// <summary> /// Implementation of the command binding event for the IFC export command. /// </summary> /// <param name="sender">The event sender (Revit UIApplication).</param> /// <param name="args">The arguments (command binding).</param> public void OnIFCExport(object sender, CommandEventArgs args) { try { // Prepare basic objects UIApplication uiApp = sender as UIApplication; UIDocument uiDoc = uiApp.ActiveUIDocument; Document activeDoc = uiDoc.Document; TheDocument = activeDoc; // Note that when exporting multiple documents, we are still going to use the configurations from the // active document. IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap(); configurationsMap.Add(IFCExportConfiguration.GetInSession()); configurationsMap.AddBuiltInConfigurations(); configurationsMap.AddSavedConfigurations(); String mruSelection = null; if (m_mruConfiguration != null && configurationsMap.HasName(m_mruConfiguration)) { mruSelection = m_mruConfiguration; } PotentiallyUpdatedConfigurations = false; IFCExport mainWindow = new IFCExport(uiApp, configurationsMap, mruSelection); mainWindow.ShowDialog(); // If user chose to continue if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings) { int docsToExport = mainWindow.DocumentsToExport.Count; // This shouldn't happen, but just to be safe. if (docsToExport == 0) { return; } bool multipleFiles = docsToExport > 1; // If user chooses to continue // change options IFCExportConfiguration selectedConfig = mainWindow.GetSelectedConfiguration(); // Prompt the user for the file location and path string defaultExt = mainWindow.DefaultExt; String fullName = mainWindow.ExportFilePathName; String path = Path.GetDirectoryName(fullName); String fileName = multipleFiles ? Properties.Resources.MultipleFiles : Path.GetFileName(fullName); // This option should be rarely used, and is only for consistency with old files. As such, it is set by environment variable only. String use2009GUID = Environment.GetEnvironmentVariable("Assign2009GUIDToBuildingStoriesOnIFCExport"); bool use2009BuildingStoreyGUIDs = (use2009GUID != null && use2009GUID == "1"); string unsuccesfulExports = string.Empty; // In rare occasions, there may be two projects loaded into Revit with the same name. This isn't supposed to be allowed, but can happen if, // e.g., a user creates a new project, exports it to IFC, and then calls Open IFC. In this case, if we export both projects, we will overwrite // one of the exports. Prevent that by keeping track of the exported file names. ISet <string> exportedFileNames = new HashSet <string>(); foreach (Document document in mainWindow.DocumentsToExport) { TheDocument = document; // Call this before the Export IFC transaction starts, as it has its own transaction. IFCClassificationMgr.DeleteObsoleteSchemas(document); Transaction transaction = new Transaction(document, "Export IFC"); transaction.Start(); FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions(); failureOptions.SetClearAfterRollback(false); transaction.SetFailureHandlingOptions(failureOptions); // Normally the transaction will be rolled back, but there are cases where we do update the document. // There is no UI option for this, but these two options can be useful for debugging/investigating // issues in specific file export. The first one supports export of only one element //exportOptions.AddOption("SingleElement", "174245"); // The second one supports export only of a list of elements //exportOptions.AddOption("ElementsForExport", "174245;205427"); if (multipleFiles) { fileName = IFCUISettings.GenerateFileNameFromDocument(document, exportedFileNames) + "." + defaultExt; fullName = path + "\\" + fileName; } // Prepare the export options IFCExportOptions exportOptions = new IFCExportOptions(); ElementId activeViewId = GenerateActiveViewIdFromDocument(document); selectedConfig.ActiveViewId = selectedConfig.UseActiveViewGeometry ? activeViewId.IntegerValue : -1; selectedConfig.UpdateOptions(exportOptions, activeViewId); bool result = document.Export(path, fileName, exportOptions); Dictionary <ElementId, string> linksGUIDsCache = new Dictionary <ElementId, string>(); if (result) { // Cache for links guids if (selectedConfig.ExportLinkedFiles == true) { Autodesk.Revit.DB.FilteredElementCollector collector = new FilteredElementCollector(document); collector.WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_RvtLinks); System.Collections.Generic.ICollection <ElementId> rvtLinkInstanceIds = collector.ToElementIds(); foreach (ElementId linkId in rvtLinkInstanceIds) { Element linkInstance = document.GetElement(linkId); if (linkInstance == null) { continue; } Parameter parameter = linkInstance.get_Parameter(BuiltInParameter.IFC_GUID); if (parameter != null && parameter.HasValue && parameter.StorageType == StorageType.String) { String sGUID = parameter.AsString(), sGUIDlower = sGUID.ToLower(); foreach (KeyValuePair <ElementId, string> value in linksGUIDsCache) { if (value.Value.ToLower().IndexOf(sGUIDlower) == 0) { sGUID += "-"; } } linksGUIDsCache.Add(linkInstance.Id, sGUID); } } } } else { unsuccesfulExports += fullName + "\n"; } // Roll back the transaction started earlier, unless certain options are set. if (result && (use2009BuildingStoreyGUIDs || selectedConfig.StoreIFCGUID)) { transaction.Commit(); } else { transaction.RollBack(); } // Export links if (selectedConfig.ExportLinkedFiles == true) { exportOptions.AddOption("ExportingLinks", true.ToString()); ExportLinkedDocuments(document, fullName, linksGUIDsCache, exportOptions); exportOptions.AddOption("ExportingLinks", false.ToString()); } } if (!string.IsNullOrWhiteSpace(unsuccesfulExports)) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = string.Format(Properties.Resources.IFCExportProcessError, unsuccesfulExports); taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; TaskDialogResult taskDialogResult = taskDialog.Show(); } } // Remember last successful export location m_mruExportPath = path; } // The cancel button should cancel the export, not any "OK"ed setup changes. if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings || mainWindow.Result == IFCExportResult.Cancel) { if (PotentiallyUpdatedConfigurations) { configurationsMap = mainWindow.GetModifiedConfigurations(); configurationsMap.UpdateSavedConfigurations(); } // Remember last selected configuration m_mruConfiguration = mainWindow.GetSelectedConfiguration().Name; } } catch (Exception e) { using (TaskDialog taskDialog = new TaskDialog(Properties.Resources.IFCExport)) { taskDialog.MainInstruction = Properties.Resources.IFCExportProcessGenericError; taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning; taskDialog.ExpandedContent = e.ToString(); TaskDialogResult result = taskDialog.Show(); } } }