示例#1
0
        private static void StoreIFCCreatorInfo(IFCFile ifcFile, ProjectInfo projectInfo)
        {
            if (ifcFile == null || projectInfo == null)
            {
                return;
            }

            IList <IFCAnyHandle> applications = ifcFile.GetInstances(IFCAnyHandleUtil.GetIFCEntityTypeName(IFCEntityType.IfcApplication), false);
            IFCAnyHandle         application  = applications.FirstOrDefault();

            if (application != null)
            {
                var appFullName = IFCAnyHandleUtil.GetStringAttribute(application, "ApplicationFullName");
                if (!string.IsNullOrEmpty(appFullName))
                {
                    var applicationNameId = new ElementId(BuiltInParameter.IFC_APPLICATION_NAME);
                    ExporterIFCUtils.AddValueString(projectInfo, applicationNameId, appFullName);
                }

                var appVersion = IFCAnyHandleUtil.GetStringAttribute(application, "Version");
                if (!string.IsNullOrEmpty(appVersion))
                {
                    var applicationVersionId = new ElementId(BuiltInParameter.IFC_APPLICATION_VERSION);
                    ExporterIFCUtils.AddValueString(projectInfo, applicationVersionId, appVersion);
                }
            }

            IList <IFCAnyHandle> organisations = ifcFile.GetInstances(IFCAnyHandleUtil.GetIFCEntityTypeName(IFCEntityType.IfcOrganization), false);
            IFCAnyHandle         organisation  = organisations.LastOrDefault();

            if (organisation != null)
            {
                var orgName = IFCAnyHandleUtil.GetStringAttribute(organisation, "Name");
                if (!string.IsNullOrEmpty(orgName))
                {
                    var organizationId = new ElementId(BuiltInParameter.IFC_ORGANIZATION);
                    ExporterIFCUtils.AddValueString(projectInfo, organizationId, orgName);
                }
            }
        }
示例#2
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;
                }
            }
        }
示例#3
0
 /// <summary>
 /// Gets instances of an entity type from an IFC file.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="includeSubTypes">True to retrieve instances of sub types.</param>
 /// <returns>The instance handles.</returns>
 public IList <IFCAnyHandle> GetInstances(IFCEntityType type, bool includeSubTypes)
 {
     return(m_IfcFile.GetInstances(IFCAnyHandleUtil.GetIFCEntityTypeName(type), includeSubTypes));
 }