Пример #1
0
        /// <summary>
        /// Construction of the main export dialog.
        /// </summary>
        /// <param name="app">The UIApplication that contains a list of all documents.</param>
        /// <param name="configurationsMap">The configurations to show in the dialog.</param>
        /// <param name="selectedConfigName">The current selected configuration name.</param>
        public IFCExport(Autodesk.Revit.UI.UIApplication app, IFCExportConfigurationsMap configurationsMap, String selectedConfigName)
        {
            m_configMap = configurationsMap;

            SetParent(app.MainWindowHandle);

            InitializeComponent();

            RestorePreviousWindow();

            currentSelectedSetup.SelectionChanged -= currentSelectedSetup_SelectionChanged;

            UpdateCurrentSelectedSetupCombo(selectedConfigName);
            UpdateOpenedProjectsListView(app);

#if IFC_OPENSOURCE
            Title = Properties.Resources.ExportIFC + " (" + IFCUISettings.GetAssemblyVersionForUI() + ")";
#else
            Title = Properties.Resources.ExportIFC;
#endif

            TheDocument = UpdateOpenedProject(app);

            int docToExport = GetDocumentExportCount();
            updateFileName();
        }
Пример #2
0
 /// <summary>
 /// Constructs the new setup name dialog.
 /// </summary>
 /// <param name="configurationMap">The configuration map.</param>
 /// <param name="initialName">The initial name for the setup.</param>
 public NewExportSetupWindow(IFCExportConfigurationsMap configurationMap, String initialName)
 {
     m_configurationMap = configurationMap;
     m_newName          = initialName;
     InitializeComponent();
     textBoxNewSetupName.Text = m_newName;
 }
Пример #3
0
        /// <summary>
        /// Shows the IFC export setup window when clicking the buttonEditSetup.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Event arguments that contains the event data.</param>
        private void buttonEditSetup_Click(object sender, RoutedEventArgs args)
        {
            IFCExportConfiguration     selectedConfig    = GetSelectedConfiguration();
            IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap(m_configMap);
            IFCExporterUIWindow        editorWindow      = new IFCExporterUIWindow(configurationsMap, selectedConfig.Name);

            // the SelectionChanged event will be temporary disabled when the Modify Config Window is active
            //   (it is particularly useful for COBie v2.4 setup to avoid the function is called repeatedly)
            currentSelectedSetup.SelectionChanged -= currentSelectedSetup_SelectionChanged;

            editorWindow.Owner = this;
            bool?ret = editorWindow.ShowDialog();

            if (ret.HasValue)
            {
                m_EditConfigVisited = ret.Value;
            }

            if (editorWindow.DialogResult.HasValue && editorWindow.DialogResult.Value)
            {
                // Check here for changes in configurations. If changed, the changes will be saved into the storage
                configurationsMap.UpdateSavedConfigurations(m_configMap);
                currentSelectedSetup.Items.Clear();
                m_configMap = configurationsMap;
                string selectedConfigName = editorWindow.GetSelectedConfigurationName();

                UpdateCurrentSelectedSetupCombo(selectedConfigName);

                updateFileName();
            }

            // The SelectionChanged event will be activated again after the Modify Config Window is closed
            currentSelectedSetup.SelectionChanged += currentSelectedSetup_SelectionChanged;
        }
Пример #4
0
        /// <summary>
        /// Shows the IFC export setup window when clicking the buttonEditSetup.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Event arguments that contains the event data.</param>
        private void buttonEditSetup_Click(object sender, RoutedEventArgs args)
        {
            IFCExportConfiguration     selectedConfig    = GetSelectedConfiguration();
            IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap(m_configMap);
            IFCExporterUIWindow        editorWindow      = new IFCExporterUIWindow(configurationsMap, selectedConfig.Name);

            // the SelectionChanged event will be temporary disabled when the Modify Config Window is active
            //   (it is particularly useful for COBie v2.4 setup to avoid the function is called repeatedly)
            currentSelectedSetup.SelectionChanged -= currentSelectedSetup_SelectionChanged;

            editorWindow.ShowDialog();
            if (editorWindow.DialogResult.HasValue && editorWindow.DialogResult.Value)
            {
                IFCCommandOverrideApplication.PotentiallyUpdatedConfigurations = true;
                currentSelectedSetup.Items.Clear();
                m_configMap = configurationsMap;
                String selectedConfigName = editorWindow.GetSelectedConfigurationName();

                UpdateCurrentSelectedSetupCombo(selectedConfigName);

                updateFileName();
            }

            // The SelectionChanged event will be activated again after the Modify Config Window is closed
            currentSelectedSetup.SelectionChanged += currentSelectedSetup_SelectionChanged;
        }
