Esempio n. 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();
        }
Esempio n. 2
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() + ")";
        }
        /// <summary>
        /// Updates the IFCExportOptions with the settings in this configuration.
        /// </summary>
        /// <param name="options">The IFCExportOptions to update.</param>
        /// <param name="filterViewId">The id of the view that will be used to select which elements to export.</param>
        public void UpdateOptions(IFCExportOptions options, ElementId filterViewId)
        {
            options.FileVersion            = IFCVersion;
            options.SpaceBoundaryLevel     = SpaceBoundaries;
            options.ExportBaseQuantities   = ExportBaseQuantities;
            options.WallAndColumnSplitting = SplitWallsAndColumns;
            options.FilterViewId           = VisibleElementsOfCurrentView ? filterViewId : ElementId.InvalidElementId;
            options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString());
            options.AddOption("ExportIFCCommonPropertySets", ExportIFCCommonPropertySets.ToString());
            options.AddOption("ExportAnnotations", Export2DElements.ToString());
            options.AddOption("Use2DRoomBoundaryForVolume", Use2DRoomBoundaryForVolume.ToString());
            options.AddOption("UseFamilyAndTypeNameForReference", UseFamilyAndTypeNameForReference.ToString());
            options.AddOption("ExportVisibleElementsInView", VisibleElementsOfCurrentView.ToString());
            options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString());
            options.AddOption("UseActiveViewGeometry", UseActiveViewGeometry.ToString());
            options.AddOption("ExportSpecificSchedules", ExportSpecificSchedules.ToString());
            options.AddOption("ExportBoundingBox", ExportBoundingBox.ToString());
            options.AddOption("ExportSolidModelRep", ExportSolidModelRep.ToString());
            options.AddOption("ExportSchedulesAsPsets", ExportSchedulesAsPsets.ToString());
            options.AddOption("ExportUserDefinedPsets", ExportUserDefinedPsets.ToString());
            options.AddOption("ExportUserDefinedParameterMapping", ExportUserDefinedParameterMapping.ToString());
            options.AddOption("ExportLinkedFiles", ExportLinkedFiles.ToString());
            options.AddOption("IncludeSiteElevation", IncludeSiteElevation.ToString());
            options.AddOption("SitePlacement", SitePlacement.ToString());
            options.AddOption("TessellationLevelOfDetail", TessellationLevelOfDetail.ToString());
            options.AddOption("UseOnlyTriangulation", UseOnlyTriangulation.ToString());
            options.AddOption("ActiveViewId", ActiveViewId.ToString());
            options.AddOption("StoreIFCGUID", StoreIFCGUID.ToString());

            // The active phase may not be valid if we are exporting multiple projects. However, if projects share a template that defines the phases,
            // then the ActivePhaseId would likely be valid for all.  There is some small chance that the ActivePhaseId would be a valid, but different, phase
            // in different projects, but that is unlikely enough that it seems worth warning against it but allowing the better functionality in general.
            if (IFCPhaseAttributes.Validate(ActivePhaseId))
            {
                options.AddOption("ActivePhase", ActivePhaseId.ToString());
            }

            options.AddOption("FileType", IFCFileType.ToString());
            string uiVersion = IFCUISettings.GetAssemblyVersion();

            options.AddOption("AlternateUIVersion", uiVersion);

            options.AddOption("ConfigName", Name);   // Add config name into the option for use in the exporter
            options.AddOption("ExportUserDefinedPsetsFileName", ExportUserDefinedPsetsFileName);
            options.AddOption("ExportUserDefinedParameterMappingFileName", ExportUserDefinedParameterMappingFileName);
            options.AddOption("ExportRoomsInView", ExportRoomsInView.ToString());
            options.AddOption("ExcludeFilter", ExcludeFilter.ToString());
            options.AddOption("COBieCompanyInfo", COBieCompanyInfo);
            options.AddOption("COBieProjectInfo", COBieProjectInfo);
            options.AddOption("IncludeSteelElements", IncludeSteelElements.ToString());
            options.AddOption("UseTypeNameOnlyForIfcType", UseTypeNameOnlyForIfcType.ToString());
            options.AddOption("UseVisibleRevitNameAsEntityName", UseVisibleRevitNameAsEntityName.ToString());
        }
Esempio n. 4
0
        /// <summary>
        /// Restores the previous window. If no previous window found, place on the left top.
        /// </summary>
        private void RestorePreviousWindow()
        {
            // Refresh restore bounds from previous window opening
            Rect restoreBounds = IFCUISettings.LoadWindowBounds(m_SettingFile);

            if (restoreBounds != new Rect())
            {
                this.Left   = restoreBounds.Left;
                this.Top    = restoreBounds.Top;
                this.Width  = restoreBounds.Width;
                this.Height = restoreBounds.Height;
            }
        }
