public void CDS_FindClosestPointOnSurface()
        {
            ObjectId surfaceId = promptForTinSurface();

            if (surfaceId.IsNull)
            {
                write("\nNo TIN Surface selected.");
                return;
            }

            PromptPointResult result = _editor.GetPoint(
                "\nSelect point outside surface: ");

            if (result.Status != PromptStatus.OK)
            {
                write("\nNo point selected.");
                return;
            }

            Point3d selectedPoint         = result.Value;
            Point3d closestPointFound     = Point3d.Origin;
            double  shortestDistanceSoFar = Double.MaxValue;

            using (Transaction tr = startTransaction())
            {
                TinSurface surface = surfaceId.GetObject(OpenMode.ForRead)
                                     as TinSurface;
                write("\nSelected surface: " + surface.Name);
                write("\nSelected point: " + selectedPoint.ToString());
                ObjectIdCollection borders = surface.ExtractBorder(
                    SurfaceExtractionSettingsType.Model);
                foreach (ObjectId borderId in borders)
                {
                    Polyline3d border = borderId.GetObject(OpenMode.ForRead)
                                        as Polyline3d;
                    Point3d closestToBorder =
                        border.GetClosestPointTo(selectedPoint, false);
                    double distance = selectedPoint.DistanceTo(closestToBorder);
                    if (distance < shortestDistanceSoFar)
                    {
                        closestPointFound     = closestToBorder;
                        shortestDistanceSoFar = distance;
                    }
                }
            }

            write("\nClosest point found: " + closestPointFound.ToString());

            using (Transaction tr = startTransaction())
            {
                BlockTableRecord btr = tr.GetObject(_database.CurrentSpaceId,
                                                    OpenMode.ForWrite) as BlockTableRecord;
                Line line = new Line(selectedPoint, closestPointFound);
                btr.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                tr.Commit();
            }
        }
Example #2
0
        public void GetBorderFromSurface()
        {
            ObjectIdCollection entityIds = ts.ExtractBorder(Autodesk.Civil.SurfaceExtractionSettingsType.Model);

            border = ObjectId.Null;

            try
            {
                for (int i = 0; i < entityIds.Count; i++)
                {
                    ObjectId entityId = entityIds[i];
                    if (entityId.ObjectClass == RXClass.GetClass(typeof(Polyline3d)))
                    {
                        border = entityId; //entityId.GetObject(OpenMode.ForRead) as Polyline3d;
                    }
                }
            }
            catch (System.Exception ex)
            { }
        }
Example #3
0
        public void ExtractBorder(Transaction trans, ObjectId surfaceId)
        {
            TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForRead) as TinSurface;

            // Extract Border from the TinSurface
            // The extracted entities can be Polyline, Polyline3d, or Face.

            ObjectIdCollection entityIds;

            entityIds = surface.ExtractBorder(Autodesk.Civil.SurfaceExtractionSettingsType.Plan);
            for (int i = 0; i < entityIds.Count; i++)
            {
                ObjectId entityId = entityIds[i];
                if (entityId.ObjectClass == RXClass.GetClass(typeof(Polyline3d)))
                {
                    Polyline3d border = entityId.GetObject(OpenMode.ForWrite) as Polyline3d;
                    // Do what you want with the extrated 3d-polyline
                }
            }
        }