Пример #5
0
 /// <summary>
 /// Constructs the new setup name dialog.
 /// </summary>
 /// <param name="configurationMap">The configuration map.</param>
 /// <param name="initialName">The initial name for the setup.</param>
 public NewExportSetupWindow(IFCExportConfigurationsMap configurationMap, String initialName)
 {
     m_configurationMap = configurationMap;
     m_newName = initialName;           
     InitializeComponent();
     textBoxNewSetupName.Text = m_newName;
 }
Пример #6
0
 /// <summary>
 /// Constructs a new map as a copy of an existing one.
 /// </summary>
 /// <param name="map">The specific map to copy.</param>
 public IFCExportConfigurationsMap(IFCExportConfigurationsMap map)
 {
     // Deep copy
     foreach (IFCExportConfiguration value in map.Values)
     {
         Add(value.Clone());
     }
 }
 /// <summary>
 /// Constructs a new map as a copy of an existing one.
 /// </summary>
 /// <param name="map">The specific map to copy.</param>
 public IFCExportConfigurationsMap(IFCExportConfigurationsMap map)
 {
     // Deep copy
     foreach (IFCExportConfiguration value in map.Values)
     {
         Add(value.Clone());
     }
 }
Пример #8
0
        /// <summary>
        /// Construction of the main export dialog.
        /// </summary>
        /// <param name="configurationsMap">The configurations to show in the dialog.</param>
        /// <param name="selectedConfigName">The current selected configuration name.</param>
        public IFCExport(IFCExportConfigurationsMap configurationsMap, String selectedConfigName)
        {
            m_configMap = configurationsMap;

            InitializeComponent();

            RestorePreviousWindow();

            UpdateCurrentSelectedSetupCombo(selectedConfigName);
        }
Пример #9
0
        /// <summary>
        /// Construction of the main export dialog.
        /// </summary>
        /// <param name="configurationsMap">The configurations to show in the dialog.</param>
        /// <param name="selectedConfigName">The current selected configuration name.</param>
        public IFCExport(IFCExportConfigurationsMap configurationsMap, String selectedConfigName)
        {
            m_configMap = configurationsMap;

            InitializeComponent();

            RestorePreviousWindow();

            UpdateCurrentSelectedSetupCombo(selectedConfigName);
        }
        string m_SettingFile = "IFCExportSettings_v15.txt";  // update the file when resize window bounds.

        /// <summary>
        /// Construction of the main export dialog.
        /// </summary>
        /// <param name="configurationsMap">The configurations to show in the dialog.</param>
        /// <param name="selectedConfigName">The current selected configuration name.</param>
        public IFCExport(Document doc, IFCExportConfigurationsMap configurationsMap, String selectedConfigName)
        {
            m_configMap = configurationsMap;
        
            InitializeComponent();

            RestorePreviousWindow();

            UpdateCurrentSelectedSetupCombo(selectedConfigName);

            Title = Properties.Resources.IFCExport + " (" + IFCUISettings.GetAssemblyVersion() + ")";
       }
Пример #11
0
        string m_SettingFile = "IFCExportSettings_v7.txt";  // update the file when resize window bounds.

        /// <summary>
        /// Construction of the main export dialog.
        /// </summary>
        /// <param name="configurationsMap">The configurations to show in the dialog.</param>
        /// <param name="selectedConfigName">The current selected configuration name.</param>
        public IFCExport(Document doc, IFCExportConfigurationsMap configurationsMap, String selectedConfigName)
        {
            m_configMap = configurationsMap;

            InitializeComponent();

            RestorePreviousWindow();

            UpdateCurrentSelectedSetupCombo(selectedConfigName);

            Title = "IFC Export (" + IFCUISettings.GetAssemblyVersion() + ")";
        }
