/// <summary>
        /// Gets the project base point for the document.
        /// </summary>
        /// <param name="doc">The document from which to get the project base point.</param>
        /// <returns>The project base point of the document.</returns>
        public static BasePoint GetProjectBasePoint(Document doc)
        {
#if REVIT_2021
            return(BasePoint.GetProjectBasePoint(doc));
#else
            using (var collector = new FilteredElementCollector(doc))
            {
                var pointCollector = collector.OfCategory(BuiltInCategory.OST_ProjectBasePoint);
                return(pointCollector.FirstElement() as BasePoint);
            }
#endif
        }
示例#2
0
        /// <summary>
        /// Compute the Eastings, Northings, OrthogonalHeight from the selected SiteTransformationBasis
        /// </summary>
        /// <param name="doc">The document</param>
        /// <param name="wcsBasis">The selected coordinate base</param>
        /// <returns>A Tuple for Eastings, Northings, and OrthogonalHeight</returns>
        public static (double eastings, double northings, double orthogonalHeight) GeoReferenceInformation(Document doc, SiteTransformBasis wcsBasis)
        {
            double eastings         = 0.0;
            double northings        = 0.0;
            double orthogonalHeight = 0.0;

            BasePoint surveyPoint      = BasePoint.GetSurveyPoint(doc);
            BasePoint projectBasePoint = BasePoint.GetProjectBasePoint(doc);

            switch (wcsBasis)
            {
            case SiteTransformBasis.Internal:
                northings        = surveyPoint.SharedPosition.Y - surveyPoint.Position.Y;
                eastings         = surveyPoint.SharedPosition.X - surveyPoint.Position.X;
                orthogonalHeight = surveyPoint.SharedPosition.Z - surveyPoint.Position.Z;
                break;

            case SiteTransformBasis.Project:
                northings        = projectBasePoint.SharedPosition.Y;
                eastings         = projectBasePoint.SharedPosition.X;
                orthogonalHeight = projectBasePoint.SharedPosition.Z;
                break;

            case SiteTransformBasis.Shared:
                northings        = 0.0;
                eastings         = 0.0;
                orthogonalHeight = 0.0;
                break;

            case SiteTransformBasis.Site:
                northings        = surveyPoint.SharedPosition.Y;
                eastings         = surveyPoint.SharedPosition.X;
                orthogonalHeight = surveyPoint.SharedPosition.Z;
                break;

            default:
                northings        = 0.0;
                eastings         = 0.0;
                orthogonalHeight = 0.0;
                break;
            }

            return(eastings, northings, orthogonalHeight);
        }
示例#3
0
        /// <summary>
        /// Compute the Eastings, Northings, OrthogonalHeight from the selected SiteTransformationBasis
        /// </summary>
        /// <param name="doc">The document</param>
        /// <param name="wcsBasis">The selected coordinate base</param>
        /// <returns>A Tuple for Eastings, Northings, and OrthogonalHeight</returns>
        public static (double eastings, double northings, double orthogonalHeight, double angleTN, double origAngleTN) GeoReferenceInformation
            (Document doc, SiteTransformBasis wcsBasis, ProjectLocation projLocation = null)
        {
            double eastings         = 0.0;
            double northings        = 0.0;
            double orthogonalHeight = 0.0;
            double angleTN          = 0.0;
            double origAngleTN      = 0.0;

            using (Transaction tr = new Transaction(doc))
            {
                try
                {
                    tr.Start("Temp Project Location change");
                }
                catch { }

                using (SubTransaction tempSiteLocTr = new SubTransaction(doc))
                {
                    tempSiteLocTr.Start();
                    if (projLocation != null)
                    {
                        doc.ActiveProjectLocation = projLocation;
                    }

                    BasePoint surveyPoint      = BasePoint.GetSurveyPoint(doc);
                    BasePoint projectBasePoint = BasePoint.GetProjectBasePoint(doc);
                    (double svNorthings, double svEastings, double svElevation, double svAngle, double pbNorthings,
                     double pbEastings, double pbElevation, double pbAngle) = ProjectLocationInfo(doc, surveyPoint.Position, projectBasePoint.Position);
                    origAngleTN = pbAngle;

                    switch (wcsBasis)
                    {
                    case SiteTransformBasis.Internal:
                        Transform rotationTrfAtInternal = Transform.CreateRotationAtPoint(new XYZ(0, 0, 1), svAngle, XYZ.Zero);
                        XYZ       intPointOffset        = rotationTrfAtInternal.OfPoint(surveyPoint.Position);
                        northings        = svNorthings - intPointOffset.Y;
                        eastings         = svEastings - intPointOffset.X;
                        orthogonalHeight = surveyPoint.SharedPosition.Z - surveyPoint.Position.Z;
                        angleTN          = -svAngle;
                        break;

                    case SiteTransformBasis.InternalInTN:
                        rotationTrfAtInternal = Transform.CreateRotationAtPoint(new XYZ(0, 0, 1), svAngle, XYZ.Zero);
                        intPointOffset        = rotationTrfAtInternal.OfPoint(surveyPoint.Position);
                        northings             = svNorthings - intPointOffset.Y;
                        eastings         = svEastings - intPointOffset.X;
                        orthogonalHeight = surveyPoint.SharedPosition.Z - surveyPoint.Position.Z;
                        angleTN          = 0.0;
                        break;

                    case SiteTransformBasis.Project:
                        northings        = pbNorthings;
                        eastings         = pbEastings;
                        orthogonalHeight = pbElevation;
                        angleTN          = -pbAngle;
                        break;

                    case SiteTransformBasis.ProjectInTN:
                        northings        = pbNorthings;
                        eastings         = pbEastings;
                        orthogonalHeight = pbElevation;
                        angleTN          = 0.0;
                        break;

                    case SiteTransformBasis.Shared:
                        northings        = 0.0;
                        eastings         = 0.0;
                        orthogonalHeight = 0.0;
                        angleTN          = 0.0;
                        break;

                    case SiteTransformBasis.Site:
                        northings        = svNorthings;
                        eastings         = svEastings;
                        orthogonalHeight = svElevation;
                        angleTN          = 0.0;
                        break;

                    default:
                        northings        = 0.0;
                        eastings         = 0.0;
                        orthogonalHeight = 0.0;
                        angleTN          = 0.0;
                        break;
                    }
                    tempSiteLocTr.RollBack();
                }
            }

            return(eastings, northings, orthogonalHeight, angleTN, origAngleTN);
        }
