/// <summary>
        /// Changes the elevation of all points in the subregion by a designated delta.
        /// </summary>
        /// <param name="uiDoc">The document.</param>
        /// <param name="elevationDelta">The change in elevation.</param>
        public static void ChangeSubregionAndPointsElevation(UIDocument uiDoc, double elevationDelta)
        {
            Document doc = uiDoc.Document;

            // Pick subregion
            TopographySurface subregion   = PickSubregion(uiDoc);
            TopographySurface toposurface = SiteEditingUtils.GetTopographySurfaceHost(subregion);

            // Get points
            IList <XYZ> points = SiteEditingUtils.GetNonBoundaryPoints(subregion);

            if (points.Count == 0)
            {
                return;
            }

            // Change in elevation
            XYZ delta = elevationDelta * XYZ.BasisZ;

            // Edit scope for all changes
            using (TopographyEditScope editScope = new TopographyEditScope(doc, "Raise/lower terrain"))
            {
                editScope.Start(toposurface.Id);

                using (Transaction t = new Transaction(doc, "Raise/lower terrain"))
                {
                    t.Start();

                    // Use MovePoints to change all points relative to their current position
                    toposurface.MovePoints(points, delta);
                    t.Commit();
                }

                editScope.Commit(new TopographyEditFailuresPreprocessor());
            }
        }
Exemple #2
0
        /// <summary>
        /// Moves a subregion and the associated topography to a new user-selected location.
        /// </summary>
        /// <param name="uiDoc">The document.</param>
        private void MoveSubregionAndPoints(UIDocument uiDoc)
        {
            Document doc = uiDoc.Document;

            // Pick subregion
            TopographySurface subregion   = SiteUIUtils.PickSubregion(uiDoc);
            TopographySurface toposurface = SiteEditingUtils.GetTopographySurfaceHost(subregion);
            IList <XYZ>       points      = SiteEditingUtils.GetPointsFromSubregionExact(subregion);
            XYZ sourceLocation            = SiteEditingUtils.GetCenterOf(subregion);

            // Pick target location
            XYZ targetPoint = SiteUIUtils.PickPointNearToposurface(uiDoc, toposurface, "Pick point to move to");

            // Delta for the move
            XYZ delta = targetPoint - sourceLocation;

            // All changes are added to one transaction group - will create one undo item
            using (TransactionGroup moveGroup = new TransactionGroup(doc, "Move subregion and points"))
            {
                moveGroup.Start();

                // Get elevation of region in current location
                IList <XYZ> existingPointsInCurrentLocation = subregion.GetPoints();

                double existingElevation = SiteEditingUtils.GetAverageElevation(existingPointsInCurrentLocation);

                // Move subregion first - allows the command delete existing points and adjust elevation to surroundings
                using (Transaction t2 = new Transaction(doc, "Move subregion"))
                {
                    t2.Start();
                    ElementTransformUtils.MoveElement(doc, subregion.Id, delta);
                    t2.Commit();
                }

                // The boundary points for the subregion cannot be deleted, since they are generated
                // to represent the subregion boundary rather than representing real points in the host.
                // Get non-boundary points only to be deleted.
                IList <XYZ> existingPointsInNewLocation = SiteEditingUtils.GetNonBoundaryPoints(subregion);

                // Average elevation of all points in the subregion.
                double newElevation = SiteEditingUtils.GetAverageElevation(subregion.GetPoints());

                // Adjust delta for elevation based on calculated values
                delta = SiteEditingUtils.MoveXYZToElevation(delta, newElevation - existingElevation);

                // Edit scope for points changes
                using (TopographyEditScope editScope = new TopographyEditScope(doc, "Edit TS"))
                {
                    editScope.Start(toposurface.Id);

                    using (Transaction t = new Transaction(doc, "Move points"))
                    {
                        t.Start();
                        // Delete existing points from target region
                        if (existingPointsInNewLocation.Count > 0)
                        {
                            toposurface.DeletePoints(existingPointsInNewLocation);
                        }

                        // Move points from source region
                        toposurface.MovePoints(points, delta);
                        t.Commit();
                    }

                    editScope.Commit(new TopographyEditFailuresPreprocessor());
                }

                moveGroup.Assimilate();
            }
        }