コード例 #1
0
ファイル: Exporter.cs プロジェクト: whztt07/BIM-IFC
        /// <summary>
        /// Initializes the common properties at the beginning of the export process.
        /// </summary>
        /// <param name="exporterIFC">The IFC exporter object.</param>
        /// <param name="document">The document to export.</param>
        private void BeginExport(ExporterIFC exporterIFC, Document document)
        {
            ExporterCacheManager.Document = document;
            String writeIFCExportedElementsVar = Environment.GetEnvironmentVariable("WriteIFCExportedElements");
            if (writeIFCExportedElementsVar != null && writeIFCExportedElementsVar.Length > 0)
            {
                m_Writer = new StreamWriter(@"c:\ifc-output-filters.txt");
            }

            IFCFileModelOptions modelOptions = new IFCFileModelOptions();
            if (exporterIFC.ExportAs2x2)
            {
                modelOptions.SchemaFile = Path.Combine(ExporterUtil.RevitProgramPath, "EDM\\IFC2X2_ADD1.exp");
                modelOptions.SchemaName = "IFC2x2_FINAL";
            }
            else
            {
                modelOptions.SchemaFile = Path.Combine(ExporterUtil.RevitProgramPath, "EDM\\IFC2X3_TC1.exp");
                modelOptions.SchemaName = "IFC2x3";
            }

            m_IfcFile = IFCFile.Create(modelOptions);
            exporterIFC.SetFile(m_IfcFile);

            //init common properties
            ExporterInitializer.InitPropertySets(ExporterCacheManager.ExportOptionsCache.FileVersion);
            ExporterInitializer.InitQuantities(ExporterCacheManager.ExportOptionsCache.FileVersion, ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities);

            IFCFile file = exporterIFC.GetFile();
            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                // create building
                IFCAnyHandle applicationHandle = CreateApplicationInformation(file, document.Application);

                CreateGlobalCartesianOrigin(exporterIFC);
                CreateGlobalDirection(exporterIFC);
                CreateGlobalDirection2D(exporterIFC);

                IFCAnyHandle units = CreateDefaultUnits(exporterIFC, document);

                // Start out relative to nothing, but replace with site later.
                IFCAnyHandle relativePlacement = ExporterUtil.CreateAxis2Placement3D(file);
                IFCAnyHandle buildingPlacement = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement);

                HashSet<IFCAnyHandle> repContexts = CreateContextInformation(exporterIFC, document);
                IFCAnyHandle ownerHistory = CreateGenericOwnerHistory(exporterIFC, document, applicationHandle);
                exporterIFC.SetOwnerHistoryHandle(ownerHistory);

                IFCAnyHandle projectHandle = IFCInstanceExporter.CreateProject(file,
                    ExporterIFCUtils.CreateProjectLevelGUID(document, IFCProjectLevelGUIDType.Project), ownerHistory,
                    null, null, null, null, null, repContexts, units);
                exporterIFC.SetProject(projectHandle);

                ProjectInfo projInfo = document.ProjectInformation;
                string projectAddress = projInfo != null ? projInfo.Address : String.Empty;
                SiteLocation siteLoc = document.ActiveProjectLocation.SiteLocation;
                string location = siteLoc != null ? siteLoc.PlaceName : String.Empty;

                if (projectAddress == null)
                    projectAddress = String.Empty;
                if (location == null)
                    location = String.Empty;

                IFCAnyHandle buildingAddress = CreateIFCAddress(file, projectAddress, location);

                string buildingName = String.Empty;
                if (projInfo != null)
                {
                    try
                    {
                        buildingName = projInfo.BuildingName;
                    }
                    catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                    {
                    }
                }

                IFCAnyHandle buildingHandle = IFCInstanceExporter.CreateBuilding(file,
                    ExporterIFCUtils.CreateProjectLevelGUID(document, IFCProjectLevelGUIDType.Building),
                    ownerHistory, buildingName, null, null, buildingPlacement, null, buildingName,
                    Toolkit.IFCElementComposition.Element, null, null, buildingAddress);
                exporterIFC.SetBuilding(buildingHandle);

                // create levels
                List<Level> levels = LevelUtil.FindAllLevels(document);

                bool exportAllLevels = true;
                for (int ii = 0; ii < levels.Count && exportAllLevels; ii++)
                {
                    Level level = levels[ii];
                    Parameter isBuildingStorey = level.get_Parameter(BuiltInParameter.LEVEL_IS_BUILDING_STORY);
                    if (isBuildingStorey == null || (isBuildingStorey.AsInteger() != 0))
                    {
                        exportAllLevels = false;
                        break;
                    }
                }

                IList<Element> unassignedBaseLevels = new List<Element>();

                ExporterCacheManager.ExportOptionsCache.ExportAllLevels = exportAllLevels;
                double scaleFactor = exporterIFC.LinearScale;
                    
                IFCAnyHandle prevBuildingStorey = null;
                IFCAnyHandle prevPlacement = null;
                double prevHeight = 0.0;
                double prevElev = 0.0;

                for (int ii = 0; ii < levels.Count; ii++)
                {
                    Level level = levels[ii];
                    if (level == null)
                        continue;

                    IFCLevelInfo levelInfo = null;

                    if (!LevelUtil.IsBuildingStory(level))
                    {
                        if (prevBuildingStorey == null)
                            unassignedBaseLevels.Add(level);
                        else
                        {
                            levelInfo = IFCLevelInfo.Create(prevBuildingStorey, prevPlacement, prevHeight, prevElev, scaleFactor, true);
                            ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo);
                        }
                        continue;
                    }

                    // When exporting to IFC 2x3, we have a limited capability to export some Revit view-specific
                    // elements, specifically Filled Regions and Text.  However, we do not have the
                    // capability to choose which views to export.  As such, we will choose (up to) one DBView per
                    // exported level.
                    // TODO: Let user choose which view(s) to export.  Ensure that the user know that only one view
                    // per level is supported.
                    View view = LevelUtil.FindViewByLevel(document, ViewType.FloorPlan, level);
                    if (view != null)
                    {
                        exporterIFC.AddViewIdToExport(view.Id, level.Id);
                    }

                    double elev = level.ProjectElevation;
                    double height = 0.0;
                    List<ElementId> coincidentLevels = new List<ElementId>();
                    for (int jj = ii+1; jj < levels.Count; jj++)
                    {
                        Level nextLevel = levels[jj];
                        if (!LevelUtil.IsBuildingStory(nextLevel))
                            continue;

                        double nextElev = nextLevel.ProjectElevation;
                        if (!MathUtil.IsAlmostEqual(nextElev, elev))
                        {
                            height = nextElev - elev;
                            break;
                        }
                        else if (ExporterCacheManager.ExportOptionsCache.WallAndColumnSplitting)
                            coincidentLevels.Add(nextLevel.Id);
                    }

                    double elevation = elev * scaleFactor;
                    XYZ orig = new XYZ(0.0, 0.0, elevation);

                    IFCAnyHandle axis2Placement3D = ExporterUtil.CreateAxis2Placement3D(file, orig);
                    IFCAnyHandle placement = IFCInstanceExporter.CreateLocalPlacement(file, buildingPlacement, axis2Placement3D);
                    string levelName = level.Name;
                    string levelGUID = LevelUtil.GetLevelGUID(level);
                    IFCAnyHandle buildingStorey = IFCInstanceExporter.CreateBuildingStorey(file,
                        levelGUID, exporterIFC.GetOwnerHistoryHandle(),
                        levelName, null, null, placement,
                        null, levelName, Toolkit.IFCElementComposition.Element, elevation);

                    // If we are using the R2009 Level GUIDs, write it to a shared paramter in the file to ensure that it is preserved.
                    if (ExporterCacheManager.ExportOptionsCache.Use2009BuildingStoreyGUIDs)
                    {
                        string oldLevelGUID;
                        ParameterUtil.GetStringValueFromElement(level, BuiltInParameter.IFC_GUID, out oldLevelGUID);
                        if (String.IsNullOrEmpty(oldLevelGUID))
                        {
                            ParameterUtil.SetStringParameter(level, BuiltInParameter.IFC_GUID, levelGUID);
                        }
                    }

                    if (prevBuildingStorey == null)
                    {
                        foreach (Level baseLevel in unassignedBaseLevels)
                        {
                            levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, scaleFactor, true);
                            ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, baseLevel.Id, levelInfo);
                        }
                    }
                    prevBuildingStorey = buildingStorey;
                    prevPlacement = placement;
                    prevHeight = height;
                    prevElev = elev;

                    levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, scaleFactor, true);
                    ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo);

                    // if we have coincident levels, add buildingstoreys for them but use the old handle.
                    for (int jj = 0; jj < coincidentLevels.Count; jj++)
                    {
                        level = levels[ii + jj + 1];
                        levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, scaleFactor, true);
                        ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo);
                    }

                    ii += coincidentLevels.Count;
                }
                transaction.Commit();
            }
        }
