Пример #1
0
            public static void segment2DtoPolyline(Segment2D segment, String referringLayer, Document currentDocument)
            {
                Database currentDatabase = currentDocument.Database;
                Editor   editor          = currentDocument.Editor;

                using (DocumentLock docLock = currentDocument.LockDocument())
                {
                    using (Transaction transaction = currentDocument.TransactionManager.StartTransaction())
                    {
                        LayerTable       layers     = (LayerTable)transaction.GetObject(currentDatabase.LayerTableId, OpenMode.ForRead);
                        BlockTable       blockTable = (BlockTable)transaction.GetObject(currentDatabase.BlockTableId, OpenMode.ForRead);
                        BlockTableRecord modelSpace = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                        Polyline polyline   = new Polyline();
                        Point2d  startPoint = new Point2d(segment.getVertices()[0].getCoordinates()[0], segment.getVertices()[0].getCoordinates()[1]);
                        Point2d  endPoint   = new Point2d(segment.getVertices()[1].getCoordinates()[0], segment.getVertices()[1].getCoordinates()[1]);
                        polyline.AddVertexAt(0, startPoint, 0, 0, 0);
                        polyline.AddVertexAt(1, endPoint, 0, 0, 0);
                        polyline.LayerId = layers[referringLayer];
                        modelSpace.AppendEntity(polyline);
                        transaction.AddNewlyCreatedDBObject(polyline, true);
                        transaction.Commit();
                    }
                }
            }