Beispiel #1
0
        /// <summary>
        /// The main entry point into the .NET IFC import code
        /// </summary>
        /// <param name="importer">The internal ImporterIFC class that contains information necessary for the import process.</param>
        public void ImportIFC(ImporterIFC importer)
        {
            TheImporter = this;

            IDictionary <String, String> options = importer.GetOptions();

            TheOptions = m_ImportOptions = IFCImportOptions.Create(options);

            // An early check, based on the options set - if we are allowed to use an up-to-date existing file on disk, use it.
            try
            {
                string fullIFCFileName = importer.FullFileName;
                if (!TheOptions.ForceImport && !NeedsReload(importer.Document, fullIFCFileName))
                {
                    return;
                }

                // Clear the category mapping table, to force reload of options.
                IFCCategoryUtil.Clear();

                if (TheOptions.Intent != IFCImportIntent.Reference)
                {
                    IFCImportFile.Import(importer);
                }
                else
                {
                    ReferenceIFC(importer.Document, fullIFCFileName, options);
                }
            }
            catch (Exception ex)
            {
                if (Importer.TheLog != null)
                {
                    Importer.TheLog.LogError(-1, ex.Message, false);
                }
                // The following message can sometimes occur when reloading some IFC files
                // from external resources.  In this case, we should silently fail, and not
                // throw.
                if (!ex.Message.Contains("Starting a new transaction is not permitted"))
                {
                    throw;
                }
            }
            finally
            {
                if (Importer.TheLog != null)
                {
                    Importer.TheLog.Close();
                }
                if (IFCImportFile.TheFile != null)
                {
                    IFCImportFile.TheFile.Close();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// The main entry point into the .NET IFC import code
        /// </summary>
        /// <param name="importer">The internal ImporterIFC class that contains information necessary for the import process.</param>
        public void ImportIFC(ImporterIFC importer)
        {
            TheImporter = this;

            IDictionary <String, String> options = importer.GetOptions();

            TheOptions = m_ImportOptions = IFCImportOptions.Create(options);

            // An early check, based on the options set - if we are allowed to use an up-to-date existing file on disk, use it.
            try
            {
                string fullFileName = importer.FullFileName;

                string revitFileName = IFCImportFile.GetRevitFileName(fullFileName);
                if (!TheOptions.ForceImport && !NeedsReload(fullFileName, revitFileName))
                {
                    return;
                }

                // Clear the category mapping table, to force reload of options.
                IFCCategoryUtil.Clear();

                if (TheOptions.Intent != IFCImportIntent.Reference)
                {
                    IFCImportFile.Import(importer);
                }
                else
                {
                    ReferenceIFC(importer.Document, fullFileName, options);
                }
            }
            catch (Exception ex)
            {
                if (Importer.TheLog != null)
                {
                    Importer.TheLog.LogError(-1, ex.Message, false);
                }
            }
            finally
            {
                if (Importer.TheLog != null)
                {
                    Importer.TheLog.Close();
                }
                if (IFCImportFile.TheFile != null)
                {
                    IFCImportFile.TheFile.Close();
                }
            }
        }
Beispiel #3
0
        public void ImportIFC(ImporterIFC importer)
        {
            TheImporter = this;

            IDictionary <String, String> options = importer.GetOptions();

            TheOptions = m_ImportOptions = IFCImportOptions.Create(options);

            // An early check, based on the options set - if we are allowed to use an up-to-date existing file on disk, use it.
            try
            {
                string revitFileName = IFCImportFile.GetRevitFileName(importer.FullFileName);
                if (!TheOptions.ForceImport && !NeedsReload(importer.FullFileName, revitFileName))
                {
                    return;
                }

                // Clear the category mapping table, to force reload of options.
                IFCCategoryUtil.Clear();

                if (TheOptions.Intent != IFCImportIntent.Reference)
                {
                    IFCImportFile.Import(importer);
                }
                else
                {
                    Document originalDocument = importer.Document;
                    Document ifcDocument      = null;

                    if (TheOptions.Action == IFCImportAction.Link)
                    {
                        string linkedFileName = IFCImportFile.GetRevitFileName(importer.FullFileName);

                        ifcDocument = LoadOrCreateLinkDocument(originalDocument, linkedFileName);
                        if (ifcDocument == null)
                        {
                            return;
                        }
                    }
                    else
                    {
                        ifcDocument = originalDocument;
                    }

                    bool useCachedRevitFile = DocumentUpToDate(ifcDocument, importer.FullFileName);

                    // In the case where the document is already opened as a link, but it has been updated on disk,
                    // give the user a warning and use the cached value.
                    if (!useCachedRevitFile && ifcDocument.IsLinked)
                    {
                        useCachedRevitFile = true;
                        Importer.AddDelayedLinkError(BuiltInFailures.ImportFailures.IFCCantUpdateLinkedFile);
                    }

                    if (!useCachedRevitFile)
                    {
                        m_ImportCache = IFCImportCache.Create(ifcDocument, importer.FullFileName);

                        // Limit creating the cache to Link, but may either remove limiting or make it more restrict (reload only) later.
                        if (TheOptions.Action == IFCImportAction.Link)
                        {
                            TheCache.CreateExistingElementMaps(ifcDocument);
                        }

                        // TheFile will contain the same value as the return value for this function.
                        IFCImportFile.Create(importer.FullFileName, m_ImportOptions, ifcDocument);
                    }

                    if (useCachedRevitFile || IFCImportFile.TheFile != null)
                    {
                        if (IFCImportFile.TheFile != null)
                        {
                            if (IFCImportFile.TheFile.IFCProject != null)
                            {
                                IFCObjectDefinition.CreateElement(ifcDocument, IFCImportFile.TheFile.IFCProject);
                            }
                            IFCImportFile.TheFile.EndImport(ifcDocument, importer.FullFileName);
                        }

                        if (TheOptions.Action == IFCImportAction.Link)
                        {
                            // If we have an original Revit link file name, don't create a new RvtLinkSymbol -
                            // we will use the existing one.
                            bool useExistingType = (TheOptions.RevitLinkFileName != null);
                            IFCImportFile.LinkInFile(importer.FullFileName, ifcDocument, originalDocument, useExistingType, !useCachedRevitFile);
                        }
                    }

                    m_ImportCache.Reset(ifcDocument);
                }
            }
            catch (Exception ex)
            {
                if (IFCImportFile.TheFile != null)
                {
                    IFCImportFile.TheFile.Log.LogError(-1, ex.Message, false);
                }
            }
            finally
            {
                if (IFCImportFile.TheFile != null)
                {
                    IFCImportFile.TheFile.Close();
                }
            }
        }