Пример #1
0
        poly3d_pnt3dColl(Polyline3d poly3d)
        {
            Point3dCollection pnts3d = new Point3dCollection();

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    foreach (ObjectId objID in poly3d)
                    {
                        PolylineVertex3d v3d   = (PolylineVertex3d)tr.GetObject(objID, OpenMode.ForRead);
                        Point3d          pnt3d = new Point3d();
                        pnt3d = v3d.Position;

                        pnts3d.Add(pnt3d);
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Conv.cs: line: 521");
            }
            return(pnts3d);
        }
Пример #2
0
        public static List <Point3d> GetPointsFrom3dPolyline(Polyline3d poly3d, Document doc)
        {
            Database db = doc.Database;
            Editor   ed = doc.Editor;

            List <Point3d> pts = new List <Point3d>();

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                if (poly3d != null)
                {
                    // Use foreach to get each contained vertex
                    foreach (ObjectId vId in poly3d)
                    {
                        PolylineVertex3d v3d = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
                        Point3d          pt  = new Point3d(v3d.Position.X, v3d.Position.Y, v3d.Position.Z);

                        pts.Add(pt);

                        ed.WriteMessage($"GetPointsFrom3dPolyline => {pt.X}, {pt.Y}, {pt.Z}\n");
                    }
                }

                tr.Commit();
            }
            return(pts);
        }
Пример #3
0
        addPoly3d(this List <Point3d> pnt3ds, string nameLayer = "0", short color = 256)
        {
            ObjectId   idPoly3d = ObjectId.Null;
            Polyline3d poly3d   = new Polyline3d();

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTable       bt = (BlockTable)BaseObjs._db.BlockTableId.GetObject(OpenMode.ForRead);
                    BlockTableRecord MS = (BlockTableRecord)bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite);

                    idPoly3d = MS.AppendEntity(poly3d);
                    tr.AddNewlyCreatedDBObject(poly3d, true);

                    poly3d.SetDatabaseDefaults();
                    Layer.manageLayers(nameLayer);
                    poly3d.Layer = nameLayer;
                    poly3d.Color = Color.FromColorIndex(ColorMethod.ByBlock, color);
                    foreach (Point3d pnt3d in pnt3ds)
                    {
                        PolylineVertex3d poly3dVertex = new PolylineVertex3d(pnt3d);
                        poly3d.AppendVertex(poly3dVertex);
                        tr.AddNewlyCreatedDBObject(poly3dVertex, true);
                    }
                    tr.Commit();
                }// end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Draw.cs: line: 406");
            }
            return(idPoly3d);
        }
Пример #4
0
        addPoly3d(Point3d[] pnt3ds, string nameLayer = "0", short color = 256)
        {
            ObjectId   idPoly3d = ObjectId.Null;
            Polyline3d poly3d   = new Polyline3d();

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTableRecord MS = Blocks.getBlockTableRecordMS();

                    idPoly3d = MS.AppendEntity(poly3d);
                    tr.AddNewlyCreatedDBObject(poly3d, true);

                    int i = -1;
                    poly3d.SetDatabaseDefaults();
                    Layer.manageLayers(nameLayer);
                    poly3d.Layer = nameLayer;
                    poly3d.Color = Color.FromColorIndex(ColorMethod.ByBlock, color);
                    foreach (Point3d pnt3d in pnt3ds)
                    {
                        i = ++i;
                        PolylineVertex3d poly3dVertex = new PolylineVertex3d(pnt3d);
                        poly3d.AppendVertex(poly3dVertex);
                        tr.AddNewlyCreatedDBObject(poly3dVertex, true);
                    }
                    tr.Commit();
                }// end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Draw.cs: line: 443");
            }
            return(idPoly3d);
        }
Пример #5
0
        updatePoly3dCoordinates(this ObjectId idPoly3dOrg, List <Point3d> pnts3d)
        {
            ObjectId   idPoly3dNew = ObjectId.Null;
            Polyline3d poly3dNew   = new Polyline3d();

            using (Transaction tr = BaseObjs.startTransactionDb())
            {
                BlockTableRecord ms = Blocks.getBlockTableRecordMS();
                idPoly3dNew = ms.AppendEntity(poly3dNew);

                poly3dNew.SetDatabaseDefaults();
                poly3dNew.Layer = idPoly3dOrg.getLayer();
                foreach (Point3d pnt3dX in pnts3d)
                {
                    PolylineVertex3d v3d = new PolylineVertex3d(pnt3dX);
                    poly3dNew.AppendVertex(v3d);
                    tr.AddNewlyCreatedDBObject(v3d, true);
                }
                tr.AddNewlyCreatedDBObject(poly3dNew, true);
                tr.Commit();
            }

            using (Transaction tr1 = BaseObjs.startTransactionDb())
            {
                DBObject dbObjOrg = tr1.GetObject(idPoly3dOrg, OpenMode.ForRead);
                DBObject dbObjNew = tr1.GetObject(idPoly3dNew, OpenMode.ForRead);

                dbObjNew.UpgradeOpen();
                dbObjNew.SwapIdWith(dbObjOrg.ObjectId, true, true);

                idPoly3dNew.delete();
                tr1.Commit();
            }
        }
Пример #6
0
        public static void Flatten(this Entity obj)
        {
            Transaction acTrans = obj.Database.TransactionManager.TopTransaction;

            //TODO: Is this the right place, add more types?
            switch (obj)
            {
            case Polyline polyline:
            {
                polyline.Elevation = 0;
                break;
            }

            case Polyline2d polyline2d:
            {
                polyline2d.Elevation = 0;
                break;
            }

            case Polyline3d polyline3d:
            {
                foreach (ObjectId id in polyline3d)
                {
                    PolylineVertex3d plv3d = (PolylineVertex3d)acTrans.GetObject(id, OpenMode.ForWrite);
                    Point3d          p3d   = plv3d.Position;
                    plv3d.Position = new Point3d(p3d.X, p3d.Y, 0);
                }

                break;
            }

            default:
                throw new NotImplementedException();
            }
        }
Пример #7
0
    public crawlAcDbPolyline(Polyline3d polyline)
    {
        Entity ent = (Entity)polyline;

        this.ObjectId = ent.ObjectId.ToString();

        Length          = polyline.Length;
        this.Layer      = polyline.Layer;
        this.Linetype   = polyline.Linetype;
        this.LineWeight = polyline.LineWeight.ToString();
        this.Color      = polyline.Color.ToString();

        Vertixes = new List <crawlPoint3d>();

        // Use foreach to get each contained vertex
        foreach (ObjectId vId in polyline)
        {
            PolylineVertex3d v3d =
                (PolylineVertex3d)
                vId.GetObject(OpenMode.ForRead);
            double x = v3d.Position.X;
            double y = v3d.Position.Y;
            double z = v3d.Position.Z;
            Vertixes.Add(new crawlPoint3d(x, y, z));
        }
    }
