예제 #1
1
        static public void CreateTunnel()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            //===========
            Matrix3d           curUCSMatrix = doc.Editor.CurrentUserCoordinateSystem;
            CoordinateSystem3d curUCS       = curUCSMatrix.CoordinateSystem3d;

            double             TunnelDia = 6.04;
            PromptEntityResult per       = ed.GetEntity("Select polylines");
            ObjectId           oid       = per.ObjectId;

            if (per.Status == PromptStatus.OK)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable       bt  = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

                    DBObject objPick = tr.GetObject(oid, OpenMode.ForRead);
                    Entity   objEnt  = objPick as Entity;
                    string   sLayer  = objEnt.Layer.ToString();

                    ObjectIdCollection oDBO = CADops.SelectAllPolyline(sLayer);

                    List <string> data = new List <string>();
                    foreach (ObjectId id in oDBO)
                    {
                        //get 3d polyline
                        Polyline3d poly3d = tr.GetObject(id, OpenMode.ForRead) as Polyline3d;

                        //get points on 3d polyline
                        List <Point3d> pts0 = CADops.GetPointsFrom3dPolyline(poly3d, doc);
                        List <Point3d> pts  = pts0.Distinct(new PointComparer(3)).ToList();

                        //get vectors on points
                        List <Vector3d> vectorAlongPath = new List <Vector3d>();
                        List <Vector3d> vectors         = CADops.getVectors(pts, doc, ref vectorAlongPath);

                        List <LoftProfile> loftProfiles = new List <LoftProfile>();
                        for (int i = 0; i < pts.Count(); i = i + 4)
                        {
                            Point3d pt = pts[i];
                            //ed.WriteMessage($"TUN_CreateTBM => {pt.X}, {pt.Y}, {pt.Z}; ");

                            Vector3d v   = vectors[i].GetNormal() * TunnelDia / 2;
                            Matrix3d mat = Matrix3d.Displacement(v);
                            Point3d  npt = pt.TransformBy(mat);

                            //create a 2d line in XY plane
                            Line ln = new Line(npt, pt);

                            btr.AppendEntity(ln);
                            tr.AddNewlyCreatedDBObject(ln, true);

                            double ang = ln.Angle; //vectors[i].GetAngleTo(curUCS.Xaxis);
                                                   //ed.WriteMessage($"angle {ang}\n");

                            Region acRegion = new Region();
                            try
                            {
                                using (Circle acCirc = new Circle())
                                {
                                    acCirc.Center = new Point3d(pt.X, pt.Y, pt.Z);
                                    acCirc.Radius = TunnelDia / 2;

                                    acCirc.TransformBy(Matrix3d.Rotation(Angle.angToRad(90), curUCS.Xaxis, acCirc.Center));
                                    acCirc.TransformBy(Matrix3d.Rotation(ang, curUCS.Zaxis, acCirc.Center));

                                    // Add the new object to the block table record and the transaction
                                    btr.AppendEntity(acCirc);
                                    tr.AddNewlyCreatedDBObject(acCirc, true);

                                    DBObjectCollection acDBObjColl = new DBObjectCollection();
                                    acDBObjColl.Add(acCirc);
                                    DBObjectCollection myRegionColl = new DBObjectCollection();
                                    myRegionColl = Region.CreateFromCurves(acDBObjColl);
                                    Region acRegion1 = myRegionColl[0] as Region;
                                    // Add the new object to the block table record and the transaction
                                    btr.AppendEntity(acRegion1);
                                    tr.AddNewlyCreatedDBObject(acRegion1, true);
                                    LoftProfile lp1 = new LoftProfile(acRegion1);
                                    loftProfiles.Add(lp1);
                                }
                            }
                            catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage(ex.ToString()); }
                        }

                        LoftProfile[] lps = new LoftProfile[loftProfiles.Count()];
                        for (int i = 0; i < loftProfiles.Count(); i++)
                        {
                            lps[i] = loftProfiles[i];
                        }

                        try
                        {
                            // =========== create loft solid
                            Solid3d sol = new Solid3d();
                            sol.SetDatabaseDefaults();
                            LoftOptions lpOptions = new LoftOptions();
                            //LoftProfile lpGuide = new LoftProfile(acLine);//create loft profile
                            //LoftProfile[] guideToLoft = new LoftProfile[1] { lpGuide };
                            //sol.CreateLoftedSolid(lps, guideToLoft, null, lpOptions);//guide to loft can not be null, this parameter is not optional
                            sol.CreateLoftedSolid(lps, null, null, lpOptions);
                            sol.Layer = sLayer;//assign layer

                            //=============save it into database
                            Autodesk.AutoCAD.DatabaseServices.Entity ent = sol;//this is created for using hyperlink
                            btr.AppendEntity(ent);
                            tr.AddNewlyCreatedDBObject(ent, true);
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage(ex.ToString()); }
                    }

                    tr.Commit();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Функция построения элементов радиаторной решетки
        /// </summary>
        /// <param name="database"> База данных</param>
        /// <param name="trans"> Транзакция</param>
        /// <param name="coordinateX"> Позиция центра по координате Х</param>
        /// <param name="coordinateZ"> Позиция центра по координате Z</param>
        private void BuildRadiator(Database database, Transaction trans, double coordinateX, double coordinateZ)
        {
            // Открываем таблицу блоков для чтения
            BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Открываем таблицу блоков модели для записи
            BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Создать новую фигуру
            double sizeLenBox      = _lenBox * 0.7;
            double sizeDiameretBox = _diameretBox / 8;

            Solid3d paw = new Solid3d();

            paw.SetDatabaseDefaults();
            paw.CreateBox(sizeDiameretBox, sizeLenBox, 5);
            paw.ColorIndex = 3;

            // Позиция центра отрисовки фигуры
            double coordY = -0.1 * _lenBox;

            paw.TransformBy(Matrix3d.Displacement(new Point3d(coordinateX, coordY, coordinateZ) - Point3d.Origin));


            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(paw);
            trans.AddNewlyCreatedDBObject(paw, true);
        }