Пример #12
0
        /// <summary>
        /// Construction of the main export dialog.
        /// </summary>
        /// <param name="app">The UIApplication that contains a list of all documents.</param>
        /// <param name="configurationsMap">The configurations to show in the dialog.</param>
        /// <param name="selectedConfigName">The current selected configuration name.</param>
        public IFCExport(Autodesk.Revit.UI.UIApplication app, IFCExportConfigurationsMap configurationsMap, String selectedConfigName)
        {
            m_configMap = configurationsMap;

            InitializeComponent();

            RestorePreviousWindow();

            UpdateCurrentSelectedSetupCombo(selectedConfigName);
            UpdateOpenedProjectsListView(app);

            Title = "IFC Export (" + IFCUISettings.GetAssemblyVersion() + ")";
        }
Пример #13
0
        string m_SettingFile = "IFCExporterUIWindowSettings_v15.txt";    // update the file when resize window bounds.

        /// <summary>
        /// Constructs a new IFC export options window.
        /// </summary>
        /// <param name="exportOptions">The export options that will be populated by settings in the window.</param>
        /// <param name="currentViewId">The Revit current view id.</param>
        public IFCExporterUIWindow(IFCExportConfigurationsMap configurationsMap, String currentConfigName)
        {
            InitializeComponent();

            RestorePreviousWindow();

            m_configurationsMap = configurationsMap;

            InitializeConfigurationList(currentConfigName);

            IFCExportConfiguration originalConfiguration = m_configurationsMap[currentConfigName];
            InitializeConfigurationOptions();
            UpdateActiveConfigurationOptions(originalConfiguration);
        }
Пример #14
0
        /// <summary>
        /// Shows the IFC export setup window when clicking the buttonEditSetup.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Event arguments that contains the event data.</param>
        private void buttonEditSetup_Click(object sender, RoutedEventArgs args)
        {
            IFCExportConfiguration     selectedConfig    = GetSelectedConfiguration();
            IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap(m_configMap);
            IFCExporterUIWindow        editorWindow      = new IFCExporterUIWindow(configurationsMap, selectedConfig.Name);

            editorWindow.ShowDialog();
            if (editorWindow.DialogResult.HasValue && editorWindow.DialogResult.Value)
            {
                currentSelectedSetup.Items.Clear();
                m_configMap = configurationsMap;
                String selectedConfigName = editorWindow.GetSelectedConfigurationName();
                UpdateCurrentSelectedSetupCombo(selectedConfigName);
            }
        }
        string m_SettingFile = "IFCExporterUIWindowSettings_v7.txt";    // update the file when resize window bounds.

        /// <summary>
        /// Constructs a new IFC export options window.
        /// </summary>
        /// <param name="exportOptions">The export options that will be populated by settings in the window.</param>
        /// <param name="currentViewId">The Revit current view id.</param>
        public IFCExporterUIWindow(IFCExportConfigurationsMap configurationsMap, String currentConfigName)
        {
            InitializeComponent();

            RestorePreviousWindow();

            m_configurationsMap = configurationsMap;

            InitializeConfigurationList(currentConfigName);

            IFCExportConfiguration originalConfiguration = m_configurationsMap[currentConfigName];

            InitializeConfigurationOptions();
            UpdateActiveConfigurationOptions(originalConfiguration);
        }
        /// <summary>
        /// Construction of the main export dialog.
        /// </summary>
        /// <param name="app">The UIApplication that contains a list of all documents.</param>
        /// <param name="configurationsMap">The configurations to show in the dialog.</param>
        /// <param name="selectedConfigName">The current selected configuration name.</param>
        public IFCExport(Autodesk.Revit.UI.UIApplication app, IFCExportConfigurationsMap configurationsMap, String selectedConfigName)
        {
            m_configMap = configurationsMap;

            MakeCurrentRevitWindow(this);

            InitializeComponent();

            RestorePreviousWindow();

            UpdateCurrentSelectedSetupCombo(selectedConfigName);
            UpdateOpenedProjectsListView(app);

            Title = Properties.Resources.ExportIFC;

            TheDocument = UpdateOpenedProject(app);

            int docToExport = GetDocumentExportCount();

            updateFileName();
        }