示例#4
0
        /// <summary>
        /// Exports as an IFC file on clicking OK.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Event arguments that contains the event data.</param>
        private void buttonNext_Click(object sender, RoutedEventArgs args)
        {
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(textBoxSetupFileName.Text);
            string filePath = Path.GetDirectoryName(textBoxSetupFileName.Text);

            // Show Path is invalid message if the path is blank or invalid.
            if (!string.IsNullOrWhiteSpace(filePath) && !Directory.Exists(filePath))
            {
                TaskDialog.Show("Error", Properties.Resources.ValidPathExists);
            }
            else
            {
                // Create a default .ifc file if the file name is blank
                if (String.IsNullOrWhiteSpace(filePath))
                {
                    updateFileName();
                }

                // Check for a valid IFC File format, if it does not exists, append the default IFC file format to export to the file
                if (Path.GetExtension(textBoxSetupFileName.Text).IndexOf(Properties.Resources.IFC, StringComparison.CurrentCultureIgnoreCase) == -1)
                {
                    textBoxSetupFileName.Text = textBoxSetupFileName.Text.ToString() + "." + m_defaultExt;
                }

                // Prompt for overwriting the file if it is already present in the directory.
                if (File.Exists(textBoxSetupFileName.Text))
                {
                    TaskDialogResult msgBoxResult = TaskDialog.Show(Properties.Resources.IFCExport, String.Format(Properties.Resources.FileExists, textBoxSetupFileName.Text), TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No);
                    if (msgBoxResult == TaskDialogResult.No)
                    {
                        return;
                    }
                }
                if (Win32API.RtlIsDosDeviceName_U(textBoxSetupFileName.Text) != 0)
                {
                    TaskDialog.Show(Properties.Resources.IFCExport, String.Format(Properties.Resources.ReservedDeviceName, textBoxSetupFileName.Text));
                    return;
                }

                IFCExportConfiguration selectedConfig = GetSelectedConfiguration();
                if (!EditConfigVisited && LastSelectedConfig.ContainsKey(selectedConfig.Name))
                {
                    selectedConfig = LastSelectedConfig[selectedConfig.Name];
                }

                // This check will be done only for IFC4 and above as this only affects IfcMapConversion use that starts in IFC4 onward
                if (!OptionsUtil.ExportAsOlderThanIFC4(selectedConfig.IFCVersion))
                {
                    // Check whether the resulting offset (to wcs) will be too large due to geo-reference information, raise warning
                    BasePoint surveyPoint      = BasePoint.GetSurveyPoint(TheDocument);
                    BasePoint projectBasePoint = BasePoint.GetProjectBasePoint(TheDocument);
                    {
                        XYZ deltaOffset = XYZ.Zero;
                        switch (selectedConfig.SitePlacement)
                        {
                        case SiteTransformBasis.Internal:
                            deltaOffset = projectBasePoint.Position;
                            break;

                        case SiteTransformBasis.Project:
                            // Offset from Project point is Zero, unchanged from the initial value
                            break;

                        case SiteTransformBasis.Site:
                            deltaOffset = projectBasePoint.Position - surveyPoint.Position;
                            break;

                        case SiteTransformBasis.Shared:
                            deltaOffset = projectBasePoint.SharedPosition;
                            break;

                        default:
                            break;
                        }

                        if (!XYZ.IsWithinLengthLimits(deltaOffset))
                        {
                            TaskDialogResult msgBoxResult = TaskDialog.Show(Properties.Resources.IFCExport, Properties.Resources.OffsetDistanceTooLarge,
                                                                            TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel);
                            if (msgBoxResult == TaskDialogResult.Cancel)
                            {
                                return;
                            }
                        }
                    }
                }

                Result = IFCExportResult.ExportAndSaveSettings;
                Close();

                // Set IFC File header with the selected exchange requirement
                if (selectedConfig.ExchangeRequirement != KnownERNames.NotDefined)
                {
                    IFCFileHeader     ifcFileHeader = new IFCFileHeader();
                    IFCFileHeaderItem fileHeaderItem;
                    if (!ifcFileHeader.GetSavedFileHeader(IFCCommandOverrideApplication.TheDocument, out fileHeaderItem))
                    {
                        // Do minimum initialization if the header item is not initialized
                        fileHeaderItem = new IFCFileHeaderItem(IFCCommandOverrideApplication.TheDocument);
                    }

                    string erName = selectedConfig.ExchangeRequirement.ToString();
                    fileHeaderItem.FileDescription = "ExchangeRequirement [" + erName + "]";
                    ifcFileHeader.UpdateFileHeader(IFCCommandOverrideApplication.TheDocument, fileHeaderItem);
                }

                LastSelectedConfig[selectedConfig.Name] = selectedConfig;
                TheDocument.Application.WriteJournalComment("Dialog Closed", true);
            }
        }