예제 #3
0
        /// <summary>
        /// Функция построения части лапы мотора
        /// </summary>
        /// <param name="database"> База данных</param>
        /// <param name="trans"> Транзакция</param>
        /// <param name="width"> Ширина части лапы</param>
        /// <param name="len"> Длина части лапы</param>
        /// <param name="coordinateX"> Позиция центра по координате Х </param>
        /// <param name="coordinateZ"> Позиция центра по координате Z</param>
        /// <param name="angle"> Угол вращения</param>
        private void BuildPawsBox(Database database, Transaction trans, double width, double len, double coordinateX, double coordinateZ, double angle)
        {
            double r     = _diameretBox / 2;
            double koord = (r * ((Math.Sqrt(2) - 1) / 2) + r) / Math.Sqrt(2);

            // Открываем таблицу блоков для чтения
            BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Открываем таблицу блоков модели для записи
            BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Создать новую фигуру
            Solid3d paw = new Solid3d();

            paw.SetDatabaseDefaults();
            paw.CreateBox(width, len, 20);
            paw.ColorIndex = 7;

            // Позиция центра отрисовки фигуры
            paw.TransformBy(Matrix3d.Displacement(new Point3d(coordinateX, 0, coordinateZ) - Point3d.Origin));
            Vector3d vRotPaw = new Point3d(0, 0, 0).GetVectorTo(new Point3d(0, 1, 0));

            paw.TransformBy(Matrix3d.Rotation(angle, vRotPaw, new Point3d(coordinateX, 0, coordinateZ)));

            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(paw);
            trans.AddNewlyCreatedDBObject(paw, true);
        }
