Example #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();
                }
            }
        }
Example #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();
                }
            }
        }
Example #3
0
        /// <summary>
        /// Do a Parametric import operation.
        /// </summary>
        /// <param name="importer">The internal ImporterIFC class that contains necessary information for the import.</param>
        /// <remarks>This is a thin wrapper to the native code that still handles Open IFC.  This should be eventually obsoleted.</remarks>
        public static void Import(ImporterIFC importer)
        {
            IFCFile ifcFile = null;

            try
            {
                IFCSchemaVersion schemaVersion = IFCSchemaVersion.IFC2x3;
                ifcFile = CreateIFCFile(importer.FullFileName, out schemaVersion);

                IFCFileReadOptions readOptions = new IFCFileReadOptions();
                readOptions.FileName          = importer.FullFileName;
                readOptions.XMLConfigFileName = Path.Combine(DirectoryUtil.RevitProgramPath, "EDM\\ifcXMLconfiguration.xml");

                ifcFile.Read(readOptions);
                importer.SetFile(ifcFile);

                //If there is more than one project, we will be ignoring all but the first one.
                IList <IFCAnyHandle> projects = ifcFile.GetInstances(IFCAnyHandleUtil.GetIFCEntityTypeName(IFCEntityType.IfcProject), false);
                if (projects.Count == 0)
                {
                    throw new InvalidOperationException("Failed to import IFC to Revit.");
                }

                IFCAnyHandle project = projects[0];

                importer.ProcessIFCProject(project);

                StoreIFCCreatorInfo(ifcFile, importer.Document.ProjectInformation);
            }
            finally
            {
                if (ifcFile != null)
                {
                    ifcFile.Close();
                    ifcFile = null;
                }
            }
        }
      /// <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();
         }
      }
Example #5
0
        //should be removed when all handles are processed in .NET
        public static void Import(ImporterIFC importer)
        {
            IFCFile ifcFile = null;

            try
            {
                IFCSchemaVersion schemaVersion = IFCSchemaVersion.IFC2x3;
                ifcFile = CreateIFCFile(importer.FullFileName, out schemaVersion);
                
                IFCFileReadOptions readOptions = new IFCFileReadOptions();
                readOptions.FileName = importer.FullFileName;
                readOptions.XMLConfigFileName = Path.Combine(RevitProgramPath, "EDM\\ifcXMLconfiguration.xml");

                ifcFile.Read(readOptions);
                importer.SetFile(ifcFile);

                //If there is more than one project, we will be ignoring all but the first one.
                IList<IFCAnyHandle> projects = ifcFile.GetInstances(IFCAnyHandleUtil.GetIFCEntityTypeName(IFCEntityType.IfcProject), false);
                if (projects.Count == 0)
                    throw new InvalidOperationException("Failed to import IFC to Revit.");

                IFCAnyHandle project = projects[0];
                
                importer.ProcessIFCProject(project);
            }
            finally
            {
                if (ifcFile != null)
                {
                    ifcFile.Close();
                    ifcFile = null;
                }
            }
        }
Example #6
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();
            }
        }
Example #7
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();
                }
            }
        }