RhSolutions-AddIn/RhSolutions.AddIn/Services/RhDxfWriter.cs
2023-04-17 08:49:26 +03:00

49 lines
1.4 KiB
C#

using netDxf;
using netDxf.Header;
using System.IO;
using Line = netDxf.Entities.Line;
namespace RhSolutions.Services;
public class RhDxfWriter : IExcelWriter
{
public void WriteProducts(Dictionary<Product, double> products)
{
WriteProducts(new[] { (string.Empty, products) });
}
public void WriteProducts(IEnumerable<(string, Dictionary<Product, double>)> products)
{ // your DXF file name
string file = "sample.dxf";
// create a new document, by default it will create an AutoCad2000 DXF version
DxfDocument doc = new DxfDocument();
// an entity
Line entity = new Line(new Vector2(5, 5), new Vector2(10, 5));
// add your entities here
doc.Entities.Add(entity);
// save to file
doc.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 versions
if (dxfVersion < DxfVersion.AutoCad2000) return;
// load file
DxfDocument loaded = DxfDocument.Load(file);
string docPath =
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
using (StreamWriter outputFile = new StreamWriter(Path.Combine(docPath, file)))
{
outputFile.Write(loaded);
}
}
public void Dispose()
{
}
}