Пример #8
0
        private static Polyline Polyline3dToPolyline(Polyline3d polyline3d)
        {
            Document doc   = DatabaseUtil.GetActiveDocument();
            Database db    = doc.Database;
            Polyline oPoly = null;

            try
            {
                using (doc.LockDocument())
                {
                    using (Transaction tr = DatabaseUtil.GetTransaction(db))
                    {
                        oPoly = new Polyline();
                        ObjectId[] idVtcies = polyline3d.Cast <ObjectId>().ToArray();

                        for (int i = 0; i < idVtcies.Length; i++)
                        {
                            PolylineVertex3d oVtx = tr.GetObject(idVtcies[i], OpenMode.ForWrite) as PolylineVertex3d;
                            oPoly.AddVertexAt(i, GeometryUtil.ToPoint2d(oVtx.Position), 0, 0, 0);
                        }

                        oPoly.Layer = polyline3d.Layer;
                        oPoly.Color = polyline3d.Color;
                    }
                }

                return(oPoly);
            }
            catch
            {
                return(null);
            }
        }
Пример #9
0
        public static double GetElevation(this Polyline3d pl)
        {
            double?height = null;

            using (var myTrans = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
            {
                foreach (ObjectId oid in pl)
                {
                    PolylineVertex3d v2d = myTrans.GetObject(oid, OpenMode.ForRead) as PolylineVertex3d;
                    if (v2d != null)
                    {
                        height = v2d.Position.Z;
                    }
                    break;
                }

                myTrans.Commit();
            }
            if (height.HasValue)
            {
                return(height.Value);
            }

            throw new InvalidOperationException("\nUngültige 3d-Polylinie!");
        }
Пример #10
0
        /// <summary>
        /// create the 3D polyline in specifed layer
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="pts"></param>
        /// <param name="layerName"></param>
        /// <returns></returns>
        public static Polyline3d CreatePolylineFromPoint(Document doc, List <Point3d> pts, string layerName)
        {
            Polyline3d pl = new Polyline3d();

            Database db = doc.Database;

            #region create polyline with points
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockTable       bt  = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

                    pl.Layer = layerName;

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


                    foreach (Point3d pt in pts)
                    {
                        PolylineVertex3d vex3d = new PolylineVertex3d(pt);
                        pl.AppendVertex(vex3d);//apdd point into 3d polyline
                        tr.AddNewlyCreatedDBObject(vex3d, true);
                    }
                }
                catch { }
                tr.Commit();
            }

            #endregion
            return(pl);
        }
Пример #11
0
        public ILineString ReadLineString(Transaction tr, Polyline3d polyline3D)
        {
            var coordinateList = new CoordinateList();

            if (polyline3D.PolyType == Poly3dType.SimplePoly) // 0??
            {
                foreach (var v in polyline3D)
                {
                    PolylineVertex3d vertex = null;
                    if (v is ObjectId)
                    {
                        vertex = tr.GetObject((ObjectId)v, OpenMode.ForRead) as PolylineVertex3d;
                    }
                    else if (v is PolylineVertex3d)
                    {
                        vertex = (PolylineVertex3d)v;
                    }

                    if (vertex != null)
                    {
                        coordinateList.Add(this.ReadCoordinate(vertex.Position), this.AllowRepeatedCoordinates);
                    }
                }
            }
            else
            {
                var dBObjectCollection = new DBObjectCollection();
                polyline3D.Explode(dBObjectCollection);
                try
                {
                    foreach (var dBObject in dBObjectCollection)
                    {
                        var line = (Line)dBObject;
                        coordinateList.Add(this.ReadCoordinate(line.StartPoint), false);
                        coordinateList.Add(this.ReadCoordinate(line.EndPoint), false);
                    }
                }
                finally
                {
                    foreach (var dBObject in dBObjectCollection)
                    {
                        if (dBObject is IDisposable)
                        {
                            (dBObject as IDisposable).Dispose();
                        }
                    }
                }
                dBObjectCollection.Dispose();
            }

            if (polyline3D.Closed)
            {
                coordinateList.Add(coordinateList[0]);
            }
            if (coordinateList.Count > 1)
            {
                return(this.GeometryFactory.CreateLineString(coordinateList.ToCoordinateArray()));
            }
            return(LineString.Empty);
        }
Пример #12
0
        /// <summary>
        /// Listing vertices of polylines (LWPOLYLINE, 2D & 3D POLYLINE)
        /// </summary>
        /// <param name="tr"></param>
        /// <param name="polylines">Polylines objectID</param>
        /// <returns></returns>
        public static Point3dCollection ListVertices(Transaction tr, ObjectIdCollection polylines)
        {
            Point3dCollection coords = new Point3dCollection();

            using (tr)
            {
                foreach (ObjectId id in polylines)
                {
                    DBObject obj = tr.GetObject(id, OpenMode.ForRead);

                    // If a lwPolyline
                    Polyline lwp = obj as Polyline;
                    if (lwp != null)
                    {
                        int vn = lwp.NumberOfVertices;
                        for (int i = 0; i < vn; i++)
                        {
                            // Could also get the 2D point here
                            Point3d pt = lwp.GetPoint3dAt(i);
                            coords.Add(pt);
                        }
                    }
                    else
                    {
                        // If an old-style, 2D polyline
                        Polyline2d p2d = obj as Polyline2d;
                        if (p2d != null)
                        {
                            foreach (ObjectId vId in p2d)
                            {
                                Vertex2d v2d = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead);
                                coords.Add(v2d.Position);
                            }
                        }
                        else
                        {
                            // If an old-style, 3D polyline
                            Polyline3d p3d = obj as Polyline3d;
                            if (p3d != null)
                            {
                                // Use foreach to get each contained vertex
                                foreach (ObjectId vId in p3d)
                                {
                                    PolylineVertex3d v3d = (PolylineVertex3d)tr.GetObject(
                                        vId,
                                        OpenMode.ForRead
                                        );
                                    coords.Add(v3d.Position);
                                }
                            }
                        }
                    }
                }
                tr.Commit();
            }
            return(coords);
        }