예제 #4
0
파일: Rotor.cs 프로젝트: sanjaysy/ORSAPR
        /// <summary>
        /// Функция построения вала
        /// </summary>
        /// <param name="database">База данных</param>
        /// <param name="Trans">Транзакция</param>
        /// <param name="parameters">Класс с параметрами построения мотора</param>
        public void Build(Database database, Transaction trans, MotorParameters parameters)
        {
            int diameretRotor = _diameretRotor;
            int lenRotor      = _lenRotor;
            int lenPin        = _lenPin;

            int lenBox = parameters.LenBox;

            // Открываем таблицу блоков для чтения
            BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Открываем таблицу блоков модели для записи
            BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Создам новый цилиндр
            Solid3d rotor = new Solid3d();

            rotor.SetDatabaseDefaults();
            rotor.CreateFrustum(lenRotor, diameretRotor / 2, diameretRotor / 2, diameretRotor / 2);
            rotor.ColorIndex = 4;

            // Позиция центра отрисовки обьекта
            rotor.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenRotor / 2 - lenBox / 2, 0) - Point3d.Origin));

            double   angleRotate = Math.PI / 2;
            Vector3d vRotRotor   = new Point3d(0, 0, 0).GetVectorTo(new Point3d(1, 0, 0));

            rotor.TransformBy(Matrix3d.Rotation(angleRotate, vRotRotor, new Point3d(0, -lenRotor / 2 - lenBox / 2, 0)));

            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(rotor);
            trans.AddNewlyCreatedDBObject(rotor, true);

            // Созать новую фигуру
            Solid3d pin = new Solid3d();

            pin.SetDatabaseDefaults();
            pin.CreateBox(diameretRotor / 10, lenPin, diameretRotor / 10);
            pin.ColorIndex = 7;

            // Позиция центра
            pin.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenBox / 2 - lenRotor + lenPin / 2, diameretRotor / 2) - Point3d.Origin));

            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(pin);
            trans.AddNewlyCreatedDBObject(pin, true);
        }
예제 #5
0
        private Solid3d CreateSphere()
        {
            // create the sphere
            Solid3d sphere = new Solid3d();

            sphere.SetDatabaseDefaults();
            // let's create a random number generator for the sphere
            Random randomGenerator = new Random();
            double radius          = randomGenerator.NextDouble() * 50;

            // create the sphere
            sphere.CreateSphere(radius);
            // randomize the position using the randomizer!
            Matrix3d randomMover;
            double   xVec = randomGenerator.NextDouble() * 500;
            double   yVec = randomGenerator.NextDouble() * 400;
            double   zVec = randomGenerator.NextDouble() * 300;

            randomMover = Matrix3d.Displacement(new Vector3d(xVec, yVec, zVec));
            // now apply the the transform to the sphere
            sphere.TransformBy(randomMover);

            // set the material name
            const string matname = "Sitework.Paving - Surfacing.Riverstone.Mortared";

            using (DBDictionary matdict = mPreviewCtrl.mCurrentDwg.MaterialDictionaryId.Open(OpenMode.ForRead) as DBDictionary)
            {
                // if we have found the material, set it to the sphere
                if (matdict.Contains(matname))
                {
                    sphere.Material = matname;
                }
                else
                {
                    // get the editor object
                    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
                    ed.WriteMessage("\nMaterial (" + matname + ") not found" + " - sphere will be rendered without it.", matname);
                }
            }

            return(sphere);
        }
예제 #6
0
파일: Findings.cs 프로젝트: sanjaysy/ORSAPR
        /// <summary>
        /// Функция отрисовки портов вывода
        /// </summary>
        /// <param name="database">База данныйх</param>
        /// <param name="Trans">Транцакция</param>
        /// <param name="parameters">Класс с параметрами построения мотора</param>
        /// <param name="positionPort">Позиция отверстия</param>
        /// <param name="Figure">Обьект класса</param>
        /// <param name="x">Позиция центра по координате Х</param>
        /// <param name="y">Позиция центра по координате Y</param>
        /// <param name="z">Позиция центра по координате Z</param>
        private void Ports(Database database, Transaction trans, MotorParameters parameters, int positionPort, Solid3d figure, double x, double y, double z)
        {
            // Открываем таблицу блоков для чтения
            BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Открываем таблицу блоков модели для записи
            BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Создаем 3D обьект - прямоугольник
            Solid3d port = new Solid3d();

            port.SetDatabaseDefaults();
            port.CreateFrustum(_widthFindings * (parameters.CountPorts - positionPort), _diameretPorts / 2, _diameretPorts / 2, _diameretPorts / 2);
            port.ColorIndex = 4;

            // Перемещение и и поворот
            port.TransformBy(Matrix3d.Displacement(new Point3d(x, y, z) - Point3d.Origin));
            Vector3d vRotPort = new Point3d(0, 0, 0).GetVectorTo(new Point3d(0, 1, 0));

            port.TransformBy(Matrix3d.Rotation(Math.PI / 2, vRotPort, new Point3d(x, y, z)));
            blockTableRecord.AppendEntity(port);
            trans.AddNewlyCreatedDBObject(port, true);
            figure.BooleanOperation(BooleanOperationType.BoolSubtract, port);
        }