Пример #17
0
        /// <summary>
        /// Construction of the main export dialog.
        /// </summary>
        /// <param name="app">The UIApplication that contains a list of all documents.</param>
        /// <param name="configurationsMap">The configurations to show in the dialog.</param>
        /// <param name="selectedConfigName">The current selected configuration name.</param>
        public IFCExport(Autodesk.Revit.UI.UIApplication app, IFCExportConfigurationsMap configurationsMap, String selectedConfigName)
        {
            m_configMap = configurationsMap;

            InitializeComponent();

            RestorePreviousWindow();

            currentSelectedSetup.SelectionChanged -= currentSelectedSetup_SelectionChanged;

            UpdateCurrentSelectedSetupCombo(selectedConfigName);
            UpdateOpenedProjectsListView(app);

            Title = Properties.Resources.ExportIFC;
            versionDescription.Text = IFCUISettings.GetAssemblyVersionForUI();

            TheDocument = UpdateOpenedProject(app);

            int docToExport = GetDocumentExportCount();

            updateFileName();
        }
Пример #18
0
        /// <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>
       /// Construction of the main export dialog.
       /// </summary>
       /// <param name="app">The UIApplication that contains a list of all documents.</param>
       /// <param name="configurationsMap">The configurations to show in the dialog.</param>
       /// <param name="selectedConfigName">The current selected configuration name.</param>
       public IFCExport(Autodesk.Revit.UI.UIApplication app, IFCExportConfigurationsMap configurationsMap, String selectedConfigName)
       {
           m_configMap = configurationsMap;

           InitializeComponent();

           RestorePreviousWindow();

           UpdateCurrentSelectedSetupCombo(selectedConfigName);
           UpdateOpenedProjectsListView(app);

           Title = "IFC Export (" + IFCUISettings.GetAssemblyVersion() + ")";
       }