Пример #13
0
        addVertexToPoly3d(this ObjectId idPoly3dOrg, Point3d pnt3d, int pos, Handle hCgPNt)
        {
            List <Point3d> pnts3d      = idPoly3dOrg.getCoordinates3dList();
            ObjectId       idPoly3dNew = ObjectId.Null;
            Polyline3d     poly3dNew   = new Polyline3d();

            using (Transaction tr = BaseObjs.startTransactionDb())
            {
                BlockTableRecord ms = Blocks.getBlockTableRecordMS();
                idPoly3dNew = ms.AppendEntity(poly3dNew);

                poly3dNew.SetDatabaseDefaults();
                poly3dNew.Layer = idPoly3dOrg.getLayer();
                pnts3d.Insert(pos + 1, pnt3d);
                foreach (Point3d pnt3dX in pnts3d)
                {
                    PolylineVertex3d v3d = new PolylineVertex3d(pnt3dX);
                    poly3dNew.AppendVertex(v3d);
                    tr.AddNewlyCreatedDBObject(v3d, true);
                }
                tr.AddNewlyCreatedDBObject(poly3dNew, true);
                tr.Commit();
            }

            using (Transaction tr1 = BaseObjs.startTransactionDb())
            {
                DBObject dbObjOrg = tr1.GetObject(idPoly3dOrg, OpenMode.ForRead);
                DBObject dbObjNew = tr1.GetObject(idPoly3dNew, OpenMode.ForRead);

                dbObjNew.UpgradeOpen();
                dbObjNew.SwapIdWith(dbObjOrg.ObjectId, true, true);

                idPoly3dNew.delete();
                tr1.Commit();
            }

            ResultBuffer rb = idPoly3dOrg.getXData(apps.lnkBrks);

            TypedValue[] tvs = rb.AsArray();

            TypedValue[] tvsNew = new TypedValue[tvs.Length + 1];
            for (int i = 0; i < pos + 2; i++)
            {
                tvsNew[i] = tvs[i];
            }
            tvsNew.SetValue(new TypedValue(1005, hCgPNt), pos + 2);

            for (int i = pos + 2; i < tvs.Length; i++)
            {
                tvsNew[i + 1] = tvs[i];
            }

            idPoly3dOrg.clearXData(apps.lnkBrks);
            idPoly3dOrg.setXData(tvsNew, apps.lnkBrks);
        }
Пример #14
0
        private Polyline3d GetRail(Point3d startPoint, Curve curve1, Curve curve2)
        {
            if (!curve1.StartPoint.IsEqualTo(startPoint))
            {
                curve1.ReverseCurve();
            }

            Polyline3d polyline = null;

            if (curve1 is Line line)
            {
                polyline = line.ToPolyline3d();
            }
            else if (curve1 is Spline spline)
            {
                polyline = (Polyline3d)spline.ToPolyline();
            }

            ObjectId objectId = ObjectId.Null;

            App.LockAndExecute(() => objectId = polyline.AddToCurrentSpace());

            var ep = polyline.EndPoint;

            if (!curve2.StartPoint.IsEqualTo(ep))
            {
                curve2.ReverseCurve();
            }

            App.LockAndExecute(() =>
            {
                objectId.QOpenForWrite <Polyline3d>(pl =>
                {
                    if (curve2 is Line line2)
                    {
                        var pt = line2.NextPoint(ep);
                        pl.AppendVertex(new PolylineVertex3d(pt));
                    }
                    else if (curve2 is Spline spline2)
                    {
                        foreach (var vertex in (Polyline3d)spline2.ToPolyline())
                        {
                            if (!((PolylineVertex3d)vertex).Position.IsEqualTo(ep))
                            {
                                var v = new PolylineVertex3d(((PolylineVertex3d)vertex).Position);

                                pl.AppendVertex(v);
                            }
                        }
                    }
                });
            });
            return(objectId.QOpenForRead <Polyline3d>());
        }
Пример #15
0
        private void CreatePolyline(List <SimplePoint3d> points)
        {
            Polyline3d polyline = new Polyline3d();

            _transaction.AddObjectToActiveModelSpace(polyline);
            foreach (SimplePoint3d point in points)
            {
                var point3d = new Point3d(point.X, point.Y, point.Z);
                using (PolylineVertex3d vertex = new PolylineVertex3d(point3d)) {
                    polyline.AppendVertex(vertex);
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Gets the vertices of a polyline.
        /// </summary>
        /// <param name="polyline">Polyline, Polyline2d, or Polyline3d from which to obtain the vertices</param>
        public static Point3dCollection GetVertices(Curve polyline)
        {
            Point3dCollection vertices = new Point3dCollection();

            if (polyline is Polyline)
            {
                Polyline pline = (Polyline)polyline;

                for (int i = 0; i < pline.NumberOfVertices; i++)
                {
                    vertices.Add(pline.GetPoint3dAt(i));
                }
            }
            else
            {
                Database    database    = HostApplicationServices.WorkingDatabase;
                Transaction transaction = database.TransactionManager.StartTransaction();

                if (polyline is Polyline2d)
                {
                    Polyline2d pline2d = (Polyline2d)polyline;

                    foreach (Object vertex in pline2d)
                    {
                        if (vertex is Vertex2d)
                        {
                            vertices.Add(((Vertex2d)vertex).Position);
                        }
                        else if (vertex is ObjectId)
                        {
                            vertices.Add(((Vertex2d)transaction.GetObject((ObjectId)vertex, OpenMode.ForRead)).Position);
                        }
                    }
                }

                else if (polyline is Polyline3d)
                {
                    Polyline3d pline3d = (Polyline3d)polyline;

                    foreach (ObjectId vertexId in pline3d)
                    {
                        PolylineVertex3d vertex = (PolylineVertex3d)transaction.GetObject(vertexId, OpenMode.ForRead);
                        vertices.Add(vertex.Position);
                    }
                }

                transaction.Dispose();
            }

            return(vertices);
        }
Пример #17
0
        /// <summary>
        ///  Adds vertices to a polyline and adds it to a transaction.
        /// </summary>
        /// <param name="polyLine"></param>
        /// <param name="pointCollection"></param>
        public static void AddVertices(this Polyline3d polyLine, Point3dCollection pointCollection)
        {
            AutoCadHelper.AppendAndAddToTransaction(polyLine);

            foreach (Point3d point in pointCollection)
            {
                var vertex = new PolylineVertex3d(point);
                polyLine.AppendVertex(vertex);
                AutoCadHelper.AddToTransaction(vertex);
            }

            // Erase the polyline before commiting so it's not drawn.
            polyLine.Erase();
        }
        private static Entity Draw3dPline(Point[] points, bool closePart)
        {
            Document   document           = AfaDocData.ActiveDocData.Document;
            Database   database           = document.Database;
            var        transactionManager = document.TransactionManager;
            Polyline3d polyline3d         = new Polyline3d();

            using (document.LockDocument())
            {
                using (Transaction transaction = transactionManager.StartTransaction())
                {
                    BlockTable       blockTable       = (BlockTable)transaction.GetObject(database.BlockTableId, 0);
                    BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[(BlockTableRecord.ModelSpace)], (OpenMode)1);
                    polyline3d.ColorIndex = (256);
                    blockTableRecord.AppendEntity(polyline3d);
                    transaction.AddNewlyCreatedDBObject(polyline3d, true);
                    int num = 0;
                    if (points != null && points.Length > 0)
                    {
                        for (int i = 0; i < points.Length; i++)
                        {
                            Point            point            = points[i];
                            PointN           pointN           = (PointN)point;
                            PolylineVertex3d polylineVertex3d = new PolylineVertex3d(new Point3d(pointN.X, pointN.Y, pointN.Z));
                            polyline3d.AppendVertex(polylineVertex3d);
                            num++;
                        }
                    }
                    if (num == 0)
                    {
                        return(null);
                    }
                    if (closePart)
                    {
                        polyline3d.Closed = (true);
                    }
                    polyline3d.ColorIndex = (256);
                    document.TransactionManager.QueueForGraphicsFlush();
                    document.TransactionManager.FlushGraphics();
                    document.Editor.UpdateScreen();
                    transaction.Commit();
                }
            }
            return(polyline3d);
        }
Пример #19
0
            public Polyline3dInfo(string code, Polyline3d poly3d)
            {
                Code   = code;
                Poly3d = poly3d;
                Poly2d = new Polyline();
                int vertNum = 0;

                foreach (ObjectId vId in poly3d)
                {
                    PolylineVertex3d v = vId.GetObject(OpenMode.ForRead) as PolylineVertex3d;

                    Point2d position2d = new Point2d(v.Position.X, v.Position.Y);
                    Poly2d.AddVertexAt(vertNum, position2d, 0, 0, 0);

                    vertNum++;
                }
                //Poly2d.ConvertFrom(poly3d, false);//Не работает
            }
Пример #20
0
        //convert parts to splines (works for line and arcs*Not arcs yet)
        static private Spline convertSpline(DBObject dbo)
        {
            if (dbo is Spline)
            {
                return(dbo as Spline);
            }
            if (dbo is Arc)
            {
                Arc    arcDat = dbo as Arc;
                Spline seg    = new Spline();
                //whatever that is
                return(seg);
            }
            else if (dbo is Line)
            {
                Line lDat = dbo as Line;
                Point3dCollection vertices = new Point3dCollection();
                vertices.Add(lDat.StartPoint);
                vertices.Add(lDat.EndPoint);
                Polyline3d tempPline = new Polyline3d();
                //polyine 3D has to be in btr before adding vertices
                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite));
                    btr.AppendEntity(tempPline);
                    foreach (Point3d pnt in vertices)
                    {
                        using (PolylineVertex3d poly3dVert = new PolylineVertex3d(pnt))
                        {
                            tempPline.AppendVertex(poly3dVert);
                        }
                    }
                    trans.Commit();
                }

                Spline seg = tempPline.Spline;
                tempPline.Erase(true);
                return(seg);
            }
            return(null);
        }