예제 #7
0
파일: Findings.cs 프로젝트: sanjaysy/ORSAPR
        /// <summary>
        /// Функция построения коробки выводов
        /// </summary>
        /// <param name="database">База данный объектов </param>
        /// <param name="Trans">Транзакции</param>
        /// <param name="parameters">Класс с параметрами построения мотора</param>
        public void Build(Database database, Transaction trans, MotorParameters parameters)
        {
            int widthFindings  = _widthFindings;
            int lenFindings    = _lenFindings;
            int heightFindings = _heightFindings;

            int countPorts    = _countPorts;
            int diameretPorts = _diameretPorts;

            int lenBox      = parameters.LenBox;
            int diameretBox = parameters.DiameretBox;

            // Коэффициенты трансформации
            double transformationFactorLen    = 1.2;
            double transformationFactorHeight = 0.1;

            // Открываем таблицу блоков для чтения
            BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Открываем таблицу блоков модели для записи
            BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Создаем 3D обьект - прямоугольник
            Solid3d findings = new Solid3d();

            findings.SetDatabaseDefaults();
            findings.CreateBox(widthFindings, lenFindings, heightFindings);
            findings.ColorIndex = 7;

            // Задаем позицию центра 3D обьекта
            findings.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenBox / 2 + transformationFactorLen * lenFindings / 2, diameretBox / 2 + heightFindings / 2 - transformationFactorHeight * heightFindings) - Point3d.Origin));

            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(findings);
            trans.AddNewlyCreatedDBObject(findings, true);

            // Параметры
            double cavityWidth  = widthFindings * 0.8;
            double cavityLen    = lenFindings * 0.9;
            double cavityHeight = heightFindings * 0.8;

            // Создать новую фигуру
            Solid3d cavity = new Solid3d();

            cavity.SetDatabaseDefaults();
            cavity.CreateBox(cavityWidth, cavityLen, cavityHeight);
            cavity.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenBox / 2 + transformationFactorLen * lenFindings / 2, diameretBox / 2 + heightFindings / 2 - transformationFactorHeight * heightFindings) - Point3d.Origin));

            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(cavity);
            trans.AddNewlyCreatedDBObject(cavity, true);

            findings.BooleanOperation(BooleanOperationType.BoolSubtract, cavity);


            double coordZ = diameretBox / 2 + heightFindings / 2 - transformationFactorHeight * heightFindings;
            double coordX = widthFindings / 3;


            if (countPorts >= 1)
            {
                double y1 = -lenBox / 2 + (transformationFactorLen * lenFindings / 2 + lenFindings / 3);
                Ports(database, trans, parameters, 0, findings, coordX, y1, coordZ);
            }
            if (countPorts > 2)
            {
                double y2 = -lenBox / 2 + (transformationFactorLen * lenFindings / 2);
                Ports(database, trans, parameters, 2, findings, coordX, y2, coordZ);
            }
            if (countPorts > 4)
            {
                double y3 = -lenBox / 2 + (transformationFactorLen * lenFindings / 2 - lenFindings / 3);
                Ports(database, trans, parameters, 4, findings, -coordX, y3, coordZ);
            }
        }