Пример #20
0
        /// <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;

                IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap();
                configurationsMap.Add(IFCExportConfiguration.GetInSession());
                configurationsMap.AddBuiltInConfigurations();
                configurationsMap.AddSavedConfigurations(doc);

                String mruSelection = null;
                if (m_mruConfiguration != null && configurationsMap.HasName(m_mruConfiguration))
                {
                    mruSelection = m_mruConfiguration;
                }

                IFCExport mainWindow = new IFCExport(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);

                        // 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)
                        {
                            //TODO localization
                            TaskDialog taskDialog = new TaskDialog("Error exporting IFC file");
                            taskDialog.MainInstruction = "The IFC export process encountered an error.";
                            taskDialog.MainIcon        = TaskDialogIcon.TaskDialogIconWarning;
                            taskDialog.Show();
                        }

                        // Always roll back the transaction started earlier
                        transaction.RollBack();

                        // Remember last successful export location
                        m_mruExportPath = path;
                    }
                }
                if (mainWindow.Result == IFCExportResult.SaveSettings || mainWindow.Result == IFCExportResult.ExportAndSaveSettings)
                {
                    configurationsMap = mainWindow.GetModifiedConfigurations();
                    configurationsMap.UpdateSavedConfigurations(doc);

                    // Remember last selected configuration
                    m_mruConfiguration = mainWindow.GetSelectedConfiguration().Name;
                }
            }
            catch (Exception e)
            {
                //TODO localization
                TaskDialog taskDialog = new TaskDialog("Error exporting IFC file");
                taskDialog.MainInstruction = "The IFC export process encountered an error.";
                taskDialog.MainIcon        = TaskDialogIcon.TaskDialogIconWarning;
                taskDialog.ExpandedContent = e.ToString();
                taskDialog.Show();
            }
        }
 /// <summary>
 /// Shows the IFC export setup window when clicking the buttonEditSetup.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">Event arguments that contains the event data.</param>
 private void buttonEditSetup_Click(object sender, RoutedEventArgs args)
 {
     IFCExportConfiguration selectedConfig = GetSelectedConfiguration();
     IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap(m_configMap);
     IFCExporterUIWindow editorWindow = new IFCExporterUIWindow(configurationsMap, selectedConfig.Name);
     editorWindow.ShowDialog();
     if (editorWindow.DialogResult.HasValue && editorWindow.DialogResult.Value)
     {
         IFCCommandOverrideApplication.PotentiallyUpdatedConfigurations = true;
         currentSelectedSetup.Items.Clear();
         m_configMap = configurationsMap;
         String selectedConfigName = editorWindow.GetSelectedConfigurationName();
         UpdateCurrentSelectedSetupCombo(selectedConfigName);
     }
 }
        /// <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);

                        // 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");

                        // 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");

                        // Roll back the transaction started earlier, unless certain options are set.
                        bool commitTransaction = (use2009BuildingStoreyGUIDs || selectedConfig.StoreIFCGUID);
                        
                        if (commitTransaction)
                            IFCStoredGUID.Clear();

                        bool result = doc.Export(path, fileName, exportOptions); // pass in the options here

                        if (!result)
                        {
                            //TODO localization
                            TaskDialog taskDialog = new TaskDialog("Error exporting IFC file");
                            taskDialog.MainInstruction = "The IFC export process encountered an error.";
                            taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning;
                            taskDialog.Show();
                        }

                        // Roll back the transaction started earlier, unless certain options are set.
                        if (commitTransaction)
                        {
                            foreach (KeyValuePair<ElementId, string> elementIdToGUID in IFCStoredGUID.ElementIdToGUID)
                            {
                                Element element = doc.GetElement(elementIdToGUID.Key);
                                if (element == null)
                                    continue;

                                BuiltInParameter builtInParameter = (element is ElementType) ? BuiltInParameter.IFC_TYPE_GUID : BuiltInParameter.IFC_GUID;
                                SetGUIDParameter(element, builtInParameter, elementIdToGUID.Value);
                            }

                            ProjectInfo projectInfo = doc.ProjectInformation;
                            if (projectInfo != null)
                            {
                                foreach (KeyValuePair<BuiltInParameter, string> elementIdToGUID in IFCStoredGUID.ProjectInfoParameterGUID)
                                {
                                    SetGUIDParameter(projectInfo, elementIdToGUID.Key, elementIdToGUID.Value);
                                }
                            }

                            transaction.Commit();
                        }
                        else
                            transaction.RollBack();
                        
                        // 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)
            {
                //TODO localization
                TaskDialog taskDialog = new TaskDialog("Error exporting IFC file");
                taskDialog.MainInstruction = "The IFC export process encountered an error.";
                taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning;
                taskDialog.ExpandedContent = e.ToString();
                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 setups to save into the document.
        /// </summary>
        public void UpdateSavedConfigurations(IFCExportConfigurationsMap initialConfigs)
        {
            // delete the old schema and the DataStorage.
            if (m_OldSchema == null)
            {
                m_OldSchema = Schema.Lookup(s_OldSchemaId);
            }
            if (m_OldSchema != null)
            {
                IList <DataStorage> oldSavedConfigurations = GetSavedConfigurations(m_OldSchema);
                if (oldSavedConfigurations.Count > 0)
                {
                    Transaction deleteTransaction = new Transaction(IFCCommandOverrideApplication.TheDocument,
                                                                    Properties.Resources.DeleteOldSetups);
                    try
                    {
                        deleteTransaction.Start(Properties.Resources.DeleteOldConfiguration);
                        List <ElementId> dataStorageToDelete = new List <ElementId>();
                        foreach (DataStorage dataStorage in oldSavedConfigurations)
                        {
                            dataStorageToDelete.Add(dataStorage.Id);
                        }
                        IFCCommandOverrideApplication.TheDocument.Delete(dataStorageToDelete);
                        deleteTransaction.Commit();
                    }
                    catch (System.Exception)
                    {
                        if (deleteTransaction.HasStarted())
                        {
                            deleteTransaction.RollBack();
                        }
                    }
                }
            }

            // delete the old schema and the DataStorage.
            if (m_mapSchema == null)
            {
                m_mapSchema = Schema.Lookup(s_mapSchemaId);
            }
            if (m_mapSchema != null)
            {
                IList <DataStorage> oldSavedConfigurations = GetSavedConfigurations(m_mapSchema);
                if (oldSavedConfigurations.Count > 0)
                {
                    Transaction deleteTransaction = new Transaction(IFCCommandOverrideApplication.TheDocument,
                                                                    Properties.Resources.DeleteOldSetups);
                    try
                    {
                        deleteTransaction.Start(Properties.Resources.DeleteOldConfiguration);
                        List <ElementId> dataStorageToDelete = new List <ElementId>();
                        foreach (DataStorage dataStorage in oldSavedConfigurations)
                        {
                            dataStorageToDelete.Add(dataStorage.Id);
                        }
                        IFCCommandOverrideApplication.TheDocument.Delete(dataStorageToDelete);
                        deleteTransaction.Commit();
                    }
                    catch (System.Exception)
                    {
                        if (deleteTransaction.HasStarted())
                        {
                            deleteTransaction.RollBack();
                        }
                    }
                }
            }

            // update the configurations to new map schema.
            if (m_jsonSchema == null)
            {
                m_jsonSchema = Schema.Lookup(s_jsonSchemaId);
            }

            // Are there any setups to save or resave?
            List <IFCExportConfiguration> setupsToSave = new List <IFCExportConfiguration>();

            foreach (IFCExportConfiguration configuration in m_configurations.Values)
            {
                // Store in-session settings in the cached in-session configuration
                if (configuration.IsInSession)
                {
                    IFCExportConfiguration.SetInSession(configuration);
                    continue;
                }

                // Only add to setupsToSave if it is a new or changed configuration
                if (initialConfigs.HasName(configuration.Name))
                {
                    if (!ConfigurationComparer.ConfigurationsAreEqual(initialConfigs[configuration.Name], configuration))
                    {
                        setupsToSave.Add(configuration);
                    }
                    else if (!configuration.IsBuiltIn)
                    {
                        setupsToSave.Add(configuration);
                    }
                }
                else
                {
                    setupsToSave.Add(configuration);
                }
            }

            // If there are no setups to save, and if the schema is not present (which means there are no
            // previously existing setups which might have been deleted) we can skip the rest of this method.
            if (setupsToSave.Count <= 0 && m_jsonSchema == null)
            {
                return;
            }

            if (m_jsonSchema == null)
            {
                SchemaBuilder builder = new SchemaBuilder(s_jsonSchemaId);
                builder.SetSchemaName("IFCExportConfigurationMap");
                builder.AddSimpleField(s_configMapField, typeof(String));
                m_jsonSchema = builder.Finish();
            }

            // It won't start any transaction if there is no change to the configurations
            if (setupsToSave.Count > 0)
            {
                // Overwrite all saved configs with the new list
                Transaction transaction = new Transaction(IFCCommandOverrideApplication.TheDocument, Properties.Resources.UpdateExportSetups);
                try
                {
                    transaction.Start(Properties.Resources.SaveConfigurationChanges);
                    IList <DataStorage> savedConfigurations = GetSavedConfigurations(m_jsonSchema);
                    int savedConfigurationCount             = savedConfigurations.Count <DataStorage>();
                    int savedConfigurationIndex             = 0;
                    foreach (IFCExportConfiguration configuration in setupsToSave)
                    {
                        DataStorage configStorage;
                        if (savedConfigurationIndex >= savedConfigurationCount)
                        {
                            configStorage = DataStorage.Create(IFCCommandOverrideApplication.TheDocument);
                        }
                        else
                        {
                            configStorage = savedConfigurations[savedConfigurationIndex];
                            savedConfigurationIndex++;
                        }

                        Entity mapEntity  = new Entity(m_jsonSchema);
                        string configData = configuration.SerializeConfigToJson();
                        mapEntity.Set <string>(s_configMapField, configData);
                        configStorage.SetEntity(mapEntity);
                    }

                    List <ElementId> elementsToDelete = new List <ElementId>();
                    for (; savedConfigurationIndex < savedConfigurationCount; savedConfigurationIndex++)
                    {
                        DataStorage configStorage = savedConfigurations[savedConfigurationIndex];
                        elementsToDelete.Add(configStorage.Id);
                    }
                    if (elementsToDelete.Count > 0)
                    {
                        IFCCommandOverrideApplication.TheDocument.Delete(elementsToDelete);
                    }

                    transaction.Commit();
                }
                catch (System.Exception)
                {
                    if (transaction.HasStarted())
                    {
                        transaction.RollBack();
                    }
                }
            }
        }
        /// <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);

                        // 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");

                        // 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");

                        // Roll back the transaction started earlier, unless certain options are set.
                        bool commitTransaction = (use2009BuildingStoreyGUIDs || selectedConfig.StoreIFCGUID);

                        if (commitTransaction)
                        {
                            IFCStoredGUID.Clear();
                        }

                        bool result = doc.Export(path, fileName, exportOptions); // pass in the options here

                        if (!result)
                        {
                            //TODO localization
                            TaskDialog taskDialog = new TaskDialog("Error exporting IFC file");
                            taskDialog.MainInstruction = "The IFC export process encountered an error.";
                            taskDialog.MainIcon        = TaskDialogIcon.TaskDialogIconWarning;
                            taskDialog.Show();
                        }

                        // Roll back the transaction started earlier, unless certain options are set.
                        if (commitTransaction)
                        {
                            foreach (KeyValuePair <ElementId, string> elementIdToGUID in IFCStoredGUID.ElementIdToGUID)
                            {
                                Element element = doc.GetElement(elementIdToGUID.Key);
                                if (element == null)
                                {
                                    continue;
                                }

                                BuiltInParameter builtInParameter = (element is ElementType) ? BuiltInParameter.IFC_TYPE_GUID : BuiltInParameter.IFC_GUID;
                                SetGUIDParameter(element, builtInParameter, elementIdToGUID.Value);
                            }

                            ProjectInfo projectInfo = doc.ProjectInformation;
                            if (projectInfo != null)
                            {
                                foreach (KeyValuePair <BuiltInParameter, string> elementIdToGUID in IFCStoredGUID.ProjectInfoParameterGUID)
                                {
                                    SetGUIDParameter(projectInfo, elementIdToGUID.Key, elementIdToGUID.Value);
                                }
                            }

                            transaction.Commit();
                        }
                        else
                        {
                            transaction.RollBack();
                        }

                        // 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)
            {
                //TODO localization
                TaskDialog taskDialog = new TaskDialog("Error exporting IFC file");
                taskDialog.MainInstruction = "The IFC export process encountered an error.";
                taskDialog.MainIcon        = TaskDialogIcon.TaskDialogIconWarning;
                taskDialog.ExpandedContent = e.ToString();
                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;

                IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap();
                configurationsMap.Add(IFCExportConfiguration.GetInSession());
                configurationsMap.AddBuiltInConfigurations();
                configurationsMap.AddSavedConfigurations(doc);

                String mruSelection = null;
                if (m_mruConfiguration != null && configurationsMap.HasName(m_mruConfiguration))
                    mruSelection =  m_mruConfiguration;

                IFCExport mainWindow = new IFCExport(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);

                        // 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)
                        {
                            //TODO localization
                            TaskDialog taskDialog = new TaskDialog("Error exporting IFC file");
                            taskDialog.MainInstruction = "The IFC export process encountered an error.";
                            taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning;
                            taskDialog.Show();
                        }

                        // Always roll back the transaction started earlier
                        transaction.RollBack();

                        // Remember last successful export location
                        m_mruExportPath = path;    
                    }      
                }
                if (mainWindow.Result == IFCExportResult.SaveSettings || mainWindow.Result == IFCExportResult.ExportAndSaveSettings)
                {
                    configurationsMap = mainWindow.GetModifiedConfigurations();
                    configurationsMap.UpdateSavedConfigurations(doc);

                    // Remember last selected configuration
                    m_mruConfiguration = mainWindow.GetSelectedConfiguration().Name;
                }
            }
            catch (Exception e)
            {
                //TODO localization
                TaskDialog taskDialog = new TaskDialog("Error exporting IFC file");
                taskDialog.MainInstruction = "The IFC export process encountered an error.";
                taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning;
                taskDialog.ExpandedContent = e.ToString();
                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();
                }
            }
        }
        /// <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();
                }
            }
        }