Esempio n. 1
0
        public void CollectLinkInstanceInfo()
        {
            try
            {
                Parameter param = m_instance.get_Parameter(BuiltInParameter.RVT_LINK_INSTANCE_NAME);
                if (null != param)
                {
                    instanceName = param.AsString();
                }

                if (null != m_instance.GetTotalTransform())
                {
                    transformValue = m_instance.GetTotalTransform();
                }

                linkedDocument = m_instance.GetLinkDocument();
                if (null != linkedDocument)
                {
                    linkDocTitle = linkedDocument.Title;
                }

                if (null != linkedDocument)
                {
                    ifcProjectGuid = ExporterIFCUtils.CreateProjectLevelGUID(linkedDocument, IFCProjectLevelGUIDType.Project);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a Project, Site, or Building GUID.  If a shared parameter is set with a valid IFC GUID value,
        /// that value will override the default one.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="guidType">The GUID being created.</param>
        /// <returns>The IFC GUID value.</returns>
        /// <remarks>For Sites, the user should only use this routine if there is no Site element in the file.  Otherwise, they
        /// should use CreateSiteGUID below, which takes an Element pointer.</remarks>
        static public string CreateProjectLevelGUID(Document document, IFCProjectLevelGUIDType guidType)
        {
            string      parameterName = "Ifc" + guidType.ToString() + " GUID";
            ProjectInfo projectInfo   = document.ProjectInformation;

            BuiltInParameter parameterId = BuiltInParameter.INVALID;

            switch (guidType)
            {
            case IFCProjectLevelGUIDType.Building:
                parameterId = BuiltInParameter.IFC_BUILDING_GUID;
                break;

            case IFCProjectLevelGUIDType.Project:
                parameterId = BuiltInParameter.IFC_PROJECT_GUID;
                break;

            case IFCProjectLevelGUIDType.Site:
                parameterId = BuiltInParameter.IFC_SITE_GUID;
                break;

            default:
                // This should eventually log an error.
                return(null);
            }

            if (projectInfo != null)
            {
                string paramValue = null;
                ParameterUtil.GetStringValueFromElement(projectInfo, parameterName, out paramValue);
                if (!IsValidIFCGUID(paramValue) && parameterId != BuiltInParameter.INVALID)
                {
                    ParameterUtil.GetStringValueFromElement(projectInfo, parameterId, out paramValue);
                }

                if (IsValidIFCGUID(paramValue))
                {
                    return(paramValue);
                }
            }

            // Only for 2022
            //ElementId projectLevelElementId = new ElementId((int)guidType);
            //System.Guid guid = ExportUtils.GetExportId(document, projectLevelElementId);
            //string ifcGUID = ConvertToIFCGuid(guid);
            string ifcGUID = ExporterIFCUtils.CreateProjectLevelGUID(document, guidType);

            if ((projectInfo != null) && ExporterCacheManager.ExportOptionsCache.GUIDOptions.StoreIFCGUID)
            {
                if (parameterId != BuiltInParameter.INVALID)
                {
                    ExporterCacheManager.GUIDsToStoreCache[new KeyValuePair <ElementId, BuiltInParameter>(projectInfo.Id, parameterId)] = ifcGUID;
                }
            }
            return(ifcGUID);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a Project, Site, or Building GUID.  If a shared parameter is set with a valid IFC GUID value,
        /// that value will override the default one.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="guidType">The GUID being created.</param>
        /// <returns>The IFC GUID value.</returns>
        /// <remarks>For Sites, the user should only use this routine if there is no Site element in the file.  Otherwise, they
        /// should use CreateSiteGUID below, which takes an Element pointer.</remarks>
        static public string CreateProjectLevelGUID(Document document, IFCProjectLevelGUIDType guidType)
        {
            string      parameterName = "Ifc" + guidType.ToString() + " GUID";
            ProjectInfo projectInfo   = document.ProjectInformation;

            BuiltInParameter parameterId = BuiltInParameter.INVALID;

            switch (guidType)
            {
            case IFCProjectLevelGUIDType.Building:
                parameterId = BuiltInParameter.IFC_BUILDING_GUID;
                break;

            case IFCProjectLevelGUIDType.Project:
                parameterId = BuiltInParameter.IFC_PROJECT_GUID;
                break;

            case IFCProjectLevelGUIDType.Site:
                parameterId = BuiltInParameter.IFC_SITE_GUID;
                break;
            }

            if (projectInfo != null)
            {
                string paramValue = null;
                ParameterUtil.GetStringValueFromElement(projectInfo, parameterName, out paramValue);
                if ((paramValue != null) && (IsValidIFCGUID(paramValue)))
                {
                    return(paramValue);
                }
                if (parameterId != BuiltInParameter.INVALID && ParameterUtil.GetStringValueFromElement(projectInfo, parameterId, out paramValue) != null)
                {
                    return(paramValue);
                }
            }
            string guid = ExporterIFCUtils.CreateProjectLevelGUID(document, guidType);

            if ((projectInfo != null) && ExporterCacheManager.ExportOptionsCache.GUIDOptions.StoreIFCGUID)
            {
                if (parameterId != BuiltInParameter.INVALID)
                {
                    ExporterCacheManager.GUIDsToStoreCache[new KeyValuePair <Element, BuiltInParameter>(projectInfo, parameterId)] = guid;
                }
            }
            return(guid);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a Project, Site, or Building GUID.  If a shared parameter is set with a valid IFC GUID value,
        /// that value will override the default one.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="guidType">The GUID being created.</param>
        /// <returns>The IFC GUID value.</returns>
        /// <remarks>For Sites, the user should only use this routine if there is no Site element in the file.  Otherwise, they
        /// should use CreateSiteGUID below, which takes an Element pointer.</remarks>
        static public string CreateProjectLevelGUID(Document document, IFCProjectLevelGUIDType guidType)
        {
            string      parameterName = "Ifc" + guidType.ToString() + " GUID";
            ProjectInfo projectInfo   = document.ProjectInformation;

            if (projectInfo != null)
            {
                string paramValue = null;
                ParameterUtil.GetStringValueFromElement(projectInfo.Id, parameterName, out paramValue);
                if ((paramValue != null) && (IsValidIFCGUID(paramValue)))
                {
                    return(paramValue);
                }
            }

            // CreateProjectLevelGUID will throw an exception if the is no Project Information, which indicates
            // some sort of error in the document.  Don't bother trying to create a consistent GUID in this case.
            // This is fixed in 2014+.
            string guid = (projectInfo != null) ? ExporterIFCUtils.CreateProjectLevelGUID(document, guidType) : CreateGUID();

            if ((projectInfo != null) && ExporterCacheManager.ExportOptionsCache.GUIDOptions.StoreIFCGUID)
            {
                BuiltInParameter parameterId = BuiltInParameter.INVALID;
                switch (guidType)
                {
                case IFCProjectLevelGUIDType.Building:
                    parameterId = BuiltInParameter.IFC_BUILDING_GUID;
                    break;

                case IFCProjectLevelGUIDType.Project:
                    parameterId = BuiltInParameter.IFC_PROJECT_GUID;
                    break;

                case IFCProjectLevelGUIDType.Site:
                    parameterId = BuiltInParameter.IFC_SITE_GUID;
                    break;
                }

                if (parameterId != BuiltInParameter.INVALID)
                {
                    IFCStoredGUID.ProjectInfoParameterGUID[parameterId] = guid;
                }
            }
            return(guid);
        }
Esempio n. 5
0
        /// <summary>
        /// Add Issue
        /// </summary>
        /// <param name="path"></param>
        /// <param name="isBcf"></param>
        /// <returns></returns>
        private Tuple <Markup, Issue> AddIssue(string path, bool isBcf)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document;

                if (!(uidoc.ActiveView is View3D || uidoc.ActiveView is ViewSheet || uidoc.ActiveView is ViewPlan || uidoc.ActiveView is ViewSection || uidoc.ActiveView is ViewDrafting))
                {
                    MessageBox.Show("I'm sorry,\nonly 3D and 2D views are supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }

                Markup issue = new Markup(DateTime.Now);

                string folderIssue = Path.Combine(path, issue.Topic.Guid);
                if (!Directory.Exists(folderIssue))
                {
                    Directory.CreateDirectory(folderIssue);
                }

                var types      = new ObservableCollection <Issuetype>();
                var assignees  = new List <User>();
                var components = new ObservableCollection <IssueTracker.Classes.Component>();
                var priorities = new ObservableCollection <Priority>();
                var noCom      = true;
                var noPrior    = true;
                var noAssign   = true;

                if (!isBcf)
                {
                    types      = mainPan.jira.TypesCollection;
                    assignees  = mainPan.getAssigneesIssue();
                    components = mainPan.jira.ComponentsCollection;
                    priorities = mainPan.jira.PrioritiesCollection;
                    noCom      =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components ==
                        null;
                    noPrior =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority ==
                        null;
                    noAssign =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee ==
                        null;
                }

                AddIssueRevit air = new AddIssueRevit(uidoc, folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign);
                air.Title = "Add Jira Issue";
                if (!isBcf)
                {
                    air.JiraFieldsBox.Visibility = System.Windows.Visibility.Visible;
                    air.VerbalStatus.Visibility  = System.Windows.Visibility.Collapsed;
                    air.BcfFieldsBox.Visibility  = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    air.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed;
                    air.BcfFieldsBox.Visibility  = System.Windows.Visibility.Visible;
                }

                air.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                air.ShowDialog();
                if (air.DialogResult.HasValue && air.DialogResult.Value)
                {
                    ViewPoint vp = new ViewPoint(true);
                    vp.SnapshotPath = Path.Combine(folderIssue, "snapshot.png");
                    int elemCheck = 2;
                    if (air.all.IsChecked.Value)
                    {
                        elemCheck = 0;
                    }
                    else if (air.selected.IsChecked.Value)
                    {
                        elemCheck = 1;
                    }
                    vp.VisInfo = generateViewpoint(elemCheck);

                    //Add annotations for description with snapshot/viewpoint
                    StringBuilder descriptionText = new StringBuilder();
                    if (!string.IsNullOrWhiteSpace(air.CommentBox.Text))
                    {
                        descriptionText.AppendLine(air.CommentBox.Text);
                    }
                    if (!isBcf)
                    {
                        if (vp.VisInfo != null)
                        {
                            descriptionText.AppendLine(string.Format("<Viewpoint>[^{0}]</Viewpoint>", "viewpoint.bcfv"));
                        }
                        if (!string.IsNullOrWhiteSpace(vp.SnapshotPath))
                        {
                            descriptionText.AppendLine(string.Format("<Snapshot>[^{0}]</Snapshot>", "snapshot.png"));
                            descriptionText.AppendLine(string.Format("!{0}|width=200!", "snapshot.png"));
                        }
                    }

                    Issue issueJira = new Issue();
                    if (!isBcf)
                    {
                        issueJira.fields             = new Fields();
                        issueJira.fields.description = descriptionText.ToString().Trim();
                        issueJira.fields.issuetype   = (Issuetype)air.issueTypeCombo.SelectedItem;
                        issueJira.fields.priority    = (Priority)air.priorityCombo.SelectedItem;
                        if (!string.IsNullOrEmpty(air.ChangeAssign.Content.ToString()) &&
                            air.ChangeAssign.Content.ToString() != "none")
                        {
                            issueJira.fields.assignee      = new User();
                            issueJira.fields.assignee.name = air.ChangeAssign.Content.ToString();
                        }

                        if (air.SelectedComponents != null && air.SelectedComponents.Any())
                        {
                            issueJira.fields.components = air.SelectedComponents;
                        }
                    }

                    issue.Viewpoints.Add(vp);
                    issue.Topic.Title          = air.TitleBox.Text;
                    issue.Topic.Description    = descriptionText.ToString().Trim();
                    issue.Topic.AssignedTo     = air.BcfAssignee.Text;
                    issue.Topic.CreationAuthor = MySettings.Get("username");
                    issue.Topic.Priority       = air.BcfPriority.Text;
                    issue.Topic.TopicStatus    = air.VerbalStatus.Text;
                    issue.Topic.TopicType      = air.BcfIssueType.Text;

                    issue.Header[0].IfcProject = ExporterIFCUtils.CreateProjectLevelGUID(doc,
                                                                                         Autodesk.Revit.DB.IFC.IFCProjectLevelGUIDType.Project);
                    string projFilename = (doc.PathName != null && doc.PathName != "")
                  ? System.IO.Path.GetFileName(doc.PathName)
                  : "";
                    issue.Header[0].Filename = projFilename;
                    issue.Header[0].Date     = DateTime.Now;

                    return(new Tuple <Markup, Issue>(issue, issueJira));
                }
                else
                {
                    mainPan.DeleteDirectory(folderIssue);
                }
            }

            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }
            return(null);
        }
        /// <summary>
        /// Add Issue
        /// </summary>
        /// <param name="path"></param>
        /// <param name="isBcf"></param>
        /// <returns></returns>
        private Tuple <IssueBCF, Issue> AddIssue(string path, bool isBcf)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document;

                if (!(uidoc.ActiveView is View3D || uidoc.ActiveView is ViewSheet || uidoc.ActiveView is ViewPlan || uidoc.ActiveView is ViewSection || uidoc.ActiveView is ViewDrafting))
                {
                    MessageBox.Show("I'm sorry,\nonly 3D and 2D views are supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }
                IssueBCF issue = new IssueBCF();

                string folderIssue = Path.Combine(path, issue.guid.ToString());
                if (!Directory.Exists(folderIssue))
                {
                    Directory.CreateDirectory(folderIssue);
                }

                var types      = new ObservableCollection <Issuetype>();
                var assignees  = new List <User>();
                var components = new ObservableCollection <IssueTracker.Data.Component>();
                var priorities = new ObservableCollection <Priority>();
                var noCom      = true;
                var noPrior    = true;
                var noAssign   = true;

                if (!isBcf)
                {
                    types      = mainPan.jira.TypesCollection;
                    assignees  = mainPan.getAssigneesIssue();
                    components = mainPan.jira.ComponentsCollection;
                    priorities = mainPan.jira.PrioritiesCollection;
                    noCom      =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components ==
                        null;
                    noPrior =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority ==
                        null;
                    noAssign =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee ==
                        null;
                }

                AddIssueRevit air = new AddIssueRevit(uidoc, folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign);
                air.Title = "Add Jira Issue";
                if (!isBcf)
                {
                    air.VerbalStatus.Visibility = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    air.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed;
                }
                air.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                air.ShowDialog();
                if (air.DialogResult.HasValue && air.DialogResult.Value)
                {
                    issue.snapshot = Path.Combine(folderIssue, "snapshot.png");
                    int elemCheck = 2;
                    if (air.all.IsChecked.Value)
                    {
                        elemCheck = 0;
                    }
                    else if (air.selected.IsChecked.Value)
                    {
                        elemCheck = 1;
                    }

                    Issue issueJira = new Issue();
                    if (!isBcf)
                    {
                        issueJira.fields           = new Fields();
                        issueJira.fields.issuetype = (Issuetype)air.issueTypeCombo.SelectedItem;
                        issueJira.fields.priority  = (Priority)air.priorityCombo.SelectedItem;
                        if (!string.IsNullOrEmpty(air.ChangeAssign.Content.ToString()) &&
                            air.ChangeAssign.Content.ToString() != "none")
                        {
                            issueJira.fields.assignee      = new User();
                            issueJira.fields.assignee.name = air.ChangeAssign.Content.ToString();
                        }

                        if (air.SelectedComponents != null && air.SelectedComponents.Any())
                        {
                            issueJira.fields.components = air.SelectedComponents;
                        }
                    }
                    issue.viewpoint                   = generateViewpoint(elemCheck);
                    issue.markup.Topic.Title          = air.TitleBox.Text;
                    issue.markup.Header[0].IfcProject = ExporterIFCUtils.CreateProjectLevelGUID(doc,
                                                                                                Autodesk.Revit.DB.IFC.IFCProjectLevelGUIDType.Project);
                    string projFilename = (doc.PathName != null && doc.PathName != "")
              ? System.IO.Path.GetFileName(doc.PathName)
              : "";
                    issue.markup.Header[0].Filename = projFilename;
                    issue.markup.Header[0].Date     = DateTime.Now;

                    //comment
                    if (!string.IsNullOrWhiteSpace(air.CommentBox.Text))
                    {
                        CommentBCF c = new CommentBCF();
                        c.Comment1   = air.CommentBox.Text;
                        c.Topic      = new CommentTopic();
                        c.Topic.Guid = issue.guid.ToString();
                        ;
                        c.Date         = DateTime.Now;
                        c.VerbalStatus = air.VerbalStatus.Text;
                        c.Status       = CommentStatus.Unknown;
                        c.Author       = (string.IsNullOrWhiteSpace(mainPan.jira.Self.displayName))
                ? UserSettings.Get("BCFusername")
                : mainPan.jira.Self.displayName;
                        issue.markup.Comment.Add(c);
                    }

                    return(new Tuple <IssueBCF, Issue>(issue, issueJira));
                }
                else
                {
                    mainPan.DeleteDirectory(folderIssue);
                }
            }

            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }
            return(null);
        }
Esempio n. 7
0
 public RevitLinkProperties(Document doc)
 {
     isLinked       = false;
     linkedDocument = doc;
     ifcProjectGuid = ExporterIFCUtils.CreateProjectLevelGUID(linkedDocument, IFCProjectLevelGUIDType.Project);
 }
Esempio n. 8
0
        /// <summary>
        /// Base implementation to export IFC site object.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="document">
        /// The Revit document.
        /// </param>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        private static void ExportSiteBase(ExporterIFC exporterIFC, Document document, Element element, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            IFCAnyHandle siteHandle = exporterIFC.GetSite();

            int numSiteElements = (!IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle) ? 1 : 0);

            if (element == null && (numSiteElements != 0))
            {
                return;
            }

            Document doc = document;

            if (doc == null)
            {
                if (element != null)
                {
                    doc = element.Document;
                }
                else
                {
                    throw new ArgumentException("Both document and element are null.");
                }
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                IFCAnyHandle siteRepresentation = null;
                if (element != null)
                {
                    // It would be possible that they actually represent several different sites with different buildings,
                    // but until we have a concept of a building in Revit, we have to assume 0-1 sites, 1 building.
                    bool appendedToSite = false;
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle))
                    {
                        IList <IFCAnyHandle> representations = IFCAnyHandleUtil.GetProductRepresentations(siteHandle);
                        if (representations.Count > 0)
                        {
                            IFCAnyHandle bodyRep     = representations[0];
                            IFCAnyHandle boundaryRep = null;
                            if (representations.Count > 1)
                            {
                                boundaryRep = representations[1];
                            }

                            siteRepresentation = RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC, element, geometryElement, true, true, ref bodyRep, ref boundaryRep);
                            appendedToSite     = true;
                        }
                    }

                    if (!appendedToSite)
                    {
                        siteRepresentation = RepresentationUtil.CreateSurfaceProductDefinitionShape(exporterIFC, element, geometryElement, true, true);
                    }
                }

                List <int>      latitude     = new List <int>();
                List <int>      longitude    = new List <int>();
                ProjectLocation projLocation = doc.ActiveProjectLocation;

                IFCAnyHandle relativePlacement = null;
                double       elevation         = 0.0;
                if (projLocation != null)
                {
                    double latitudeInDeg  = projLocation.SiteLocation.Latitude * 180 / Math.PI;
                    double longitudeInDeg = projLocation.SiteLocation.Longitude * 180 / Math.PI;


                    int latDeg     = ((int)latitudeInDeg); latitudeInDeg -= latDeg; latitudeInDeg *= 60;
                    int latMin     = ((int)latitudeInDeg); latitudeInDeg -= latMin; latitudeInDeg *= 60;
                    int latSec     = ((int)latitudeInDeg); latitudeInDeg -= latSec; latitudeInDeg *= 1000000;
                    int latFracSec = ((int)latitudeInDeg);
                    latitude.Add(latDeg);
                    latitude.Add(latMin);
                    latitude.Add(latSec);
                    if (!exporterIFC.ExportAs2x2)
                    {
                        latitude.Add(latFracSec);
                    }

                    int longDeg     = ((int)longitudeInDeg); longitudeInDeg -= longDeg; longitudeInDeg *= 60;
                    int longMin     = ((int)longitudeInDeg); longitudeInDeg -= longMin; longitudeInDeg *= 60;
                    int longSec     = ((int)longitudeInDeg); longitudeInDeg -= longSec; longitudeInDeg *= 1000000;
                    int longFracSec = ((int)longitudeInDeg);
                    longitude.Add(longDeg);
                    longitude.Add(longMin);
                    longitude.Add(longSec);
                    if (!exporterIFC.ExportAs2x2)
                    {
                        longitude.Add(longFracSec);
                    }

                    Transform siteSharedCoordinatesTrf = projLocation.GetTransform().Inverse;
                    if (!siteSharedCoordinatesTrf.IsIdentity)
                    {
                        XYZ orig = siteSharedCoordinatesTrf.Origin;
                        orig = orig.Multiply(exporterIFC.LinearScale);
                        relativePlacement = ExporterUtil.CreateAxis2Placement3D(file, orig, siteSharedCoordinatesTrf.BasisZ, siteSharedCoordinatesTrf.BasisX);
                    }
                }

                // Get elevation for site.
                elevation = -LevelUtil.GetReferenceHeightForRelativeElevation(doc) * exporterIFC.LinearScale;

                if (IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement))
                {
                    relativePlacement = ExporterUtil.CreateAxis2Placement3D(file);
                }

                IFCAnyHandle localPlacement = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement);
                IFCAnyHandle ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
                string       objectType     = NamingUtil.CreateIFCObjectName(exporterIFC, element);

                if (element != null)
                {
                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(siteHandle))
                    {
                        string instanceGUID        = ExporterIFCUtils.CreateGUID(element);
                        string origInstanceName    = exporterIFC.GetName();
                        string instanceName        = NamingUtil.GetNameOverride(element, origInstanceName);
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceObjectType  = NamingUtil.GetObjectTypeOverride(element, objectType);
                        string instanceElemId      = NamingUtil.CreateIFCElementId(element);

                        siteHandle = IFCInstanceExporter.CreateSite(file, instanceGUID, ownerHistory, instanceName, instanceDescription, instanceObjectType, localPlacement,
                                                                    siteRepresentation, null, Toolkit.IFCElementComposition.Element, latitude, longitude, elevation, null, null);
                    }
                }
                else
                {
                    // don't bother if we have nothing in the site whatsoever.
                    if ((latitude.Count == 0 || longitude.Count == 0) && IFCAnyHandleUtil.IsNullOrHasNoValue(relativePlacement))
                    {
                        return;
                    }

                    string defaultSiteName = "Default";
                    siteHandle = IFCInstanceExporter.CreateSite(file, ExporterIFCUtils.CreateProjectLevelGUID(doc, IFCProjectLevelGUIDType.Site), ownerHistory, defaultSiteName, null, objectType, localPlacement,
                                                                null, null, Toolkit.IFCElementComposition.Element, latitude, longitude, elevation, null, null);
                }

                productWrapper.AddSite(siteHandle);
                exporterIFC.SetSite(siteHandle);

                tr.Commit();
            }
        }