예제 #8
0
        /// <summary>
        /// Функция построения корпуса мотора
        /// </summary>
        /// <param name="database">База данных</param>
        /// <param name="trans">Транцакция</param>
        /// <param name="parameters">Класс с параметрами построения мотора</param>
        public void Build(Database database, Transaction trans, MotorParameters parameters)
        {
            int lenBox      = _lenBox;
            int diameretBox = _diameretBox;

            // Открываем таблицу блоков для чтения
            BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

            // Открываем таблицу блоков модели для записи
            BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            Solid3d box = new Solid3d();

            box.SetDatabaseDefaults();
            box.CreateFrustum(lenBox, diameretBox / 2, diameretBox / 2, diameretBox / 2);
            box.ColorIndex = 4;

            // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию
            blockTableRecord.AppendEntity(box);
            trans.AddNewlyCreatedDBObject(box, true);

            ObjectId[] ids = new ObjectId[] { box.ObjectId };

            SubentityId subentId = new SubentityId(SubentityType.Null, IntPtr.Zero);

            FullSubentityPath path = new FullSubentityPath(ids, subentId);

            List <SubentityId> subentIds    = new List <SubentityId>();
            DoubleCollection   radii        = new DoubleCollection();
            DoubleCollection   startSetback = new DoubleCollection();
            DoubleCollection   endSetback   = new DoubleCollection();

            // Углы скругления
            double angTop  = 60.0;
            double angDown = 15.0;

            using (Autodesk.AutoCAD.BoundaryRepresentation.Brep brep = new Autodesk.AutoCAD.BoundaryRepresentation.Brep(path))
            {
                foreach (Autodesk.AutoCAD.BoundaryRepresentation.Edge edge in brep.Edges)
                {
                    if (edge.Vertex1.Point.Z == -lenBox / 2)
                    {
                        subentIds.Add(edge.SubentityPath.SubentId);
                        radii.Add(angTop);

                        startSetback.Add(0.0);
                        endSetback.Add(angDown);
                    }
                    if (edge.Vertex1.Point.Z == lenBox / 2)
                    {
                        subentIds.Add(edge.SubentityPath.SubentId);
                        radii.Add(angDown);

                        startSetback.Add(0.0);
                        endSetback.Add(angDown);
                    }
                }
            }

            box.FilletEdges(subentIds.ToArray(), radii, startSetback, endSetback);

            // Позиция центра новой фигуры
            box.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, 0) - Point3d.Origin));

            double   angleRotate = Math.PI / 2;
            Vector3d vRot        = new Point3d(0, 0, 0).GetVectorTo(new Point3d(1, 0, 0));

            box.TransformBy(Matrix3d.Rotation(angleRotate, vRot, new Point3d(0, 0, 0)));

            double radiusBox  = diameretBox / 2;
            double coordinate = (radiusBox * ((Math.Sqrt(2) - 1) / 2) + radiusBox) / Math.Sqrt(2);

            // Отрисовка лап
            double lenPaw = 0.9 * lenBox;

            BuildPawsBox(database, trans, radiusBox / 2, lenBox, radiusBox, -radiusBox, 0);
            BuildPawsBox(database, trans, radiusBox / 2, lenPaw, coordinate, -coordinate, angleRotate / 2);
            BuildPawsBox(database, trans, radiusBox / 2, lenBox, -radiusBox, -radiusBox, 0);
            BuildPawsBox(database, trans, radiusBox / 2, lenPaw, -coordinate, -coordinate, -angleRotate / 2);

            // Элементы радиатора
            int    n      = parameters.CountGrille;
            double coordX = 0;
            double coordZ = 0;
            double angleRadiatorElements = 40;
            double angleRadiatorStep     = 5;

            if (n > 1)
            {
                angleRadiatorStep = 80 / (n - 1);
            }

            for (int i = 0; i < n; i++)
            {
                if (angleRadiatorElements <= 40 && angleRadiatorElements >= -40)
                {
                    coordX = radiusBox * Math.Cos(angleRadiatorElements * Math.PI / 180);
                    coordZ = radiusBox * Math.Sin(angleRadiatorElements * Math.PI / 180);

                    BuildRadiator(database, trans, coordX, coordZ);
                    BuildRadiator(database, trans, -coordX, coordZ);

                    angleRadiatorElements -= angleRadiatorStep;
                }
            }
        }
