static void ConvertFile(string from, string to, bool displayshapes, bool outlineshapes) { ParsedGerber PLS = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), from, true, State: new GerberParserState() { PreCombinePolygons = true }); DxfDocument dxf = new DxfDocument(); // add your entities here if (outlineshapes) { foreach (var a in PLS.OutlineShapes) { List <netDxf.Entities.PolylineVertex> Vertices = new List <netDxf.Entities.PolylineVertex>(); foreach (var v in a.Vertices) { Vertices.Add(new netDxf.Entities.PolylineVertex(v.X, v.Y, 0)); } netDxf.Entities.Polyline pl = new netDxf.Entities.Polyline(Vertices, true); pl.Color = new AciColor(System.Drawing.Color.Blue); dxf.AddEntity(pl); } } if (displayshapes) { foreach (var a in PLS.DisplayShapes) { List <netDxf.Entities.PolylineVertex> Vertices = new List <netDxf.Entities.PolylineVertex>(); foreach (var v in a.Vertices) { Vertices.Add(new netDxf.Entities.PolylineVertex(v.X, v.Y, 0)); } netDxf.Entities.Polyline pl = new netDxf.Entities.Polyline(Vertices, true); pl.Color = new AciColor(System.Drawing.Color.Green); dxf.AddEntity(pl); } } if (false) { foreach (var a in PLS.Shapes) { List <netDxf.Entities.PolylineVertex> Vertices = new List <netDxf.Entities.PolylineVertex>(); foreach (var v in a.Vertices) { Vertices.Add(new netDxf.Entities.PolylineVertex(v.X, v.Y, 0)); } netDxf.Entities.Polyline pl = new netDxf.Entities.Polyline(Vertices, true); pl.Color = new AciColor(System.Drawing.Color.Red); dxf.AddEntity(pl); } } // save to file dxf.Save(to); }
private static void Ellipse() { DxfDocument dxf = new DxfDocument(); Line line = new Line(new Vector3(0, 0, 0), new Vector3(2 * Math.Cos(Math.PI / 4), 2 * Math.Cos(Math.PI / 4), 0)); dxf.AddEntity(line); Line line2 = new Line(new Vector3(0, 0, 0), new Vector3(0, -2, 0)); dxf.AddEntity(line2); Arc arc = new Arc(Vector3.Zero, 2, 45, 270); dxf.AddEntity(arc); // ellipses are saved as polylines Ellipse ellipse = new Ellipse(new Vector3(2, 2, 0), 5, 3); ellipse.Rotation = 30; ellipse.Normal = new Vector3(1, 1, 1); ellipse.Thickness = 2; dxf.AddEntity(ellipse); dxf.Save("ellipse.dxf", DxfVersion.AutoCad2000); dxf = new DxfDocument(); dxf.Load("ellipse.dxf"); }
public void WriteDxfDocument() { string file = "bin3.dxf"; // by default it will create an AutoCad2000 DXF version DxfDocument dxf = new DxfDocument(); // a rectangular wipeout defined by its bottom-left corner and its width and height Wipeout wipeout = new Wipeout(0, 0, Bin.Width, Bin.Height); dxf.AddEntity(wipeout); if (Bin.NestedItems.Count >= 1) { foreach (Item nestedItem in Bin.NestedItems) { wipeout = new Wipeout(nestedItem.BLpPosition, nestedItem.BLqPosition, nestedItem.Width, nestedItem.Height); dxf.AddEntity(wipeout); } // save to file dxf.Save(file); } // this check is optional but recommended before loading a DXF file DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file); // netDxf is only compatible with AutoCad2000 and higher DXF version if (dxfVersion < DxfVersion.AutoCad2000) { return; } // load file DxfDocument loaded = DxfDocument.Load(file); }
void AddRectangle(ref DxfDocument dxf, Vector2 a, Vector2 b) { dxf.AddEntity(new Line(a, new Vector2(b.X, a.Y))); dxf.AddEntity(new Line(b, new Vector2(b.X, a.Y))); dxf.AddEntity(new Line(b, new Vector2(a.X, b.Y))); dxf.AddEntity(new Line(a, new Vector2(a.X, b.Y))); }
public void saveDxfFromListListPoints(string savePath, List <List <System.Drawing.Point> > listListPoints) { ListAddedElements_as_List_Of_Point = listListPoints; dxf_File = new DxfDocument(netDxf.Header.DxfVersion.AutoCad2013); listToPolyline = ToPolyLine2(ListAddedElements_as_List_Of_Point); ListAddedElements_as_PL = new List <List <shapes.Polyline> >(); ListAddedElements_as_PL.Add(listToPolyline); allLists_LwPolyline = ToLwPolyline2(ListAddedElements_as_PL); foreach (List <LwPolyline> List_LwPL in allLists_LwPolyline) { foreach (LwPolyline LwPL in List_LwPL) { LwPL.Layer = new netDxf.Tables.Layer(Werkzeug); dxf_File.AddEntity(LwPL); } } netDxf.Entities.Point newPt = new netDxf.Entities.Point(Width, Height, Depth); dxf_File.AddEntity(newPt); dxf_File.Save(savePath); }
private static void HatchTest1() { DxfDocument dxf = new DxfDocument(); Polyline poly = new Polyline(); poly.Vertexes.Add(new PolylineVertex(-10, -10)); poly.Vertexes.Add(new PolylineVertex(10, -10)); poly.Vertexes.Add(new PolylineVertex(10, 10)); poly.Vertexes.Add(new PolylineVertex(-10, 10)); poly.Vertexes[2].Bulge = 1; poly.IsClosed = true; Polyline poly2 = new Polyline(); poly2.Vertexes.Add(new PolylineVertex(-5, -5)); poly2.Vertexes.Add(new PolylineVertex(5, -5)); poly2.Vertexes.Add(new PolylineVertex(5, 5)); poly2.Vertexes.Add(new PolylineVertex(-5, 5)); poly2.Vertexes[1].Bulge = -0.25; poly2.IsClosed = true; Polyline poly3 = new Polyline(); poly3.Vertexes.Add(new PolylineVertex(-8, -8)); poly3.Vertexes.Add(new PolylineVertex(-6, -8)); poly3.Vertexes.Add(new PolylineVertex(-6, -6)); poly3.Vertexes.Add(new PolylineVertex(-8, -6)); poly3.IsClosed = true; List <HatchBoundaryPath> boundary = new List <HatchBoundaryPath> { new HatchBoundaryPath(new List <IEntityObject> { poly }), new HatchBoundaryPath(new List <IEntityObject> { poly2 }), new HatchBoundaryPath(new List <IEntityObject> { poly3 }), }; Hatch hatch = new Hatch(HatchPattern.Net, boundary); hatch.Layer = new Layer("hatch") { Color = AciColor.Red, LineType = LineType.Continuous }; hatch.Pattern.Angle = 30; hatch.Pattern.Scale = 1 / hatch.Pattern.LineDefinitions[0].Delta.Y; dxf.AddEntity(poly); dxf.AddEntity(poly2); dxf.AddEntity(poly3); dxf.AddEntity(hatch); dxf.Save("hatchTest.dxf", DxfVersion.AutoCad2000); dxf.Load("hatchTest.dxf"); }
public void Circle(SolverPoint center, double radius, int color, string layer) { var l = GetLayer(mDxf, layer); var e = new Circle(new Vector2(center.X, center.Y), radius); e.Layer = l; mDxf.AddEntity(e); }
public DxfDocument Please() { var document = new DxfDocument(); document.AddEntity(circles); document.AddEntity(polylines); return(document); }
public void WriteLine2DXF(PointF StartPoint, PointF EndPoint) { Line line = new Line(StartPoint, EndPoint) { Layer = layerWrite }; docWrite.AddEntity(line); }
public void PrintM() { DxfDocument dxfDocument = new DxfDocument(); //Печать рамы for (int i = 0; i < epureLines.Length; i++) { Line line = new Line(epureLines[i].StartPoint, epureLines[i].EndPoint); dxfDocument.AddEntity(line); } //Печать эпюр. Нужно добавить кф отображения for (int i = 0; i < epureLines.Length; i++) { double coefficient = 15; var dx = Math.Abs(epureLines[i].StartPoint.X - epureLines[i].EndPoint.X); var dy = (epureLines[i].EndPoint.Y - epureLines[i].StartPoint.Y); var hypotenuse = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)); var cos = dx / hypotenuse; double sin; //Для ригелей у которых dy< 0 меняем направление по Х, для стоек оставляем изначальное (можно поменять направление ригелей для унификации) switch (Math.Round(dx, 2)) { case 0: sin = dy / hypotenuse; break; default: sin = -dy / hypotenuse; break; } //var startMoment = Math.Sqrt(Math.Pow(epureLines[i].StartMoment, 2) / 2); var pointStartMoment = new Vector2(epureLines[i].StartPoint.X + epureLines[i].StartMoment * sin / coefficient, epureLines[i].StartPoint.Y + epureLines[i].StartMoment * cos / coefficient); //var middleMoment = Math.Sqrt(Math.Pow(epureLines[i].MiddleMoment, 2) / 2); var pointMiddle = new Vector2((epureLines[i].StartPoint.X + epureLines[i].EndPoint.X) / 2, (epureLines[i].StartPoint.Y + epureLines[i].EndPoint.Y) / 2); var pointMidlleMoment = new Vector2((epureLines[i].StartPoint.X + epureLines[i].EndPoint.X) / 2 + epureLines[i].MiddleMoment * sin / coefficient, (epureLines[i].StartPoint.Y + epureLines[i].EndPoint.Y) / 2 + epureLines[i].MiddleMoment * cos / coefficient); //var endtMoment = Math.Sqrt(Math.Pow(epureLines[i].EndMoment, 2) / 2); var pointEndMoment = new Vector2(epureLines[i].EndPoint.X + epureLines[i].EndMoment * sin / coefficient, epureLines[i].EndPoint.Y + epureLines[i].EndMoment * cos / coefficient); Line line1 = new Line(epureLines[i].StartPoint, pointStartMoment); Line line2 = new Line(pointMiddle, pointMidlleMoment); Line line3 = new Line(epureLines[i].EndPoint, pointEndMoment); Line line4 = new Line(pointStartMoment, pointMidlleMoment); Line line5 = new Line(pointMidlleMoment, pointEndMoment); var lines = new List <Line>() { line1, line2, line3, line4, line5 }; dxfDocument.AddEntity(lines); } dxfDocument.Save(@"e:\Програмирование\Перемножение эпюр\plot.dxf"); }
private void button_export(object sender, EventArgs e) { DxfDocument Doc = new DxfDocument(); /* Отрисовка участков */ for (int z = 0; z < MyXmlReader.spatials.Count; z++) { LwPolyline parcel = new LwPolyline(); foreach (var Point in MyXmlReader.spatials[z].Points) { centerX += (ulong)Point.X; centerY += (ulong)Point.Y; centerCounter++; if (Switch.Checked)//Перевернуть X Y { parcel.Vertexes.Add(new LwPolylineVertex(new Vector2(Point.Y, Point.X))); } else { parcel.Vertexes.Add(new LwPolylineVertex(Point)); } } Doc.AddEntity(parcel); } /* Создаем надпись кад. номера */ Text cad_number = new Text(); cad_number.Value = MyXmlReader.CadastralNumber; cad_number.Alignment = TextAlignment.MiddleCenter; cad_number.Height = 2.5d; if (Switch.Checked) { Vector3 textPosition = new Vector3((double)centerY / centerCounter, (double)centerX / centerCounter, 0); cad_number.Position = textPosition; } else { Vector3 textPosition = new Vector3((double)centerX / centerCounter, (double)centerY / centerCounter, 0); cad_number.Position = textPosition; } Doc.AddEntity(cad_number); try { Doc.Save(textBoxTo.Text); } catch (IOException x) { MessageBox.Show(x.Message); } Application.Exit(); }
/// <summary> /// Fügt Entity Objekte in einer bereits vorhandenen DXF Datei hinzu. /// </summary> /// <param name="dxf_path">Pfad des DXF Documents, wo es hingespeichert werden soll</param> /// <param name="doc">DXF Document wo es hinzugefügt werden soll</param> /// <param name="workPiece">Entsprechende Arbeitseigenschaften</param> /// <param name="listObj">Liste der hinzuzufügenden Entity Objekte</param> static public void JoinToDxF(string dxf_path, ref DxfDocument doc, ElementManager.workpiece workPiece, params EntityObject[] listObj) { foreach (EntityObject item in listObj) { item.Layer = new netDxf.Tables.Layer(workPiece.werkzeugName); doc.AddEntity(item); } netDxf.Entities.Point newPt = new netDxf.Entities.Point(workPiece.height, workPiece.width, workPiece.depth); doc.AddEntity(newPt); doc.Save(dxf_path); }
private static void HatchTest3() { DxfDocument dxf = new DxfDocument(); Polyline poly = new Polyline(); poly.Vertexes.Add(new PolylineVertex(-10, -10)); poly.Vertexes.Add(new PolylineVertex(10, -10)); poly.Vertexes.Add(new PolylineVertex(10, 10)); poly.Vertexes.Add(new PolylineVertex(-10, 10)); poly.Vertexes[2].Bulge = 1; poly.IsClosed = true; Ellipse ellipse = new Ellipse(Vector3.Zero, 16, 10); ellipse.Rotation = 0; ellipse.StartAngle = 0; ellipse.EndAngle = 180; Polyline poly2 = new Polyline(); poly2.Vertexes.Add(new PolylineVertex(-8, 0)); poly2.Vertexes.Add(new PolylineVertex(0, -4)); poly2.Vertexes.Add(new PolylineVertex(8, 0)); Arc arc = new Arc(Vector3.Zero, 8, 180, 0); Line line = new Line(new Vector3(8, 0, 0), new Vector3(-8, 0, 0)); List <HatchBoundaryPath> boundary = new List <HatchBoundaryPath> { new HatchBoundaryPath(new List <IEntityObject> { poly }), new HatchBoundaryPath(new List <IEntityObject> { poly2, ellipse }) }; Hatch hatch = new Hatch(HatchPattern.Line, boundary); hatch.Pattern.Angle = 45; dxf.AddEntity(poly); dxf.AddEntity(ellipse); //dxf.AddEntity(arc); //dxf.AddEntity(line); dxf.AddEntity(poly2); dxf.AddEntity(hatch); dxf.Save("hatchTest.dxf", DxfVersion.AutoCad2010); }
public bool SaveAsDXF(string filename) { if (filename == null || filename.Length <= 0) { return(false); } string layerName; DxfDocument dxfDocument = new DxfDocument(new netDxf.Header.HeaderVariables()); layerName = "points"; foreach (MarkGeometryPoint point in Points) { dxfDocument.AddEntity(point.GetAsDXFEntity(layerName)); } layerName = "arcs"; foreach (MarkGeometryArc arc in Arcs) { dxfDocument.AddEntity(arc.GetAsDXFEntity(layerName)); } layerName = "arcs"; foreach (MarkGeometryCircle circle in Circles) { dxfDocument.AddEntity(circle.GetAsDXFEntity(layerName)); } layerName = "lines"; foreach (MarkGeometryLine line in Lines) { dxfDocument.AddEntity(line.GetAsDXFEntity(layerName)); } layerName = "paths"; foreach (MarkGeometryPath path in Paths) { foreach (MarkGeometryLine line in GeometricArithmeticModule.ToLines(path.Points)) { dxfDocument.AddEntity(line.GetAsDXFEntity(layerName)); } } // TODO : add support for other geometric objects and shapes e.g. splines, ellipses, etc // Also could optimise the object heirarchy (i.e. saving entities in an efficient order) dxfDocument.Save(filename); return(File.Exists(filename)); }
/// <summary> /// metodo per scrivere un file dxf a partire /// dalle sequenze di bin generate da hsolve /// </summary> /// <param name="sequences"></param> /// <param name="fileName"></param> public void WriteAllData(IList <Sequence> sequences, string fileName) { string file = fileName + ".dxf"; DxfDocument dxf = new DxfDocument(); TextStyle style = new TextStyle("MyStyle", "Helvetica", FontStyle.Italic | FontStyle.Bold); int offsetX = 0; int sequenceIndex = 1; foreach (var sequence in sequences) { MText title = new MText("ITERAZIONE N° " + sequenceIndex) { Position = new Vector3(0 + offsetX, 1800, 0.0), Height = 70, Style = style }; dxf.AddEntity(title); foreach (var bin in sequence.Bins) { if (bin.PricedItems != null) { //un wipeout rettangolare che contiene tutte le altre forme Wipeout wipeout = new Wipeout(0 + offsetX, 0, sequence.Bins.ElementAt(0).Width, sequence.Bins.ElementAt(0).Height); dxf.AddEntity(wipeout); foreach (var pricedItem in bin.PricedItems) { //un wipeout rettangolare che rappresenta una forma wipeout = new Wipeout(pricedItem.BLpPosition + offsetX, pricedItem.BLqPosition, pricedItem.Width, pricedItem.Height); //un id progressivo per il wipeout rettangolare MText text = new MText(pricedItem.Id.ToString()) { Position = new Vector3(pricedItem.BLpPosition + 30 + offsetX, pricedItem.BLqPosition + 45, 0.0), Height = 30, Style = style }; dxf.AddEntity(wipeout); dxf.AddEntity(text); } offsetX += 4000; } } offsetX += 3000; sequenceIndex += 99; } dxf.Save(file); }
public override void ToDxf(DxfDocument dxf) { //= new DxfDocument(); // Bound List <netDxf.Entities.LwPolylineVertex> polyVertexes = new List <netDxf.Entities.LwPolylineVertex>(); foreach (IFigure p in this.CulvertBound.Dependencies) { if (p is IPoint) { var point = p as IPoint; polyVertexes.Add(new netDxf.Entities.LwPolylineVertex(point.Coordinates.X, point.Coordinates.Y)); } } // Cells // Số cells trên mặt cắt ngang int cellsNumber = NumberOfCellsToInt(this.NumberOfCells); for (int i = 0; i < cellsNumber; i++) { List <netDxf.Entities.LwPolylineVertex> cellVertexes = new List <netDxf.Entities.LwPolylineVertex>(); foreach (IPoint p in GetCellDependencies(i)) { cellVertexes.Add(new netDxf.Entities.LwPolylineVertex(p.Coordinates.X, p.Coordinates.Y)); } netDxf.Entities.LwPolyline cellPolyline = new netDxf.Entities.LwPolyline(cellVertexes, true); cellPolyline.Layer = new netDxf.Tables.Layer("polyline2d"); cellPolyline.Layer.Color.Index = ColorHelper.ColorToAutoCADColor(this.LineStyle.Color); //polyline2d.Normal = new Vector3(1, 1, 1); //polyline2d.Elevation = 0.0f; dxf.AddEntity(cellPolyline); } netDxf.Entities.LwPolyline polyline2d = new netDxf.Entities.LwPolyline(polyVertexes, true); polyline2d.Layer = new netDxf.Tables.Layer("polyline2d"); polyline2d.Layer.Color.Index = ColorHelper.ColorToAutoCADColor(this.LineStyle.Color); //polyline2d.Normal = new Vector3(1, 1, 1); //polyline2d.Elevation = 0.0f; dxf.AddEntity(polyline2d); dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2000; //dxf.Save(fileName); foreach (IFigure f in Children) { var child = f as FigureBase; child.ToDxf(dxf); } }
private Line AddDxfLine(string layerName, LayoutLine line, LineExportConfig lineConfig) { var dxfLine = new Line(PointToVector(line.P1), PointToVector(line.P2)) { Layer = GetLayer(layerName), Color = GetColor(lineConfig.Color) }; if (lineConfig.IsDashed) { dxfLine.Linetype = Linetype.Dashed; } Document.AddEntity(dxfLine); return(dxfLine); }
private void FillRectangle(DxfDocument dxf, Layer layer, double x, double y, double width, double height, ArgbColor color) { var fill = ToColor(color); var fillTransparency = ToTransparency(color); var bounds = new List <HatchBoundaryPath> { new HatchBoundaryPath( new List <EntityObject> { CreateLine(x, y, x + width, y), CreateLine(x + width, y, x + width, y + height), CreateLine(x + width, y + height, x, y + height), CreateLine(x, y + height, x, y) }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = layer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; dxf.AddEntity(hatch); }
private void DrawToBottom(int x, int y, CADShape shape, List <CADShape> shapes, DxfDocument dxf) { var line = new Line(new Vector2(x, y), new Vector2(shape.X2, shape.Y2)); //Desenhando o lado direito para baixo line.Layer = _layerParede; dxf.AddEntity(line); //Tentando ir para direita var rightShape = shapes.FirstOrDefault(s => s.X <= shape.X2 && s.X2 > shape.X2 && s.Y == shape.Y2); if (rightShape != null) { DrawToRight(shape.X2, shape.Y2, rightShape, shapes, dxf); return; } //Tentando ir para baixo var bottomShape = shapes.FirstOrDefault(s => s.X2 == shape.X2 && s.Y == shape.Y2); if (bottomShape != null) { DrawToBottom(shape.X2, shape.Y2, bottomShape, shapes, dxf); return; } DrawToLeft(shape.X2, shape.Y2, shape, shapes, dxf); }
private void DrawToLeft(int x, int y, CADShape shape, List <CADShape> shapes, DxfDocument dxf) { var line = new Line(new Vector2(x, y), new Vector2(shape.X, shape.Y2)); //Desenhando o lado de baixo para esquerda line.Layer = _layerParede; dxf.AddEntity(line); //Tentando ir para baixo var bottomShape = shapes.FirstOrDefault(s => s.X2 == shape.X && s.Y >= shape.Y2 && s.Y2 < shape.Y2); if (bottomShape != null) { DrawToBottom(shape.X, shape.Y2, bottomShape, shapes, dxf); return; } //Tentando ir para esquerda var leftShape = shapes.FirstOrDefault(s => s.X2 == x && s.Y2 == y); if (leftShape != null) { DrawToLeft(shape.X, shape.Y2, leftShape, shapes, dxf); return; } DrawToTop(shape.X, shape.Y2, shape, shapes, dxf); }
private void DrawToTop(int x, int y, CADShape shape, List <CADShape> shapes, DxfDocument dxf) { var line = new Line(new Vector2(x, y), new Vector2(shape.X, shape.Y)); //Desenhando lado esquerdo para cima line.Layer = _layerParede; dxf.AddEntity(line); if (shape == shape.Place.OriginShape) //Terminou de desenhar todo o comodo { return; } //Tentando ir para esquerda var leftShape = shapes.FirstOrDefault(s => s.X2 == x && s.Y2 == y); if (leftShape != null) { DrawToLeft(shape.X, shape.Y, leftShape, shapes, dxf); return; } //Tentando ir para direita var topShape = shapes.FirstOrDefault(s => s.X == x && s.Y2 == y); if (topShape != null) { DrawToTop(shape.X, shape.Y, topShape, shapes, dxf); return; } DrawToRight(shape.X, shape.Y, shape, shapes, dxf); }
internal void OutputTraverse(string p, List <string> col0, List <string> colX, List <string> colY) { DxfDocument dxfTranvese = new DxfDocument(); Polyline poly = new Polyline(); for (int i = 0; i < col0.Count; i++) { poly.Vertexes.Add(new PolylineVertex(float.Parse(colX[i]), float.Parse(colY[i]))); Text text = new Text(); text.Value = col0[i]; text.BasePoint = new Vector3f(float.Parse(colX[i]), float.Parse(colY[i]), 0f); dxfTranvese.AddEntity(text); } dxfTranvese.AddEntity(poly); dxfTranvese.Save(p, DxfVersion.AutoCad2007);//保存为2007格式 }
private void WriteArc(DxfDocument doc, Arc arc) { var radius = CADPoint.Distance(arc.center, arc.startPoint); doc.AddEntity(new netDxf.Entities.Arc(new Vector2(arc.center.X, arc.center.Y), radius, arc.startAngle, arc.endAngle)); }
private void DrawToRight(int x, int y, CADShape shape, List <CADShape> shapes, DxfDocument dxf) { var line = new Line(new Vector2(x, y), new Vector2(shape.X2, shape.Y)); //Desenhando o topo para direita line.Layer = _layerParede; dxf.AddEntity(line); //Tentando ir para cima var topShape = shapes.FirstOrDefault(s => s.X == shape.X2 && s.Y2 == y); if (topShape != null) { DrawToTop(shape.X2, shape.Y, topShape, shapes, dxf); return; } //Tentando ir para direita var rightShape = shapes.FirstOrDefault(s => s.X == shape.X2 && s.Y == y); if (rightShape != null) { DrawToRight(shape.X2, shape.Y, rightShape, shapes, dxf); return; } DrawToBottom(shape.X2, shape.Y, shape, shapes, dxf); }
internal void OutputPoint(string p, List <string> col0, List <string> colX, List <string> colY) { DxfDocument dxfTranvese = new DxfDocument(); for (int i = 0; i < col0.Count; i++) { Point point = new Point(); point.Location = new Vector3f(float.Parse(colX[i]), float.Parse(colY[i]), 0f); dxfTranvese.AddEntity(point); Text text = new Text(); text.Value = col0[i]; text.BasePoint = new Vector3f(float.Parse(colX[i]), float.Parse(colY[i]), 0f); dxfTranvese.AddEntity(text); } dxfTranvese.Save(p, DxfVersion.AutoCad2007);//保存为2007格式 }
/// <summary> /// Saves the contours and hatches in layers corresponding to its tile /// </summary> /// <param name="outputDirectory"></param> /// <param name="outputName"></param> /// <returns></returns> public bool ExportAsDXF(string outputDirectory, string outputName) { var outputFilePath = Path.Combine(outputDirectory, outputName); var document = new DxfDocument(new HeaderVariables()); // combine geometries var geometries = HatchLines.Concat(ContourLines).ToArray(); // clip geometries in tiles and results to dxf layer for (int i = 0; i < Tiles.Count; i++) { for (int j = 0; j < geometries.Length; j++) { var results = GeometricArithmeticModule.ClipGeometry( geometries[j], Tiles[i] ); for (int k = 0; k < results?.Count; k++) { document.AddEntity( results[k].GetAsDXFEntity( $"Tile {i}" ) ); } } } document.Save(outputFilePath); return(File.Exists(outputFilePath)); }
public void WriteToFile(Project toExport, string filename) { Model modelSpace = null; if (toExport.GetModelCount() == 1) { modelSpace = toExport.GetModel(0); } else { modelSpace = toExport.FindModel("*Model_Space"); } if (modelSpace == null) { modelSpace = toExport.GetActiveModel(); } for (int i = 0; i < modelSpace.Count; i++) { EntityObject entity = GeoObjectToEntity(modelSpace[i]); if (entity != null) { doc.AddEntity(entity); } } doc.Save(filename); }
public void writeDxf(string file, string inputText, double textHeight, Layer layer) { bool isBinary; // this check is optional but recommended before loading a DXF file DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file, out isBinary); // netDxf is only compatible with AutoCad2000 and higher DXF version if (dxfVersion < DxfVersion.AutoCad2000) { return; } // load file dxfDocument = DxfDocument.Load(file); // text text = new Text(inputText, textLocation, textHeight); text.Layer = layer; text.Alignment = TextAlignment.BottomLeft; dxfDocument.AddEntity(text); // save to file dxfDocument.Save(file); }
private static void WritePolyline3d() { DxfDocument dxf = new DxfDocument(); List <Polyline3dVertex> vertexes = new List <Polyline3dVertex> { new Polyline3dVertex(0, 0, 0), new Polyline3dVertex(10, 0, 10), new Polyline3dVertex(10, 10, 20), new Polyline3dVertex(0, 10, 30) }; Polyline3d poly = new Polyline3d(vertexes, true); XData xdata = new XData(new ApplicationRegistry("netDxf")); xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf")); xdata.XDataRecord.Add(XDataRecord.OpenControlString); xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "netDxf polyline3d")); xdata.XDataRecord.Add(new XDataRecord(XDataCode.Integer, poly.Vertexes.Count)); xdata.XDataRecord.Add(XDataRecord.CloseControlString); poly.XData = new Dictionary <ApplicationRegistry, XData> { { xdata.ApplicationRegistry, xdata }, }; dxf.AddEntity(poly); dxf.Save("polyline.dxf", DxfVersion.AutoCad2000); }
private static void WritePolyfaceMesh() { DxfDocument dxf = new DxfDocument(); List <PolyfaceMeshVertex> vertexes = new List <PolyfaceMeshVertex> { new PolyfaceMeshVertex(0, 0, 0), new PolyfaceMeshVertex(10, 0, 0), new PolyfaceMeshVertex(10, 10, 0), new PolyfaceMeshVertex(5, 15, 0), new PolyfaceMeshVertex(0, 10, 0) }; List <PolyfaceMeshFace> faces = new List <PolyfaceMeshFace> { new PolyfaceMeshFace(new[] { 1, 2, -3 }), new PolyfaceMeshFace(new[] { -1, 3, -4 }), new PolyfaceMeshFace(new[] { -1, 4, 5 }) }; PolyfaceMesh mesh = new PolyfaceMesh(vertexes, faces); dxf.AddEntity(mesh); dxf.Save("mesh.dxf", DxfVersion.AutoCad2000); }
/// <summary> /// Saves a block to a dxf file. /// </summary> /// <param name="file">Dxf file name.</param> /// <param name="version">Version of the dxf database version.</param> /// <param name="isBinary">Defines if the file will be saved as binary, by default it will be saved as text</param> /// <returns>Return true if the file has been successfully save, false otherwise.</returns> public bool Save(string file, DxfVersion version, bool isBinary = false) { DxfDocument dwg = new DxfDocument(version); dwg.DrawingVariables.InsBase = this.position; dwg.DrawingVariables.InsUnits = this.Record.Units; Block copy = (Block) this.Clone(); dwg.AddEntity(copy.Entities); foreach (AttributeDefinition attdef in copy.AttributeDefinitions.Values) { dwg.AddEntity(attdef); } return dwg.Save(file, isBinary); }
/// <summary> /// Saves a block to a dxf file. /// </summary> /// <param name="file">Dxf file name.</param> /// <param name="version">Version of the dxf database version.</param> /// <param name="isBinary">Defines if the file will be saved as binary, by default it will be saved as text</param> /// <returns>Return true if the file has been successfully save, false otherwise.</returns> public bool Save(string file, DxfVersion version, bool isBinary = false) { DxfDocument dwg = new DxfDocument(version); dwg.DrawingVariables.InsBase = this.origin; dwg.DrawingVariables.InsUnits = this.Record.Units; foreach (EntityObject entity in this.entities) dwg.AddEntity((EntityObject)entity.Clone()); foreach (AttributeDefinition attdef in this.attributes.Values) dwg.AddEntity((EntityObject)attdef.Clone()); return dwg.Save(file, isBinary); }