private static void LoadSaveHatchTest() { DxfDocument dxf = new DxfDocument(); dxf.Load("Hatch2.dxf"); dxf.Save("HatchTest.dxf", DxfVersion.AutoCad2000); }
private void button1_Click(object sender, EventArgs e) { var fileContent = string.Empty; var filePath = string.Empty; var FCode = string.Empty; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "dxf files (*.dxf)|*.dxf|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Get the path of specified file filePath = openFileDialog.FileName; DxfDocument dxfLoad = DxfDocument.Load(filePath); Read_DXF(dxfLoad); } } }
/// <summary> /// Fügt Entity Objekte in einer bereits vorhandenen DXF Datei hinzu. /// </summary> /// <param name="dxf_path"> Pfad der DXF Datei, wo hinzugefügt werden soll</param> /// <param name="listObj"> Liste der hinzuzufügenden Entity Objekte</param> static public void JoinToDxF(string dxf_path, ElementManager.workpiece workPiece, params EntityObject[] listObj) { DxfDocument doc; if (File.Exists(dxf_path)) { FileInfo file = new FileInfo(dxf_path); if (file.Extension == ".dxf") { doc = DxfDocument.Load(dxf_path); 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); } else { throw new Exception(" Error NTB_DXF_200003 : The file you gave is not a dxf file"); } } else { throw new Exception(" Error NTB_DXF_200004 : The path you entered is not corrrect"); } }
// Open profile private static DxfDocument OpenProfile(string file) { // open the profile file FileInfo fileInfo = new FileInfo(file); // check if profile file is valid if (!fileInfo.Exists) { Console.WriteLine("THE FILE {0} DOES NOT EXIST", file); Console.WriteLine(); return(null); } DxfDocument dxf = DxfDocument.Load(file, new List <string> { @".\Support" }); // check if there has been any problems loading the file, if (dxf == null) { Console.WriteLine("ERROR LOADING {0}", file); Console.WriteLine(); Console.WriteLine("Press a key to continue..."); Console.ReadLine(); return(null); } return(dxf); }
public override void Read(IDrawing drawing) { try { DxfDocument dxf = DxfDocument.Load(_stream); var entities = new List <Entity>(); entities.AddRange(ReadLines(dxf)); entities.AddRange(ReadPolylines(dxf)); entities.AddRange(ReadArcs(dxf)); entities.AddRange(ReadCircles(dxf)); entities.AddRange(ReadEllipses(dxf)); foreach (var item in drawing.CurrentBlock) { item.Erase(); } foreach (var item in entities) { drawing.CurrentBlock.AppendEntity(item); } } finally { if (_stream != null) { _stream.Close(); } } }
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"); }
private void loadDXFToolStripMenuItem_Click(object sender, EventArgs e) { if (dxfOpenFileDialog.ShowDialog() == DialogResult.OK) { try { _model.GetNodes().Clear(); //Get the path of specified file _doc = DxfDocument.Load(dxfOpenFileDialog.FileName); if (_doc == null) { MessageBox.Show("Failed to Load DXF File", "Error"); return; } var fileName = new FileInfo(dxfOpenFileDialog.FileName); Text = "xModel Gen \"" + fileName.Name + "\""; DrawDxf(_doc); } catch (Exception exception) { Console.WriteLine(exception); MessageBox.Show(exception.Message, "Error"); } } }
public void OpenDxfFile(string path) { try { var layer = new Layer(); var dxfDoc = DxfDocument.Load(path); foreach (var poly in dxfDoc.Polylines) { if (poly.Layer.Name != "KADASTRO") { continue; } var polygon = new Polygon(); foreach (var vertex in poly.Vertexes) { polygon.Coors.Add(new Coor(vertex.Position.X, vertex.Position.Y)); } layer.Geoms.Add(polygon); } Map.Layers.Add(layer); } catch (Exception) { } }
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); }
private IPolygon ReadPolygonFromDXF(string path) { bool isBinary; using (var stream = File.OpenRead(path)) { var dxfVersion = DxfDocument.CheckDxfFileVersion(stream, out isBinary); if (dxfVersion < DxfVersion.AutoCad12 && dxfVersion > DxfVersion.AutoCad2010) { throw new ApplicationException("系统无法读取当前版本的CAD文件,请提交AutoCAD R12至AutoCAD 2010版本生成的DXF文件。"); } var dxf = DxfDocument.Load(stream, dxfVersion < DxfVersion.AutoCad2000); if (dxf == null) { throw new ApplicationException("无法识别的dxf文件,上传的dxf文件可能已经损坏。"); } if (dxf.LwPolylines.Count == 0) { throw new ApplicationException("CAD文件中无法找到红线。"); } if (dxf.LwPolylines.Count > 1) { throw new ApplicationException("CAD文件中红线数量大于一个,请删除不必要的图形。"); } return(GeneratePolygon(dxf.LwPolylines[0])); } }
public void Load(IMesh mesh, string filePath) { var dxfLoad = DxfDocument.Load(filePath); var vertices = new List <IVertex>(); var faces = new List <IFace>(); var verticesIndexMap = new Dictionary <IVertex, int>(); int currentVertexIndex = 0; foreach (var face3D in dxfLoad.Faces3d) { var v1 = face3D.FirstVertex; var v2 = face3D.SecondVertex; var v3 = face3D.ThirdVertex; var v4 = face3D.FourthVertex; currentVertexIndex = CreateTriangleFace(v1, v2, v3, verticesIndexMap, currentVertexIndex, vertices, faces); currentVertexIndex = CreateTriangleFace(v3, v4, v1, verticesIndexMap, currentVertexIndex, vertices, faces); } foreach (var vertex in vertices) { mesh.AddVertex(vertex); } foreach (var face in faces) { mesh.AddFace(face); } }
/// <summary> /// 获取dxf文件中的图形数据 /// </summary> /// <param name="path"></param> /// <returns></returns> public static List <FigureBaseModel> LoadDXF(string path) { List <FigureBaseModel> values = new List <FigureBaseModel>(); DxfDocument dxfdoc = DxfDocument.Load(path); var points = dxfdoc.Points.ToConverter(); var lines = dxfdoc.Lines.ToConverter(); var lwPolylines = dxfdoc.LwPolylines.ToConverter(); var arcs = dxfdoc.Arcs.ToConverter(); var circles = dxfdoc.Circles.ToConverter(); var ellipses = dxfdoc.Ellipses.ToConverter(); var leaders = dxfdoc.Leaders.ToConverter(); var splines = dxfdoc.Splines.ToConverter(); var xlines = dxfdoc.XLines.ToConverter(); var mtexts = dxfdoc.MTexts.ToConverter(); values.AddRange(points); values.AddRange(lines); values.AddRange(lwPolylines); values.AddRange(arcs); values.AddRange(circles); values.AddRange(ellipses); values.AddRange(splines); values.AddRange(xlines); values.AddRange(mtexts); SN = 1; return(values); }
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 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"); }
void DataLoaded(byte[] data) { MemoryStream stream = new MemoryStream(data); DxfDocument doc = DxfDocument.Load(stream); editor.PushUndo(); foreach (var l in doc.Lines) { AddLine(l); } foreach (var pl in doc.Polylines) { foreach (netDxf.Entities.Line l in pl.Explode()) { AddLine(l); } } foreach (var pl in doc.LwPolylines) { foreach (var e in pl.Explode()) { if (e is netDxf.Entities.Line) { AddLine((netDxf.Entities.Line)e); } if (e is netDxf.Entities.Arc) { AddArc((netDxf.Entities.Arc)e); } } } foreach (var spl in doc.Splines) { var vertices = spl.PolygonalVertexes(32); for (int i = 0; i < vertices.Count - 1; i++) { var s = vertices[i]; var e = vertices[i + 1]; LineEntity line = new LineEntity(DetailEditor.instance.currentSketch.GetSketch()); line.p0.SetPosition(new UnityEngine.Vector3((float)s.X, (float)s.Y, (float)s.Z)); line.p1.SetPosition(new UnityEngine.Vector3((float)e.X, (float)e.Y, (float)e.Z)); AutoConstrain(line); } } foreach (var c in doc.Circles) { AddCircle(c); } foreach (var a in doc.Arcs) { AddArc(a); } }
static void Main(string[] args) { DxfDocument dxfDocument; dxfDocument = DxfDocument.Load(@"C:\Users\Николай\Desktop\шаблон_Эпюр.dxf"); var test = dxfDocument.Blocks.Items.Where(x => x.Name == "тест1").First().AttributeDefinitions.Where(x => x.Key == "ТЕСТОВЫЙ_АТРИБУТ").First().Value.Value; var epureM = new EpureM(dxfDocument.Lines.Where(x => x.Layer.Name == "M").ToArray()); var epureM1 = new EpureM(dxfDocument.Lines.Where(x => x.Layer.Name == "M1").ToArray()); var epureM2 = new EpureM(dxfDocument.Lines.Where(x => x.Layer.Name == "M2").ToArray()); var epureM3 = new EpureM(dxfDocument.Lines.Where(x => x.Layer.Name == "M3").ToArray()); var d11 = EpureM.MultiplicationEpure(epureM1, epureM1); var d12 = EpureM.MultiplicationEpure(epureM1, epureM2); var d13 = EpureM.MultiplicationEpure(epureM1, epureM3); var d22 = EpureM.MultiplicationEpure(epureM2, epureM2); var d23 = EpureM.MultiplicationEpure(epureM2, epureM3); var d33 = EpureM.MultiplicationEpure(epureM3, epureM3); var d1p = EpureM.MultiplicationEpure(epureM, epureM1); var d2p = EpureM.MultiplicationEpure(epureM, epureM2); var d3p = EpureM.MultiplicationEpure(epureM, epureM3); Excel.Workbook workbook; Excel.Worksheet worksheet; Excel.Application application = new Excel.Application(); workbook = application.Workbooks.Open(@"e:\Програмирование\Перемножение эпюр\матрица.xlsx"); worksheet = workbook.Worksheets.get_Item(1); worksheet.Cells[3, 2] = d11; worksheet.Cells[4, 3] = d22; worksheet.Cells[5, 4] = d33; worksheet.Cells[3, 3] = d12; worksheet.Cells[3, 4] = d13; worksheet.Cells[4, 4] = d23; worksheet.Cells[3, 6] = -d1p; worksheet.Cells[4, 6] = -d2p; worksheet.Cells[5, 6] = -d3p; double.TryParse((worksheet.Cells[8, 6] as Excel.Range)?.Value.ToString(), out double x1); double.TryParse((worksheet.Cells[9, 6] as Excel.Range)?.Value.ToString(), out double x2); double.TryParse((worksheet.Cells[10, 6] as Excel.Range)?.Value.ToString(), out double x3); EpureM epureM1X = epureM1.MultiplicationEpure(x1); EpureM epureM2X = epureM2.MultiplicationEpure(x2); EpureM epureM3X = epureM3.MultiplicationEpure(x3); EpureM epureOk = EpureM.SumEpureM(epureM1X, epureM2X, epureM3X, epureM); epureOk.AddLoad(20, 1); epureOk.PrinyQ(); //epureOk.PrintM(); Point point = new Point(); }
/// <summary> /// 读取加载dxf底图文件 /// </summary> /// <param name="ms">文件流</param> /// <param name="type"></param> /// <param name="layerName"></param> public List <Plist> Read(System.IO.Stream ms, int type, string layerName) { try { DxfDocument doc = new DxfDocument(); doc.Load(ms); this.MinX = 50;//doc.ExtMinPoint.X - doc.ExtMaxPoint.X + doc.ExtMinPoint.X; this.MaxY = 2 * (doc.ExtMaxPoint.Y - doc.ExtMinPoint.Y) - 700; if (MaxY > 10000 || doc.ExtMaxPoint.X - doc.ExtMinPoint.X > 10000) { throw new DxfException("Dxf的图形界限长宽不能超过10000"); } Layers = doc.Layers.Where(p => p.IsVisible).Select(p => new SvyLayer() { ID = null, IsClose = false, LayerName = p.Name, Type = 0 }).ToList(); Dictionary <int, string> dictionary = new Dictionary <int, string>(); var i = 1; List <string> list = new List <string>(); Layers.ForEach(c => { //dictionary.Add(i, c.LayerName); list.Add(c.LayerName); //++i; }); if (layerName.Equals("all")) { return(LoadShaps(doc.Shaps, type, list)); } var dd = dictionary.ToList().Where(c => c.Value == layerName); list = list.Where(c => c.Equals(layerName)).ToList(); //var bb = dictionary; return(LoadShaps(doc.Shaps, type, list)); } catch (DxfException de) { throw de; } catch (Exception ex) { throw ex; } }
private void Do() { GmshMeshGenerator meshGenerator = new GmshMeshGenerator(configuration.GmshPath); MeshProperties meshProperties = new MeshProperties { Size = Convert.ToDouble(tbDimensionFE.Text, CultureInfo.InvariantCulture), Type = (MeshType)cbTypeOfFE.SelectedItem, }; List <string> files = ChooseFiles(); foreach (string file in files.Where(File.Exists)) { FileInfo fileInfo = new FileInfo(file); DxfDocument doc = DxfDocument.Load(file); DxfModel model = DxfManager.GetDxfModel(doc, tbFrameLayer.Text, tbShellLayer.Text); Model meshModel = Solver.GetMeshModel(model); Mesh mesh = meshGenerator.GenerateMesh(meshModel, meshProperties); List <int[]> elements = mesh.Connectivities .Select(con => { int[] ints = new int[con.Points.Length]; for (int index = 0; index < ints.Length; index++) { ints[index] = con.Points[index]; } return(ints); }) .ToList(); Dictionary <int, double[]> points = mesh.Points .ToDictionary(kvp => kvp.Key, kvp => { double[] point = new double[kvp.Value.Count]; for (var index = 0; index < point.Length; index++) { point[index] = kvp.Value[index]; } return(point); }); if (cbGenerateDXF.Checked) { if (fileInfo.DirectoryName != null) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file); string destinationPath = Path.Combine(fileInfo.DirectoryName, path2: $"{fileNameWithoutExtension}_IMPORT_TO_SAP.dxf"); DxfManager.CreateDxfFile(destinationPath, elements, points); } } if (cbImportSAP2000.Checked) { } //SAPmodelGenerator.ImportModel(elements, points); } }
// 读取Dxf文件 public void ReadFile(string path) { DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(path); if (dxfVersion < DxfVersion.AutoCad2000) { return; } this.Dxf = DxfDocument.Load(path); }
private void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Dxf files (*.dxf)|*.dxf|All files (*.*)|*.*"; if (dialog.ShowDialog() == true) { dxfDocument = DxfDocument.Load(dialog.FileName); } }
public void Draw(string path) { dxf = DxfDocument.Load(path); if (dxf != null) { AddLayers(); AddGraph(); AdjustGraph(); } }
//needs to go to cadgen exporter with a list of polylines and attributes public static MemoryStream Get(string fileName, IExporter cadGenExporter, Action <string> action) { bool isBinary; var ver = DxfDocument.CheckDxfFileVersion(fileName, out isBinary); DxfDocument doc = DxfDocument.Load(fileName); var docSector = doc.Texts.FirstOrDefault(x => string.Equals(x.Layer.Name, "Sector", StringComparison.InvariantCultureIgnoreCase)); var polys = GetPolys(doc); var i = 0; var c = polys.Count(); //Parallel.ForEach(polys, p => foreach (var p in polys) { var cI = Interlocked.Increment(ref i); action($"Export DXF: {cI} / {c}; index:{p.index.Value}"); //CF - INDEX int index; if (int.TryParse(p.index.Value.Trim(), out index)) { var points = p.poly.ToPoints(); var area = VectorExtensions.Area(points); p.poly.XData.Clear(); var cg = cadGenExporter.Export(index, points, area, p.nrCadGeneral?.Value, docSector?.Value, p.nrCadastral?.Value).Result; if (cg.Length > 0) { var xD = new XData(new ApplicationRegistry("TOPO")); xD.XDataRecord.Add(new XDataRecord(XDataCode.ControlString, "{")); foreach (var line in cg) { var xDR = new XDataRecord(XDataCode.String, line); xD.XDataRecord.Add(xDR); } xD.XDataRecord.Add(new XDataRecord(XDataCode.ControlString, "}")); p.poly.XData.Add(xD); } } }//); var stream = new MemoryStream(); doc.Save(stream, isBinary); stream.Seek(0, SeekOrigin.Begin); return(stream); }
public ColoOptimizer(string fileName) { boxes = new List <ColoBox>(); try { dxf = DxfDocument.Load(fileName); } catch (Exception) { } }
public void Load(string filePath) { _dxf = new DxfDocument(); _dxf.Load(filePath); foreach (netDxf.Tables.LineType lineType in _dxf.LineTypes) { _lineTypeDictionary.Add(lineType, PicGraphics.LT.LT_CUT); _lineType2GrpDictionary.Add(lineType, 0); } }
internal DxfDocument Optimize() { dxf = DxfDocument.Load(fileName); boxes = new List <ColoBox>(); loadPolylinesToBoxes(); //CustomHatchPattern(dxf,layer); RelocateRacks(dxf); return(dxf); }
public DxfHelperRead(String fullFileName) { if (String.IsNullOrEmpty(fullFileName)) { throw new ArgumentNullException("File name is null or is empty."); } if (!File.Exists(fullFileName)) { throw new FileNotFoundException(fullFileName); } this.dxf = DxfDocument.Load(fullFileName); }
private static void ReadDxfFile() { DxfDocument dxf = new DxfDocument(); //dxf.Load("AutoCad2007.dxf"); //dxf.Load("AutoCad2004.dxf"); dxf.Load("AutoCad2000.dxf"); dxf.Save("AutoCad2000 result.dxf", DxfVersion.AutoCad2000); //dxf.Load("AutoCad12.dxf"); //dxf.Load("Tablet.dxf"); //dxf.Save("Tablet result.dxf", DxfVersion.AutoCad2000); }
public void LoadFile(string filename) { DxfDocument loaded = DxfDocument.Load(filename); Layers = loaded.Layers.OrderBy(x => x.Name).Select(x => new DXFLayer { LayerName = x.Name, Visible = true, color = x.Color.ToColor() }).ToArray(); Shapes = new List <DXFShape>(); foreach (var block in loaded.Blocks) { foreach (var shape in block.Entities) { switch (shape.Type) { case EntityType.Polyline: Shapes.Add(new DXFPolyline(shape.Color.ToColor(), 1, shape.Layer.Name)); break; case EntityType.LightWeightPolyline: Color color = shape.Color.ToColor(); if (shape.Color.IsByLayer) { color = shape.Layer.Color.ToColor(); } var pl = new DXFPolyline(color, 1, shape.Layer.Name); var specificShape = (LwPolyline)shape; for (int i = 1; i < specificShape.Vertexes.Count; i++) { pl.AppendLine(new DFXLine( new System.Drawing.Point((int)specificShape.Vertexes[i - 1].Position.X, -1 * (int)specificShape.Vertexes[i - 1].Position.Y), new System.Drawing.Point((int)specificShape.Vertexes[i].Position.X, -1 * (int)specificShape.Vertexes[i].Position.Y), color, (int)specificShape.Vertexes[i].StartWidth) ); } Shapes.Add(pl); break; case EntityType.Hatch: break; default: break; } } } }
void fixDXF(string[] files) { foreach (string file in files) { //open in the version that supports saving and opening R12, do all the work in latest version, then save as R12 string fileName = Path.GetFileName(file); string tempFileName = file.Substring(0, file.Length - fileName.Length) + "TMP.DXF"; Console.WriteLine(fileName.Substring(fileName.Length - 4).ToLower()); if (fileName == null || fileName.Substring(fileName.Length - 4).ToLower() != ".dxf") { continue; } //open as R12 and save in different format for newer library R12.netDxf.DxfDocument inputDxf = new R12.netDxf.DxfDocument(); inputDxf.Load(file); inputDxf.Save(tempFileName, R12.netDxf.Header.DxfVersion.AutoCad2010); //open in new library and do all the editing DxfDocument workingDxf = DxfDocument.Load(tempFileName); Arc[] toRemove = new Arc[workingDxf.Arcs.Count()]; LwPolyline[] toAdd = new LwPolyline[workingDxf.Arcs.Count()]; int count = 0; foreach (Arc i in workingDxf.Arcs) { toRemove[count] = i; toAdd[count] = i.ToPolyline(1000); count++; } for (int i = 0; i < toRemove.Length; i++) { workingDxf.RemoveEntity(toRemove[i]); workingDxf.AddEntity(toAdd[i]); } workingDxf.Save(tempFileName); //open it back in R12 library and save as R12 R12.netDxf.DxfDocument outputDxf = new R12.netDxf.DxfDocument(); outputDxf.Load(tempFileName); outputDxf.Save(file.Insert(file.Length - 4, "_FIXED"), R12.netDxf.Header.DxfVersion.AutoCad12); File.Delete(tempFileName); } }
public Drawing ReadDrawing(string dxfFileName, Canvas canvas) { _doc = DxfDocument.Load(dxfFileName); _drawing = new Drawing(canvas); ReadLines(); ReadPolylines(); ReadArcs(); ReadCircles(); ReadInserts(); _drawing.Recalculate(); return(_drawing); }