Пример #21
0
        polyX_listPnts3d(ObjectId id)
        {
            List <Point3d> pnts3d = new List <Point3d>();

            pnts3d.TrimExcess();
            Point3d pnt3d;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);

                    if (ent is Polyline3d)
                    {
                        Polyline3d poly3d = (Polyline3d)ent;
                        foreach (ObjectId objID in poly3d)
                        {
                            PolylineVertex3d v3d = (PolylineVertex3d)objID.GetObject(OpenMode.ForRead);
                            pnt3d = v3d.Position;
                            pnts3d.Add(pnt3d);
                        }
                    }
                    else if (ent is Polyline)
                    {
                        Polyline poly = (Polyline)ent;
                        for (int i = 0; i < poly.NumberOfVertices; i++)
                        {
                            pnt3d = poly.GetPoint3dAt(i);
                            pnts3d.Add(pnt3d);
                        }
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Conv.cs: line: 628");
            }

            return(pnts3d);
        }
Пример #22
0
        private static void CreatePolyline3dFromPoints(Database db, IEnumerable <Point3d> points, bool shouldClose)
        {
            var trans = db.TransactionManager.TopTransaction;

            var acBlkTbl    = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
            var acBlkTblRec = (BlockTableRecord)trans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

            var poly3d = new Polyline3d();

            acBlkTblRec.AppendEntity(poly3d);
            trans.AddNewlyCreatedDBObject(poly3d, true);

            foreach (var point in points)
            {
                using (var poly3dVertex = new PolylineVertex3d(point))
                {
                    poly3d.AppendVertex(poly3dVertex);
                }
            }

            poly3d.Closed = shouldClose;
        }
Пример #23
0
        /// <summary>
        /// project 3d polyline in XY plane, return a flattened polyline on XY plane and orignal 3d polyline
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="id">ObjectId of the 3d Polyline</param>
        /// <param name="originalPoly3d"></param>
        /// <returns></returns>
        public static Polyline3d CreatePolylineOnXYPlane(Document doc, ObjectId id, ref Polyline3d originalPoly3d)
        {
            Polyline3d pl = new Polyline3d();

            Database db = doc.Database;

            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 obj       = tr.GetObject(id, OpenMode.ForRead);
                Entity   ent       = obj as Entity;
                string   layerName = ent.Layer.ToString();

                pl.Layer = layerName;
                btr.AppendEntity(pl);
                tr.AddNewlyCreatedDBObject(pl, true);

                Polyline3d p3d = obj as Polyline3d;
                if (p3d != null)
                {
                    originalPoly3d = p3d;
                    foreach (ObjectId vId in p3d)
                    {
                        PolylineVertex3d v3d     = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
                        PolylineVertex3d v3d_new = new PolylineVertex3d(new Point3d(v3d.Position.X, v3d.Position.Y, 0));
                        pl.AppendVertex(v3d_new);//apdd point into 3d polyline
                        tr.AddNewlyCreatedDBObject(v3d_new, true);
                    }
                }

                tr.Commit();
            }

            return(pl);
        }