コード例 #2
0
ファイル: Exporter.cs プロジェクト: whztt07/RevitIFC
        /// <summary>
        /// Creates the IfcProject.
        /// </summary>
        /// <param name="exporterIFC">The IFC exporter object.</param>
        /// <param name="doc">The document provides the owner information.</param>
        /// <param name="application">The handle of IFC file to create the owner history.</param>
        private void CreateProject(ExporterIFC exporterIFC, Document doc, IFCAnyHandle application)
        {
            string familyName;
            string givenName;
            List<string> middleNames;
            List<string> prefixTitles;
            List<string> suffixTitles;

            string author = String.Empty;
            ProjectInfo projectInfo = doc.ProjectInformation;
            if (projectInfo != null)
            {
                try
                {
                    author = projectInfo.Author;
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                {
                    //if failed to get author from project info, try to get the username from application later.
                }
            }

            if (String.IsNullOrEmpty(author))
            {
                author = doc.Application.Username;
            }

            NamingUtil.ParseName(author, out familyName, out givenName, out middleNames, out prefixTitles, out suffixTitles);

            IFCFile file = exporterIFC.GetFile();

            IFCAnyHandle telecomAddress = GetTelecomAddressFromExtStorage(file, doc);
            IList<IFCAnyHandle> telecomAddresses = null;
            if (telecomAddress != null)
            {
                telecomAddresses = new List<IFCAnyHandle>();
                telecomAddresses.Add(telecomAddress);
            }

            IFCAnyHandle person = IFCInstanceExporter.CreatePerson(file, null, familyName, givenName, middleNames,
                prefixTitles, suffixTitles, null, telecomAddresses);

            string organizationName = String.Empty;
            string organizationDescription = String.Empty;
            if (projectInfo != null)
            {
                try
                {
                    organizationName = projectInfo.OrganizationName;
                    organizationDescription = projectInfo.OrganizationDescription;
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                {
                }
            }

            int creationDate = (int) GetCreationDate(doc);
            
            IFCAnyHandle organization = IFCInstanceExporter.CreateOrganization(file, null, organizationName, organizationDescription,
                null, null);

            IFCAnyHandle owningUser = IFCInstanceExporter.CreatePersonAndOrganization(file, person, organization, null);
            IFCAnyHandle ownerHistory = IFCInstanceExporter.CreateOwnerHistory(file, owningUser, application, null,
                Toolkit.IFCChangeAction.NoChange, null, null, null, creationDate);

            exporterIFC.SetOwnerHistoryHandle(ownerHistory);

            // Getting contact information from Revit extensible storage that COBie extension tool creates
            GetCOBieContactInfo(file, doc);

            IFCAnyHandle units = CreateDefaultUnits(exporterIFC, doc);
            HashSet<IFCAnyHandle> repContexts = CreateContextInformation(exporterIFC, doc);

            // As per IFC implementer's agreement, we get IfcProject.Name from ProjectInfo.Number and IfcProject.Longname from ProjectInfo.Name 
            string projectName = (projectInfo != null) ? projectInfo.Number : null;
            string projectLongName = (projectInfo != null) ? projectInfo.Name :null;

            // Get project description if it is set in the Project info
            string projectObjectType = (projectInfo != null) ? NamingUtil.GetObjectTypeOverride(projectInfo, null) : null;
            string projectDescription = (projectInfo != null) ? NamingUtil.GetDescriptionOverride(projectInfo, null) : null;

            string projectPhase = null;
            if (projectInfo != null)
                ParameterUtil.GetStringValueFromElement(projectInfo.Id, "Project Phase", out projectPhase);

            string projectGUID = GUIDUtil.CreateProjectLevelGUID(doc, IFCProjectLevelGUIDType.Project);
            IFCAnyHandle projectHandle = IFCInstanceExporter.CreateProject(file, projectGUID, ownerHistory,
                projectName, projectDescription, projectObjectType, projectLongName, projectPhase, repContexts, units);
            exporterIFC.SetProject(projectHandle);

            if (ExporterCacheManager.ExportOptionsCache.FileVersion == IFCVersion.IFCCOBIE)
            {
                HashSet<IFCAnyHandle> projectHandles = new HashSet<IFCAnyHandle>();
                projectHandles.Add(projectHandle);
                string clientName = (projectInfo != null) ? projectInfo.ClientName : String.Empty;
                IFCAnyHandle clientOrg = IFCInstanceExporter.CreateOrganization(file, null, clientName, null, null, null);
                IFCAnyHandle actor = IFCInstanceExporter.CreateActor(file, GUIDUtil.CreateGUID(), ownerHistory, null, null, null, clientOrg);
                IFCInstanceExporter.CreateRelAssignsToActor(file, GUIDUtil.CreateGUID(), ownerHistory, "Project Client/Owner", null, projectHandles, null, actor, null);

                IFCAnyHandle architectActor = IFCInstanceExporter.CreateActor(file, GUIDUtil.CreateGUID(), ownerHistory, null, null, null, person);
                IFCInstanceExporter.CreateRelAssignsToActor(file, GUIDUtil.CreateGUID(), ownerHistory, "Project Architect", null, projectHandles, null, architectActor, null);
            }
        }
コード例 #3
0
ファイル: Exporter.cs プロジェクト: stiter/ifcexporter
        /// <summary>
        /// Creates the IfcProject.
        /// </summary>
        /// <param name="exporterIFC">The IFC exporter object.</param>
        /// <param name="doc">The document provides the owner information.</param>
        /// <param name="application">The handle of IFC file to create the owner history.</param>
        private void CreateProject(ExporterIFC exporterIFC, Document doc, IFCAnyHandle application)
        {
            string familyName;
            string givenName;
            List<string> middleNames;
            List<string> prefixTitles;
            List<string> suffixTitles;

            string author = String.Empty;
            ProjectInfo projInfo = doc.ProjectInformation;
            if (projInfo != null)
            {
                try
                {
                    author = projInfo.Author;
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                {
                    //if failed to get author from project info, try to get the username from application later.
                }
            }

            if (String.IsNullOrEmpty(author))
            {
                author = doc.Application.Username;
            }

            NamingUtil.ParseName(author, out familyName, out givenName, out middleNames, out prefixTitles, out suffixTitles);

            IFCFile file = exporterIFC.GetFile();
            IFCAnyHandle person = IFCInstanceExporter.CreatePerson(file, null, familyName, givenName, middleNames,
                prefixTitles, suffixTitles, null, null);

            string organizationName = String.Empty;
            string organizationDescription = String.Empty;
            if (projInfo != null)
            {
                try
                {
                    organizationName = projInfo.OrganizationName;
                    organizationDescription = projInfo.OrganizationDescription;
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                {
                }
            }

            int creationDate = (int) GetCreationDate(doc);

            IFCAnyHandle organization = IFCInstanceExporter.CreateOrganization(file, null, organizationName, organizationDescription,
                null, null);

            IFCAnyHandle owningUser = IFCInstanceExporter.CreatePersonAndOrganization(file, person, organization, null);
            IFCAnyHandle ownerHistory = IFCInstanceExporter.CreateOwnerHistory(file, owningUser, application, null,
                Toolkit.IFCChangeAction.NoChange, null, null, null, creationDate);

            exporterIFC.SetOwnerHistoryHandle(ownerHistory);

            IFCAnyHandle units = CreateDefaultUnits(exporterIFC, doc);
            HashSet<IFCAnyHandle> repContexts = CreateContextInformation(exporterIFC, doc);

            // find project description
            string projectDescription = NamingUtil.GetDescriptionOverride(projInfo, null);

            IFCAnyHandle projectHandle = IFCInstanceExporter.CreateProject(file,
                GUIDUtil.CreateProjectLevelGUID(doc, IFCProjectLevelGUIDType.Project), ownerHistory,
                null, projectDescription, null, null, null, repContexts, units);
            exporterIFC.SetProject(projectHandle);

            if (ExporterCacheManager.ExportOptionsCache.FileVersion == IFCVersion.IFCCOBIE)
            {
                HashSet<IFCAnyHandle> projectHandles = new HashSet<IFCAnyHandle>();
                projectHandles.Add(projectHandle);
                string clientName = projInfo != null ? projInfo.ClientName : String.Empty;
                IFCAnyHandle clientOrg = IFCInstanceExporter.CreateOrganization(file, null, clientName, null, null, null);
                IFCAnyHandle actor = IFCInstanceExporter.CreateActor(file, GUIDUtil.CreateGUID(), ownerHistory, null, null, null, clientOrg);
                IFCInstanceExporter.CreateRelAssignsToActor(file, GUIDUtil.CreateGUID(), ownerHistory, "Project Client/Owner", null, projectHandles, null, actor, null);

                IFCAnyHandle architectActor = IFCInstanceExporter.CreateActor(file, GUIDUtil.CreateGUID(), ownerHistory, null, null, null, person);
                IFCInstanceExporter.CreateRelAssignsToActor(file, GUIDUtil.CreateGUID(), ownerHistory, "Project Architect", null, projectHandles, null, architectActor, null);
            }
        }