/// <summary>
        /// Gets the IFC Schema version for a model
        /// </summary>
        /// <param name="modelPath">Path to a model in any supported format (IFC, IfcXml, IfcZip, or XBIM)</param>
        /// <returns></returns>
        public override XbimSchemaVersion GetXbimSchemaVersion(string modelPath)
        {
            var storageType = modelPath.StorageType();

            if (storageType == StorageType.Invalid)
            {
                return(XbimSchemaVersion.Unsupported);
            }
            if (storageType != StorageType.Xbim)
            {
                return(MemoryModel.GetSchemaVersion(modelPath));
            }

            // Have to use Esent for internal format
            var            stepHeader       = EsentModel.GetStepFileHeader(modelPath);
            IList <string> schemas          = stepHeader.FileSchema.Schemas;
            var            schemaIdentifier = string.Join(", ", schemas);

            foreach (var schema in schemas)
            {
                if (string.Compare(schema, "Ifc4", StringComparison.OrdinalIgnoreCase) == 0 ||
                    schema.StartsWith("Ifc4RC", StringComparison.OrdinalIgnoreCase))
                {
                    return(XbimSchemaVersion.Ifc4);
                }
                if (string.Compare(schema, "Ifc4x1", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(XbimSchemaVersion.Ifc4x1);
                }
                if (string.Compare(schema, "Ifc2x3", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(XbimSchemaVersion.Ifc2X3);
                }
                if (schema.StartsWith("Ifc2x", StringComparison.OrdinalIgnoreCase)) //return this as 2x3
                {
                    return(XbimSchemaVersion.Ifc2X3);
                }
            }

            return(XbimSchemaVersion.Unsupported);
        }
示例#2
0
        public static void Run()
        {
            const string   file    = "SampleModel.ifc";
            const string   db      = "sample.xbim";
            var            schema  = MemoryModel.GetSchemaVersion(file);
            IEntityFactory factory = null;

            switch (schema)
            {
            case XbimSchemaVersion.Ifc4:
                factory = new Xbim.Ifc4.EntityFactoryIfc4();
                break;

            case XbimSchemaVersion.Ifc4x1:
                factory = new Xbim.Ifc4.EntityFactoryIfc4x1();
                break;

            case XbimSchemaVersion.Ifc2X3:
                factory = new Xbim.Ifc2x3.EntityFactoryIfc2x3();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(schema));
            }
            using (var model = new EsentModel(factory))
            {
                model.CreateFrom(file, db);
                model.Close();
            }

            IfcStore.ModelProviderFactory.UseEsentModelProvider();
            using (var model = IfcStore.Open(db))
            {
                // ... do anything you need to do ...
            }
        }