Esempio n. 5
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() + ")";
        }
        /// <summary>
        /// Updates the IFCExportOptions with the settings in this configuration.
        /// </summary>
        /// <param name="options">The IFCExportOptions to update.</param>
        /// <param name="filterViewId">The filter view.</param>
        public void UpdateOptions(IFCExportOptions options, ElementId filterViewId)
        {
            options.FileVersion            = IFCVersion;
            options.SpaceBoundaryLevel     = SpaceBoundaries;
            options.ExportBaseQuantities   = ExportBaseQuantities;
            options.WallAndColumnSplitting = SplitWallsAndColumns;
            if (VisibleElementsOfCurrentView)
            {
                options.FilterViewId = filterViewId;
            }
            else
            {
                options.FilterViewId = ElementId.InvalidElementId;
            }
            options.AddOption("ExportInternalRevitPropertySets", ExportInternalRevitPropertySets.ToString());
            options.AddOption("ExportIFCCommonPropertySets", ExportIFCCommonPropertySets.ToString());
            options.AddOption("ExportAnnotations", Export2DElements.ToString());
            options.AddOption("Use2DRoomBoundaryForVolume", Use2DRoomBoundaryForVolume.ToString());
            options.AddOption("UseFamilyAndTypeNameForReference", UseFamilyAndTypeNameForReference.ToString());
            options.AddOption("ExportVisibleElementsInView", VisibleElementsOfCurrentView.ToString());
            options.AddOption("ExportPartsAsBuildingElements", ExportPartsAsBuildingElements.ToString());
            options.AddOption("ExportBoundingBox", ExportBoundingBox.ToString());
            options.AddOption("ExportSolidModelRep", ExportSolidModelRep.ToString());
            options.AddOption("ExportSchedulesAsPsets", ExportSchedulesAsPsets.ToString());
            options.AddOption("ExportUserDefinedPsets", ExportUserDefinedPsets.ToString());
            options.AddOption("ExportLinkedFiles", ExportLinkedFiles.ToString());
            options.AddOption("IncludeSiteElevation", IncludeSiteElevation.ToString());
            options.AddOption("UseCoarseTessellation", UseCoarseTessellation.ToString());
            options.AddOption("TessellationLevelOfDetail", TessellationLevelOfDetail.ToString());
            options.AddOption("StoreIFCGUID", StoreIFCGUID.ToString());
            options.AddOption("ActivePhase", ActivePhaseId.ToString());

            options.AddOption("FileType", IFCFileType.ToString());
            string uiVersion = IFCUISettings.GetAssemblyVersion();

            options.AddOption("AlternateUIVersion", uiVersion);

            options.AddOption("ConfigName", Name);      // Add config name into the option for use in the exporter
            options.AddOption("ExportUserDefinedPsetsFileName", ExportUserDefinedPsetsFileName);

            options.AddOption("ExportRoomsInView", ExportRoomsInView.ToString());
        }
Esempio n. 7
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();
        }
Esempio n. 8
0
 /// <summary>
 /// Saves the window bounds when close the window.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">Event arguments that contains the event data.</param>
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     // Save restore bounds for the next time this window is opened
     IFCUISettings.SaveWindowBounds(m_SettingFile, this.RestoreBounds);
 }
Esempio n. 9
0
        /// <summary>
        /// Generate the file name for export.
        /// If the number of documents to export is greater than 1, export as Multiple Files.
        /// </summary>
        private String GetFileName()
        {
            int    docToExport   = GetDocumentExportCount();
            bool   multipleFiles = docToExport > 1;
            String fileName      = multipleFiles ? Properties.Resources.MultipleFiles : IFCUISettings.GenerateFileNameFromDocument(DocumentsToExport[0], null);

            return(fileName);
        }
Esempio n. 10
0
        /// <summary>
        /// Updates the IFCExportOptions with the settings in this configuration.
        /// </summary>
        /// <param name="options">The IFCExportOptions to update.</param>
        /// <param name="filterViewId">The id of the view that will be used to select which elements to export.</param>
        public void UpdateOptions(IFCExportOptions options, ElementId filterViewId)
        {
            JavaScriptSerializer ser = new JavaScriptSerializer();

            foreach (var prop in GetType().GetProperties())
            {
                switch (prop.Name)
                {
                case "Name":
                    options.AddOption("ConfigName", Name);    // Add config name into the option for use in the exporter
                    break;

                case "IFCVersion":
                    options.FileVersion = IFCVersion;
                    break;

                case "ActivePhaseId":
                    if (IFCPhaseAttributes.Validate(ActivePhaseId))
                    {
                        options.AddOption(prop.Name, ActivePhaseId.ToString());
                    }
                    break;

                case "SpaceBoundaries":
                    options.SpaceBoundaryLevel = SpaceBoundaries;
                    break;

                case "SplitWallsAndColumns":
                    options.WallAndColumnSplitting = SplitWallsAndColumns;
                    break;

                case "ExportBaseQuantities":
                    options.ExportBaseQuantities = ExportBaseQuantities;
                    break;

                case "ProjectAddress":
                    string projectAddrJsonString = ser.Serialize(ProjectAddress);
                    options.AddOption(prop.Name, projectAddrJsonString);
                    break;

                case "ClassificationSettings":
                    string classificationJsonStr = ser.Serialize(ClassificationSettings);
                    options.AddOption(prop.Name, classificationJsonStr);
                    break;

                default:
                    var propVal = prop.GetValue(this, null);
                    if (propVal != null)
                    {
                        options.AddOption(prop.Name, propVal.ToString());
                    }
                    break;
                }
            }

            options.FilterViewId = VisibleElementsOfCurrentView ? filterViewId : ElementId.InvalidElementId;

            string uiVersion = IFCUISettings.GetAssemblyVersion();

            options.AddOption("AlternateUIVersion", uiVersion);
        }
        /// <summary>
        /// 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();
                }
            }
        }