Пример #24
0
        poly3d_Poly(ObjectId idPoly3d, string nameLayer)
        {
            ObjectId id = ObjectId.Null;

            try
            {
                using (BaseObjs._acadDoc.LockDocument())
                {
                    using (Transaction tr = BaseObjs.startTransactionDb())
                    {
                        Polyline3d        poly3d = (Polyline3d)tr.GetObject(idPoly3d, OpenMode.ForRead);
                        Point3dCollection pnts3d = new Point3dCollection();
                        foreach (ObjectId vId in poly3d)
                        {
                            PolylineVertex3d v3d   = (PolylineVertex3d)vId.GetObject(OpenMode.ForRead);
                            Point3d          pnt3d = new Point3d();
                            pnt3d = v3d.Position;
                            try
                            {
                                pnts3d.Add(pnt3d);
                            }
                            catch (System.Exception ex)
                            {
                                BaseObjs.writeDebug(ex.Message + " Conv.cs: line: 577");
                            }
                        }
                        tr.Commit();
                        id = Draw.addPoly(pnts3d, nameLayer);
                    }
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Conv.cs: line: 587");
            }
            return(id);
        }
Пример #25
0
        public static List <Edge> ToCeometricEdgeList(Polyline3d pline3d)
        {
            Database    workingDatabase = HostApplicationServices.WorkingDatabase;
            List <Edge> list            = new List <Edge>();
            PointSet    pointSet        = new PointSet();

            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                foreach (ObjectId objectId in pline3d)
                {
                    PolylineVertex3d polylineVertex3d = (PolylineVertex3d)transaction.GetObject(objectId, (OpenMode)0);
                    pointSet.Add(new ngeometry.VectorGeometry.Point(polylineVertex3d.Position.X, polylineVertex3d.Position.Y, polylineVertex3d.Position.Z));
                }
                if (pline3d.Closed)
                {
                    pointSet.Add(pointSet[0]);
                }
            }
            for (int i = 0; i < pointSet.Count - 1; i++)
            {
                list.Add(new Edge(pointSet[i], pointSet[i + 1]));
            }
            return(list);
        }
        public void LandXmlHandling()
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;
            int pntListCount = 0;
            int profileCount = 0;
            int pviCount     = 0;

            string[] fileNames = OpenFiles();
            foreach (string fileName in fileNames)
            {
                XmlReader             reader = XmlReader.Create(fileName, settings);
                List <string>         alignmentCollection = new List <string>();
                List <List <double> > pntListCollection   = new List <List <double> >();
                List <double>         pviList             = new List <double>();
                try
                {
                    while (reader.Read())
                    {
                        if (reader.IsStartElement() == true)
                        {
                            switch (reader.Name)
                            {
                            case "PntList2D":
                                pntListCount++;
                                reader.Read();
                                Console.WriteLine("{0}.PntList", pntListCount);
                                Console.WriteLine(reader.Value);
                                Console.ReadLine();
                                List <double> pntList    = new List <double>();
                                string[]      pntListStr = reader.Value.Split(' ');
                                for (int i = 0; i < pntListStr.Length; i += 2)
                                {
                                    pntList.Add(Convert.ToDouble(pntListStr[i + 1]));
                                    pntList.Add(Convert.ToDouble(pntListStr[i]));
                                    Console.WriteLine("{0}", pntList[i]);
                                }
                                pntListCollection.Add(pntList);
                                break;


                            case "ProfAlign":
                                if (pntListCollection.Count == 0)
                                {
                                    break;
                                }
                                profileCount++;
                                Console.WriteLine("{0}.Profile", profileCount);
                                Console.WriteLine(reader.Value);
                                Console.ReadLine();
                                alignmentCollection.Add(reader.GetAttribute("name"));
                                break;

                            case "PVI":
                                if (pntListCollection.Count == 0)
                                {
                                    break;
                                }

                                pviCount++;
                                reader.Read();
                                Console.WriteLine(reader.Value);
                                Console.ReadLine();
                                string[] pviListStr = reader.Value.Split(' ');
                                pviList.Add(Convert.ToDouble(pviListStr[1]));
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                //----------------------------------------------------------//
                //---------------MERGING PVI LIST TO THE POINT LIST---------//
                //----------------------------------------------------------//
                int k = 0;
                while (k < pviList.Count)
                {
                    foreach (List <double> item in pntListCollection)
                    {
                        int i = 2;
                        do
                        {
                            item.Insert(i, pviList[k]);
                            i += 3;
                            k++;
                        } while (i <= item.Count);
                    }
                }

                //----------------------------------------------------------//
                //---------------CREEATING LAYERS----------------------------//
                //----------------------------------------------------------//
                foreach (string alignment in alignmentCollection)
                {
                    CreateLayer(alignment);
                }


                //---------------CREATING 3DPOLYLINE-----------//
                using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
                {
                    BlockTable acBlkTbl;
                    acBlkTbl = ts.GetObject(Db.BlockTableId, OpenMode.ForRead) as BlockTable;
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = ts.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                    int sayac = 0;
                    foreach (List <double> item in pntListCollection)
                    {
                        Polyline3d poly = new Polyline3d();
                        acBlkTblRec.AppendEntity(poly);

                        for (int i = 0; i < item.Count; i += 3)
                        {
                            Point3d          pnt    = new Point3d(item[i], item[i + 1], item[i + 2]);
                            PolylineVertex3d vertex = new PolylineVertex3d(pnt);
                            poly.AppendVertex(vertex);
                            ts.AddNewlyCreatedDBObject(vertex, true);
                        }
                        poly.Layer = alignmentCollection[sayac];
                        sayac++;
                        ts.AddNewlyCreatedDBObject(poly, true);
                    }

                    ts.Commit();
                }
            }
        }
Пример #27
0
        public void Figura2()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.GetDocument(db);
            Editor ed = doc.Editor;

            PromptDoubleOptions GetSpindulys = new PromptDoubleOptions("\nĮveskite detalės spindulį");
            double Spindulys;
            GetSpindulys.AllowNegative = false;
            GetSpindulys.AllowZero = false;
            GetSpindulys.AllowNone = false;
            PromptDoubleResult GetSpindulysRezultatas = ed.GetDouble(GetSpindulys);
            Spindulys = GetSpindulysRezultatas.Value;

            PromptPointOptions GetTaskas = new PromptPointOptions("\nPasirinkite centro tašką");
            Point3d Taskas;
            GetTaskas.AllowNone = false;
            PromptPointResult GetTaskasRezultatas = ed.GetPoint(GetTaskas);
            Taskas = GetTaskasRezultatas.Value;

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

                //Apskritimas
                Circle Apskritimas = new Circle(Taskas, new Vector3d(0, 0, 1), Spindulys);
                btr.AppendEntity(Apskritimas);
                tr.AddNewlyCreatedDBObject(Apskritimas, true);

                //Linijos
                Polyline3d polyline = new Polyline3d();
                btr.AppendEntity(polyline);
                tr.AddNewlyCreatedDBObject(polyline, true);
                PolylineVertex3d vex3d = new PolylineVertex3d();

                // Linija NR1 (centrine)
                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y + Spindulys / 6, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 6, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 2 + Spindulys / 6, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 2 - Spindulys / 6, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y - Spindulys / 2 - Spindulys / 1.5, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                polyline = new Polyline3d();
                btr.AppendEntity(polyline);
                tr.AddNewlyCreatedDBObject(polyline, true);

                // Linija NR2 (virsutine)
                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y + Spindulys / 2 + Spindulys / 5, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y + Spindulys / 2 - Spindulys / 5, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y + Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y + Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y + Spindulys / 2 + Spindulys / 1.5, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                polyline = new Polyline3d();
                btr.AppendEntity(polyline);
                tr.AddNewlyCreatedDBObject(polyline, true);

                // Linija NR3 (kaire)
                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 2, Taskas.Y + Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 2, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                vex3d = new PolylineVertex3d(new Point3d(Taskas.X - Spindulys / 2 - Spindulys / 2 - Spindulys / 4, Taskas.Y - Spindulys / 2, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                //Apskritimas FIll Viduryje
                Circle ApskritimasFillMIni = new Circle(new Point3d(Taskas.X + Spindulys / 2, Taskas.Y - Spindulys / 2, 0), new Vector3d(0, 0, 1), Spindulys / 8);
                btr.AppendEntity(ApskritimasFillMIni);
                tr.AddNewlyCreatedDBObject(ApskritimasFillMIni, true);

                Hatch hatch = new Hatch();
                btr.AppendEntity(hatch);
                tr.AddNewlyCreatedDBObject(hatch, true);

                ObjectIdCollection ID = new ObjectIdCollection();
                ID.Add(ApskritimasFillMIni.ObjectId);
                hatch.HatchStyle = HatchStyle.Ignore;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                hatch.Associative = true;
                hatch.AppendLoop(HatchLoopTypes.Outermost, ID);
                hatch.EvaluateHatch(true);

                //Trikampis
                Solid trikampis = new Solid(new Point3d(Taskas.X - Spindulys / 4, Taskas.Y, 0), new Point3d(Taskas.X, Taskas.Y + Spindulys / 6, 0), new Point3d(Taskas.X, Taskas.Y - Spindulys / 6, 0));
                btr.AppendEntity(trikampis);
                tr.AddNewlyCreatedDBObject(trikampis, true);

                tr.Commit();
            }
        }
Пример #28
0
        static public void ListVertices()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            HostApplicationServices hs = HostApplicationServices.Current;
            string path = hs.FindFile(doc.Name, doc.Database, FindFileHint.Default);

            //ed.WriteMessage("\nTo List all the points in the 3D string, type command LISTVERTICES.");

            long adjustX = 0;
            long adjustY = 0;
            long scaler  = 1;

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

            if (per.Status == PromptStatus.OK)
            {
                Transaction tr      = db.TransactionManager.StartTransaction();
                DBObject    objPick = tr.GetObject(oid, OpenMode.ForRead);
                Entity      objEnt  = objPick as Entity;
                string      sLayer  = objEnt.Layer.ToString();

                path += "_" + sLayer;

                ObjectIdCollection oDBO = CADops.SelectAllPolyline(sLayer);
                //Handle handseed = db.Handseed;

                try
                {
                    using (tr)
                    {
                        long          shtNo = 1;
                        List <string> data  = new List <string>();
                        foreach (ObjectId id in oDBO)
                        {
                            //DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead);
                            DBObject obj       = tr.GetObject(id, OpenMode.ForRead);
                            Entity   ent       = obj as Entity;
                            string   layerName = ent.Layer.ToString();

                            //create list for storing x,y,z value of point
                            string StrId = "";


                            // If a "lightweight" (or optimized) polyline
                            Autodesk.AutoCAD.DatabaseServices.Polyline lwp = obj as Autodesk.AutoCAD.DatabaseServices.Polyline;

                            if (lwp != null)
                            {
                                //StrId = lwp.ObjectId.ToString();
                                StrId = lwp.Handle.ToString();
                                ed.WriteMessage("\n" + StrId);
                                // Use a for loop to get each vertex, one by one
                                int vn = lwp.NumberOfVertices;
                                for (int i = 0; i < vn; i++)
                                {
                                    // Could also get the 3D point here
                                    Point2d pt   = lwp.GetPoint2dAt(i);
                                    string  temp = CADops.scaleNmove(pt.X, adjustX, scaler) + "," + CADops.scaleNmove(pt.Y, adjustY, scaler) + ", ," + StrId + "," + layerName;
                                    data.Add(temp);
                                    ed.WriteMessage("\n" + pt.ToString());
                                }
                            }
                            else
                            {
                                // If an old-style, 2D polyline
                                Polyline2d p2d = obj as Polyline2d;
                                if (p2d != null)
                                {
                                    StrId = p2d.Handle.ToString();
                                    ed.WriteMessage("\n" + StrId);

                                    // Use foreach to get each contained vertex
                                    foreach (ObjectId vId in p2d)
                                    {
                                        Vertex2d v2d  = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead);
                                        string   temp = CADops.scaleNmove(v2d.Position.X, adjustX, scaler) + "," + CADops.scaleNmove(v2d.Position.Y, adjustY, scaler) + "," + v2d.Position.Z * scaler + "," + StrId + "," + layerName;
                                        data.Add(temp);
                                        ed.WriteMessage("\n" + v2d.Position.ToString());
                                    }
                                }
                                else
                                {
                                    // If an old-style, 3D polyline
                                    Polyline3d p3d = obj as Polyline3d;
                                    if (p3d != null)
                                    {
                                        StrId = p3d.Handle.ToString();
                                        ed.WriteMessage("\n" + StrId);

                                        // Use foreach to get each contained vertex
                                        foreach (ObjectId vId in p3d)
                                        {
                                            PolylineVertex3d v3d  = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
                                            string           temp = CADops.scaleNmove(v3d.Position.X, adjustX, scaler) + "," + CADops.scaleNmove(v3d.Position.Y, adjustY, scaler) + "," + v3d.Position.Z * scaler + "," + StrId + "," + layerName;
                                            data.Add(temp);
                                            ed.WriteMessage("\n" + v3d.Position.ToString());
                                        }
                                    }
                                }
                            }
                            //create dataarray to populate in excel
                            int no = data.Count;
                            ed.WriteMessage("\n Number of Point:" + no);

                            //createCSV(data, shtNo);
                            shtNo += 1;
                        }
                        Excel.createCSV(data, path);
                        // Committing is cheaper than aborting
                        ed.WriteMessage("\ncsv file has been created under path " + path);
                        ed.WriteMessage("\nData format: Easting, Northing, Elevation, String ID, Layer Name.");
                        tr.Commit();
                    }
                }
                catch { }
            }
        }
Пример #29
0
        private void plotButton_Click(object sender, EventArgs e)
        {
            int      blockCount = 0;
            Document doc        = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor   ed         = doc.Editor;
            Database db         = doc.Database;

            intervalPline = Convert.ToDouble(textBox2.Text);
            Database blockDB = new Database(true, true);
            ObjectId insertedBlockId;

            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    double     lengthToNextVertex = 0;
                    DBObject   obj      = tr.GetObject(prmtEnt.ObjectId, OpenMode.ForRead);
                    Polyline3d polyline = obj as Polyline3d;
                    if (polyline != null)
                    {
                        List <ObjectId> vertices = new List <ObjectId>();
                        foreach (ObjectId id in polyline)
                        {
                            vertices.Add(id);
                        }
                        for (int i = 0; i < vertices.Count - 1; i++)
                        {
                            PolylineVertex3d vertex     = tr.GetObject(vertices[i], OpenMode.ForRead) as PolylineVertex3d;
                            PolylineVertex3d nextVertex = tr.GetObject(vertices[i + 1], OpenMode.ForRead) as PolylineVertex3d;
                            BlockTable       blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                            Double           length     = vertex.Position.DistanceTo(nextVertex.Position);
                            lengthToNextVertex += length;
                            if (checkEveryVertext.CheckState != CheckState.Checked)
                            {
                                while (lengthToNextVertex >= intervalPline)
                                {
                                    Point3d pt = GetPt(vertex.Position, nextVertex.Position, intervalPline - (lengthToNextVertex - length));
                                    lengthToNextVertex -= intervalPline;
                                    if (blockTable.Has(blockName))
                                    {
                                        BlockTableRecord blockTableRecord = blockTable[blockName].GetObject(OpenMode.ForRead) as BlockTableRecord;
                                        if (blockTable != null)
                                        {
                                            using (BlockReference spotHeight = new BlockReference(pt, blockTableRecord.ObjectId))
                                            {
                                                blockCount++;
                                                using (DocumentLock doclock = doc.LockDocument())
                                                {
                                                    spotHeight.ScaleFactors = new Autodesk.AutoCAD.Geometry.Scale3d(blockScale, blockScale, blockScale);
                                                    BlockTableRecord blocktableRec = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                                                    blocktableRec.AppendEntity(spotHeight);
                                                    tr.AddNewlyCreatedDBObject(spotHeight, true);
                                                    insertedBlockId = spotHeight.ObjectId;
                                                    foreach (ObjectId attrID in blockTableRecord)
                                                    {
                                                        DBObject            atttObj = attrID.GetObject(OpenMode.ForRead);
                                                        AttributeDefinition attrib  = atttObj as AttributeDefinition;
                                                        if ((attrib != null) && (!attrib.Constant))
                                                        {
                                                            using (AttributeReference attributeRef = new AttributeReference())
                                                            {
                                                                attributeRef.SetAttributeFromBlock(attrib, spotHeight.BlockTransform);
                                                                attributeRef.TextString = Decimal.Round(Convert.ToDecimal(spotHeight.Position.Z), 2, MidpointRounding.AwayFromZero).ToString();

                                                                spotHeight.AttributeCollection.AppendAttribute(attributeRef);
                                                                tr.AddNewlyCreatedDBObject(attributeRef, true);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (blockTable.Has(blockName))
                                {
                                    BlockTableRecord blockTableRecord = blockTable[blockName].GetObject(OpenMode.ForRead) as BlockTableRecord;
                                    if (blockTable != null)
                                    {
                                        using (BlockReference spotHeight = new BlockReference(vertex.Position, blockTableRecord.ObjectId))
                                        {
                                            blockCount++;
                                            using (DocumentLock doclock = doc.LockDocument())
                                            {
                                                spotHeight.ScaleFactors = new Autodesk.AutoCAD.Geometry.Scale3d(blockScale, blockScale, blockScale);
                                                BlockTableRecord blocktableRec = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                                                blocktableRec.AppendEntity(spotHeight);
                                                tr.AddNewlyCreatedDBObject(spotHeight, true);
                                                insertedBlockId = spotHeight.ObjectId;
                                                foreach (ObjectId attrID in blockTableRecord)
                                                {
                                                    DBObject            atttObj = attrID.GetObject(OpenMode.ForRead);
                                                    AttributeDefinition attrib  = atttObj as AttributeDefinition;
                                                    if ((attrib != null) && (!attrib.Constant))
                                                    {
                                                        using (AttributeReference attributeRef = new AttributeReference())
                                                        {
                                                            attributeRef.SetAttributeFromBlock(attrib, spotHeight.BlockTransform);
                                                            attributeRef.TextString = Decimal.Round(Convert.ToDecimal(spotHeight.Position.Z), 2, MidpointRounding.AwayFromZero).ToString();

                                                            spotHeight.AttributeCollection.AppendAttribute(attributeRef);
                                                            tr.AddNewlyCreatedDBObject(attributeRef, true);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        tr.Commit();
                    }
                    ed.Regen();
                    this.Close();
                    ed.WriteMessage("Successfully added {0} instances of block {1}", blockCount, blockName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #30
0
        private static void InteratePolyLines(ObjectId selectedObjectId, Database db)
        {
            //Document doc = Application.DocumentManager.MdiActiveDocument;
            //Editor ed = doc.Editor;
            //Database db = doc.Database;
            Transaction tr = db.TransactionManager.StartTransaction();

            // Get the current UCS

            //CoordinateSystem3d ucs =
            //    ed.CurrentUserCoordinateSystem.CoordinateSystem3d;

            using (tr)
            {
                DBObject obj =
                    tr.GetObject(selectedObjectId, OpenMode.ForRead);


                // If a "lightweight" (or optimized) polyline

                Polyline lwp = obj as Polyline;

                if (lwp != null)
                {
                    // Is Polyline Closed
                    if (lwp.Closed)
                    {
                        //Common.Logging.ACADLogging.LogMyExceptions(lwp.Layer);
                        lwp.UpgradeOpen();
                        if (IsLayerDefined(db, AssignPolyLinesToLayers(lwp).ToUpper()))
                        {
                            lwp.Layer = AssignPolyLinesToLayers(lwp).ToUpper() ?? lwp.Layer;
                        }
                        lwp.DowngradeOpen();
                        //Common.Logging.ACADLogging.LogMyExceptions(lwp.Layer);
                    }
                    // Use a for loop to get each vertex, one by one

                    int vn = lwp.NumberOfVertices;

                    for (int i = 0; i < vn; i++)
                    {
                        // Could also get the 3D point here

                        Point2d pt = lwp.GetPoint2dAt(i);

                        //ed.WriteMessage("\n" + pt.ToString());
                    }
                }

                else
                {
                    // If an old-style, 2D polyline

                    Polyline2d p2d = obj as Polyline2d;

                    if (p2d != null)
                    {
                        // Use foreach to get each contained vertex

                        foreach (ObjectId vId in p2d)
                        {
                            Vertex2d v2d =
                                (Vertex2d)tr.GetObject(
                                    vId,
                                    OpenMode.ForRead
                                    );

                            //ed.WriteMessage(
                            //    "\n" + v2d.Position.ToString()
                            //    );
                        }
                    }

                    else
                    {
                        // If an old-style, 3D polyline

                        Polyline3d p3d = obj as Polyline3d;

                        if (p3d != null)
                        {
                            // Use foreach to get each contained vertex

                            foreach (ObjectId vId in p3d)
                            {
                                PolylineVertex3d v3d =
                                    (PolylineVertex3d)tr.GetObject(
                                        vId,
                                        OpenMode.ForRead
                                        );

                                //ed.WriteMessage(
                                //    "\n" + v3d.Position.ToString()
                                //    );
                            }
                        }
                    }
                }

                // Committing is cheaper than aborting

                tr.Commit();
            }
        }
Пример #31
0
        public static Point3dCollection ListVertices()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            Point3dCollection result = new Point3dCollection();

            PromptEntityResult per = ed.GetEntity("Select a polyline");

            if (per.Status == PromptStatus.OK)
            {
                Transaction tr = db.TransactionManager.StartTransaction();
                using (tr)
                {
                    DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead);
                    Polyline lwp = obj as Polyline;

                    if (lwp != null)
                    {
                        // Use a for loop to get each vertex, one by one
                        int vn = lwp.NumberOfVertices;
                        for (int i = 0; i < vn; i++)
                        {
                            // Could also get the 3D point here
                            Point2d pt = lwp.GetPoint2dAt(i);
                            result.Add(new Point3d(pt.X, pt.Y, 0));
                        }
                    }
                    else
                    {
                        // If an old-style, 2D polyline
                        Polyline2d p2d = obj as Polyline2d;
                        if (p2d != null)
                        {
                            // Use foreach to get each contained vertex
                            foreach (ObjectId vId in p2d)
                            {
                                Vertex2d v2d = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead);
                                result.Add(new Point3d(v2d.Position.X, v2d.Position.Y, v2d.Position.Z));
                            }
                        }
                        else
                        {
                            // If an old-style, 3D polyline
                            Polyline3d p3d = obj as Polyline3d;
                            if (p3d != null)
                            {
                                // Use foreach to get each contained vertex
                                foreach (ObjectId vId in p3d)
                                {
                                    PolylineVertex3d v3d = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
                                    result.Add(new Point3d(v3d.Position.X, v3d.Position.Y, v3d.Position.Z));
                                }
                            }
                        }
                    }
                    tr.Commit();
                }
            }
            return(result);
        }
Пример #32
0
        public void Figura1()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.GetDocument(db);
            Editor ed = doc.Editor;

            PromptDoubleOptions GetIlgis = new PromptDoubleOptions("\nĮveskite mikroskemos ilgį");
            double Ilgis;
            GetIlgis.AllowNegative = false;
            GetIlgis.AllowZero = false;
            GetIlgis.AllowNone = false;
            PromptDoubleResult GetIlgisRezultatas = ed.GetDouble(GetIlgis);
            Ilgis = GetIlgisRezultatas.Value;

            PromptDoubleOptions GetPlotis = new PromptDoubleOptions("\nĮveskite mikroskemos plotį");
            double Plotis;
            GetPlotis.AllowNegative = false;
            GetPlotis.AllowZero = false;
            GetPlotis.AllowNone = false;
            PromptDoubleResult GetPlotisRezultatas = ed.GetDouble(GetPlotis);
            Plotis = GetPlotisRezultatas.Value;

            PromptPointOptions GetTaskas = new PromptPointOptions("\nPasirinkite tašką");
            Point3d Taskas;
            GetTaskas.AllowNone = false;
            PromptPointResult GetTaskasRezultatas = ed.GetPoint(GetTaskas);
            Taskas = GetTaskasRezultatas.Value;

            Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite,false);
                Polyline3d polyline = new Polyline3d();
                btr.AppendEntity(polyline);
                tr.AddNewlyCreatedDBObject(polyline, true);
                PolylineVertex3d vex3d = new PolylineVertex3d();

                //Pradinis taskas
                vex3d = new PolylineVertex3d(Taskas);
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                //Atsakos tarp pradinio ir pirmo kampo
                double betaIlgis = Ilgis / 8;
                double AtsakosIlgis = Math.Min(Ilgis / 4, Plotis / 4);
                for (int i = 1; i < 8; i++)
                {
                    // Linija iki atsakos
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X, Taskas.Y + betaIlgis * i, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);

                    //Atsakos linija
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X - AtsakosIlgis, Taskas.Y + betaIlgis * i, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);

                    //Atsakos grizimas atgal i kontura
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X, Taskas.Y + betaIlgis * i, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);
                }

                // Pirmas kampas
                vex3d = new PolylineVertex3d(new Point3d(Taskas.X, Taskas.Y + Ilgis, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                //Atsakos tarp pirmo ir angtro kampo
                double betaPlotis = Plotis / 2;
                for (int i = 1; i < 2; i++)
                {
                    // Linija iki atsakos
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X + betaPlotis * i, Taskas.Y + Ilgis, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);

                    //Atsakos linija
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X + betaPlotis * i, Taskas.Y + Ilgis + AtsakosIlgis, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);

                    //Atsakos grizimas atgal i kontura
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X + betaPlotis * i, Taskas.Y + Ilgis, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);
                }

                //Antras kampas
                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Plotis, Taskas.Y + Ilgis, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                //Atsakos tarp antro ir trecio kampo
                for (int i = 1; i < 8; i++)
                {
                    // Linija iki atsakos
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Plotis, Taskas.Y + Ilgis - betaIlgis * i, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);

                    //Atsakos linija
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Plotis + AtsakosIlgis, Taskas.Y + Ilgis - betaIlgis * i, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);

                    //Atsakos grizimas atgal i kontura
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Plotis, Taskas.Y + Ilgis - betaIlgis * i, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);
                }

                //Trecias kampas
                vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Plotis, Taskas.Y, 0));
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);

                //Atsakos tarp trecio ir pradinio kampo
                for (int i = 1; i < 2; i++)
                {
                    // Linija iki atsakos
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Plotis - betaPlotis * i, Taskas.Y, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);

                    //Atsakos linija
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Plotis - betaPlotis * i, Taskas.Y - AtsakosIlgis, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);

                    //Atsakos grizimas atgal i kontura
                    vex3d = new PolylineVertex3d(new Point3d(Taskas.X + Plotis - betaPlotis * i, Taskas.Y, 0));
                    polyline.AppendVertex(vex3d);
                    tr.AddNewlyCreatedDBObject(vex3d, true);
                }

                //Ketvirtas kampas / Pradinis taskas
                vex3d = new PolylineVertex3d(Taskas);
                polyline.AppendVertex(vex3d);
                tr.AddNewlyCreatedDBObject(vex3d, true);
                tr.Commit();
            }
        }