예제 #9
0
        public static Point3d DistFromPointToSolid(
            ref Document doc, ref Solid3d solid, Point3d point, double start, double step, ref double off, bool line)
        {
            var rez = new Point3d();

            using (var acTrans = doc.Database.TransactionManager.StartTransaction())
            {
                var acBlkTbl = (BlockTable)acTrans.GetObject(doc.Database.BlockTableId, OpenMode.ForWrite);

                var acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                var SOLID = (Solid3d)solid.Clone();
                SOLID.SetDatabaseDefaults();
                acBlkTblRec.AppendEntity(SOLID);
                acTrans.AddNewlyCreatedDBObject(SOLID, true);


                var startR = start <= 0 ? step : start;

                var sphere = new Solid3d();
                sphere.SetDatabaseDefaults();
                sphere.CreateSphere(startR);
                sphere.TransformBy(Matrix3d.Displacement(Point3d.Origin.GetVectorTo(point)));
                sphere.SetDatabaseDefaults();
                acBlkTblRec.AppendEntity(sphere);
                acTrans.AddNewlyCreatedDBObject(sphere, true);


                while (sphere.CheckInterference(solid) == false)
                {
                    try
                    {
                        sphere.OffsetBody(step);
                        off += step;
                    }
                    catch
                    {
                    }
                }

                if (line)
                {
                    var counter = 0;

                    sphere.BooleanOperation(BooleanOperationType.BoolIntersect, SOLID);
                    var dbo = new DBObjectCollection();
                    sphere.Explode(dbo);

                    var coll       = new Point3dCollection();
                    var curvesColl = new DBObjectCollection();

                    var ent = dbo[0] as Entity;
                    if (ent.GetType().ToString().IndexOf("Surface") > 0)
                    {
                        var surf =
                            ent as Surface;
                        var ns = surf.ConvertToNurbSurface();
                        foreach (var nurb in ns)
                        {
                            double ustart   = nurb.UKnots.StartParameter,
                                     uend   = nurb.UKnots.EndParameter,
                                     uinc   = (uend - ustart) / nurb.UKnots.Count,
                                     vstart = nurb.VKnots.StartParameter,
                                     vend   = nurb.VKnots.EndParameter,
                                     vinc   = (vend - vstart) / nurb.VKnots.Count;

                            for (var u = ustart; u <= uend; u += uinc)
                            {
                                for (var v = vstart; v <= vend; v += vinc)
                                {
                                    coll.Add(nurb.Evaluate(u, v));
                                    counter++;
                                }
                            }
                        }
                        if (counter < 1)
                        {
                            var sub = new DBObjectCollection();
                            surf.Explode(sub);
                            foreach (Entity entt in sub)
                            {
                                acBlkTblRec.AppendEntity(entt);
                                acTrans.AddNewlyCreatedDBObject(entt, true);
                                curvesColl.Add(entt);
                            }
                        }
                    }
                    else
                    {
                        var surf = (Region)ent;
                        var p1   = surf.GeometricExtents.MaxPoint;
                        var p2   = surf.GeometricExtents.MinPoint;
                        var p    = new Point3d((p1.X + p2.X) / 2.0, (p1.Y + p2.Y) / 2.0, (p1.Z + p2.Z) / 2.0);
                        coll.Add(p);
                        coll.Add(p);
                        var sub = new DBObjectCollection();
                        surf.Explode(sub);
                        foreach (Entity entt in sub)
                        {
                            acBlkTblRec.AppendEntity(entt);
                            acTrans.AddNewlyCreatedDBObject(entt, true);
                            curvesColl.Add(entt);
                        }
                    }

                    foreach (DBObject ob in curvesColl)
                    {
                        var curve = (Curve)acTrans.GetObject(ob.Id, OpenMode.ForRead);
                        var p1    = curve.StartPoint;
                        var p2    = curve.EndPoint;
                        var p     = new Point3d((p1.X + p2.X) / 2.0, (p1.Y + p2.Y) / 2.0, (p1.Z + p2.Z) / 2.0);

                        coll.Add(p);
                        coll.Add(p1);
                        coll.Add(p2);
                    }

                    if (coll.Count > 0)
                    {
                        rez = coll[0];
                        foreach (Point3d p in coll)
                        {
                            if (p.DistanceTo(point) < rez.DistanceTo(point))
                            {
                                rez = p;
                            }
                        }
                    }
                    else
                    {
                        rez = point;
                    }
                }
                // acTrans.Commit();
            }
            return(rez);
        }