Git Product home page Git Product logo

dxf's People

Contributors

brettfo avatar lgrzywac avatar nzain avatar sampletext32 avatar soreinhard avatar ugaitzetxebarria avatar zoisjp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dxf's Issues

Read error while opening dxf in AutoCAD 2013

Saved drawing from AutoCAD (2013) as DXF (test_001.dxf) , read the file in IxMilia and without any changes, save the file again from IxMilia (test_002.dxf) and then the file won't open in AutoCAD.

The error showing in AutoCAD is :
Invalid symbol table record name: on line 1570
Invalid or imcomplete DXF input -- drawing discarded.

I think there is a problem in AcDbViewTableRecord section. Please check.

test_001.dxf.txt
test_002.dxf.txt

Better support with Teigha libraries.

Tweak files written by IxMilia.Dxf so that the Open Design Aliance Teigha libraries can open them. This may include, but is not limitied to:

1 - $ACADVER should default to R12 instead of R14.
2 - Add support for the OBJECTS section.

As another note, Teigha will read R10 files written by IxMilia.Dxf, but not R11, and it won't read any R14 file even if the header only contains $ACADVER/AC1014.

Read error while opening dxf - Invalid or incomplete DXF input

I have generated a new drawing from the acadiso.dwt template using AutoCAD v2019. I then saved this drawing file in dxf format in AutoCAD. Using the IxMilia.Dxf library to open the file and then save a copy appears to generate an invalid dxf file that I am unable to open in AutoCAD or BricsCAD.

AutoCAD displays the error message...

Unknown group 102 for table on line 758.
Invalid or incomplete DXF input -- drawing discarded.

DraftSight v2018 will open the file and includes added entities, however it displays a warning before opening the file...

ViewTableRecord(D): Record name is empty - Ignored

using System.IO;
using IxMilia.Dxf;
using IxMilia.Dxf.Entities;
using Xunit;

namespace plansTest1
{
    public class UnitTest1
    {
        [Fact]
        public void ReadWriteDxf()
        {
            // Open existing drawing file
            DxfFile dxfFile = new DxfFile();
            using (FileStream fs = new FileStream(@"Blank_test.dxf", FileMode.Open))
            {
                dxfFile = DxfFile.Load(fs);
            }

            // Add a line entity to the file
            dxfFile.Entities.Add(new DxfLine(new DxfPoint(0, 0, 0), new DxfPoint(100, 100, 0)));

            // Save a copy of the file
            using (FileStream fs = new FileStream(@"Read_Write_Test.dxf", FileMode.Create))
            {
                dxfFile.Header.SetDefaults();
                dxfFile.ViewPorts.Clear();
                dxfFile.Save(fs);
            }
        }
    }
}

Blank_test.dxf.txt
Read_Write_Test.dxf.txt

Help extracting this information

Hey guys. This is sort of a long shot, but I was wondering if anyone could give me some guidance into how I could be able to extract the information in the table shown in this image.

I have a possible small project where I need to be able to grab a DXF file representing architecture blueprints made with AutoCAD, find one or several of those tables and convert the data to human-friendly descriptions.

I've used a couple of DXF viewers to be able to understand their structure, but to my untrained eye there doesn't seem to be any. The file seems to be composed of visual elements such as lines and labels with no real relationship between them.

Any ideas? Thanks.

Release newest features

Is it possible to build a release from the newest trunk version? I'm trying to export a 3DPolyline and would need the changes in DxfVertex and DxfPolyline for it to work properly.

Crash while reading DXF file (R14)

Hi,

Thank you very much for this library that I would like to use for my DXF importing.
It is a big help.

Now, I got a "special" DXF where it crashes while it is reading a dxf file. It crashes in "DXFLib.dll!IxMilia.Dxf.DxfAsciiReader.GetCodePair()" , with the message "Unexpected code value".

Do you may have an idea what is wrong?

File attached (you need to rename from txt to dxf).

Thanks in advance

Best regards

Happe

822621004001.txt

QCAD Compatibility

I've been using this library with great success for reading simple dxf files from various sources. Now, I'm trying to write a simple 2D polyline like this:

DxfFile dxfFile = new DxfFile();
DxfLayer layer = new DxfLayer("testlayer", DxfColor.FromIndex(2));
dxfFile.Layers .Add(layer);
List<DxfVertex> staVertices = staticSegs
    .Select(point => new DxfVertex(new DxfPoint(point.X, point.Y, 0)))
    .ToList();
DxfPolyline staticPoly = new DxfPolyline(staVertices)
{
    Layer = layer.Name,
    Color = DxfColor.FromIndex(4),
    Thickness = 0.001,
    IsClosed = true
};
dxfFile.Entities.Add(staticPoly);
using (var fs = File.Create(@"d:\downloads\" + trackname + ".dxf"))
{
    dxfFile.Header.SetDefaults();
    dxfFile.ViewPorts.Clear();
    dxfFile.Header.Version = DxfAcadVersion.R2000;
    dxfFile.Header.DefaultDrawingUnits = DxfUnits.Meters;
    dxfFile.Header.DrawingUnits = DxfDrawingUnits.Metric;
    dxfFile.Save(fs);
}

Opening the resulting file in QCAD community edition does not show the expected result: The polyline is visible, but neither layer, color, nor thickness is set. Either QCAD cannot read the format (I've tried with default AcadVersion R12, max R2018, and R2000), or the library does not write them as expected, or I'm doing something wrong. Any idea what's going wrong?

Side note: a DxfLwPolyline did not show up at all in QCAD.

Maintenance Version larger than int16

While translating a file exported using Bentley Micro Station using IxMilia Dxf it was observed that the Maintenance Version was greater than an int16.

This can be resolved by changing it from short to int on lines 303 and 3709 in the DxfHeaderGenerated.cs file. I have submitted a pull request with this change.

Cheers

about Table

Hi,
which DXFVersion support to write the table ?
thank you.

Loading dxf fails

Loading fails with the attached file Original.dxf in the function DxfMLineStyle/PostParse, with an index out of range exception (cause: different length of lists).

Loading works with removed section AcDbMlineStyle in the dxf file (AcDbMlineStyle_Removed.dxf).

Would it be possible to change the funktion PostParse, that only DxfMLineStyleElements are added if the lists have the same lengths?

dxfFiles.zip

DxfColor.FromIndex(0) returns ByBlock

I'm trying to convert RGB values to DxfColor. One way to do this is search the table of DxfColor.DefaultColors for the "closest match", e.g. by computing a squared distance.

However, the the library defines RawValue = 0 as "ByBlock" and essentially the first color (index zero: 0xFF000000) cannot be retreived. Is this intended? Related: #14 and #18.

Any other smart ideas, how to convert RGB to its closest DxfColor?

Thanks in advance!
Patrick

netstandard nuget dependencies pollution

Hi Brett,

we're moving our desktop application to .net framework 4.6.2 (compatible with netstandard2.0) and reference our own netstandard2.0 libraries now. No extra dependencies required. When I reference ixmilia.dxf.csproj directly (cloned from github) this works as expected - no extra dependencies. However, when I install the ixmilia.dxf nuget package, lots of netstandard nuget packages pollute my poor library. Eventually the extra dependencies don't make a difference for the final bin/release folder, but

  • the packages.config is overwhelming right now (from 2 entries up to 48) and
  • relevant nuget package updates for the application are hidden between many netstandard updates (that don't make a difference anyways?).

You told me (via email last year) that this is the intended behavior for desktop apps - but since it works for direct project references, this looks wrong to me and eventually we can find a simple solution.

I've googled quite a bit, but couldn't find anything yet. There were lots of tooling issues with indirect references not flowing correctly - not my concern. I've found some threads saying it will be resolved, when netstandard2.0 is out (e.g. aspnet/Logging#550 ) but that seems to be wrong with nuget packages. Referencing the csproj is fine, referencing the nuget package requires 46 confusing dependencies.

Okay... I found a solution by myself: multi-targeting. Edit the csproj and change

- <TargetFramework>netstandard1.0</TargetFramework>
+ <TargetFrameworks>netstandard1.0;net45</TargetFrameworks>

(note that extra 's'). This will add a net45 layer to the nuget package
capture
and consumers via nuget don't have to install netstandard dependencies. Just tested it, works as expected.

If there is no drawback (except for increased nupkg file size), it would be great to see this in the next release.

Maximum size of dxf-file

Sorry that im making an issue for this but i actually don´t know how to ask this question in an other way.

As the title says i want to know the actual size of the dxf, well not the file size but the maximum size of the element to make something like the green border in the picture.
grafik

Where and how do i get these measurements?
Because it seems that they have to be in the dxf file itself, but the values for $extmin and $extmax aren´t trustworthy.
Thanks in advance.

How can I load it from AutoCAD?

In AutoCAD 2018, save the line as a dxf file.
Load the file with IxMillia.DXF and save it again.
AutoCAD 2018 can not load the dxf file.

How can I load it from AutoCAD?

like this code..
filename_temp.dxf can not be opened in AutoCAD.

private void button1_Click(object sender, EventArgs e)
{
try {
OpenFileDialog openFile = new OpenFileDialog();

    openFile.Filter = "dxf Files(*.dxf)|*.dxf";
    openFile.ShowDialog();

    if (openFile.FileNames.Length > 0)
    {
        String filePath = openFile.FileName;

        DxfFile readDxfFile;
        using (FileStream fs = new FileStream(filePath, FileMode.Open))
        {
            readDxfFile = DxfFile.Load(fs);
        }
                
        String tempFilePath = filePath.ToLower().Replace(".dxf", "_temp.dxf");

        using (FileStream fs = new FileStream(tempFilePath, FileMode.Create))
        {
            readDxfFile.Header.Version = DxfAcadVersion.R12;
            readDxfFile.Save(fs);
        }

        MessageBox.Show("done");
                
    }
}
catch (Exception exp)
{
    MessageBox.Show(exp.Message);
}

}

Net 3.5 Support

We use this dxf library successfully for modern WPF apps, but we have several projects for mobile applications based on compact framework (WinCE) which is supported until VS2008 and .net35. I loaded Ixmilia.Dxf source code into a net35 project and found mostly covariance issues, a missing Guid.TryParse call, and a linq Zip call. That looks promising. Since we won't get away from net35 anytime soon, I'd like to support a net35 variation of this library. I can see different routes - before I bring up a PR, I'd like to hear your oppinion.

  1. I could fork and build for net35 myself. This repository stays clean and modern.
  2. We could use #if preprocessor directives to support "the old way" in about 20 places and have a IxMilia.Dxf.Net35.csproj parallel to the netcore one. I can create a PR for this and I would support this one, if you're interested.
  3. I can tell my boss that we have to upgrade some apps (VS and framework, too) and duplicate many csproj files (VS08+net35/VS17+net462) - probably the most time consuming option.
  4. Evaluate other libraries for DXF, e.g. Teigha. Not my favorite plan.

Lets ignore 3. and 4. please :-) I know, you're working with code generation (this project doesn't even load on my machine) and eventually compiler flags are tricky? Let me know what you think.

DxfLwPolyline not correctly saved and loaded

FileStream stream = File.Create("out.dxf");
DxfFile dxfFile = new DxfFile();
dxfFile.Entities.Add(new DxfLwPolyline(new List<DxfLwPolyline>()
{
    new DxfLwPolyline() {X = 0, Y = 1},
    new DxfLwPolyline() {X = 1, Y = 1},
    new DxfLwPolyline() {X = 1, Y = 0},
}));
dxfFile.Save(stream);
stream.Flush();
stream.Dispose();

I have codes like above.
By setting breakpoints, there is 1 entity in dxfFile.Entities when dxfFile.Save is called.
However, when the file gets read by calling DxfFile.Load, there is nothing in the entity set.
I have tested that entities of type DxfLine, DxfCircle, DxfArc, and even DxfPolyline can be correctly exported, but entities of type DxfLwPolyline are always missing when load from file streams.

LwPolyLine.Vertices do not have their Bulge set

When loading a DxfLwPolyline with some bulged segments, the Vertices all have Bulge zero (never set). While the DxfLwPolyline.Bulge list contains the bulge values, there is no way to associate those values with a DxfVertex.

If I understood the code, the PostParse method converts all x-coordinates and y-coordinates into vertices - however, the list of bulge doubles typically has a different length and, thus, they can't be combined "post-mortem". A TODO tag indicates that this is not finished :)

For example, when parsing a LWPOLYLINE entity

 10
2.0
 20
0.0
 42
0.7

 10
1.0
 20
2.5

 10
-1.0
 20
2.5
 42
0.7

 10
-2.0
 20
0.0

there are four vertices (x,y each), two of them with non-zero bulge (key 42). The bulge values never makes it into the corresponding vertex.

I don't have an old POLYLINE entity to test with, but the respective code seems very different from LWPOLYLINE parsing. Again, I could not find sourcecode, where key 42 ~ bulge is set.

It seems that the parser has to maintain some internal state - the vertex being parsed currently. That vertex is added, when the next vertex begins / the polyline ends. Not sure, how to integrate this with your t4 magic.

Drop me an e-mail, if you need test files (created with free version of QCad).
best, Patrick

Don't allow invalid values to be set.

This is a larger issue encompassing many smaller items, specifically, but not necessarily limited to:

  • Instances of List<T> should be replaced with something like ListWithPredicate<T> that will throw on null or otherwise invalid values. This will make a lot of internal null checks go away. COMPLETE WITH c61c463
  • Line type styles specified by entities will have to have a valid entry in the LTYPE table. If one is not present, one will be created. Similarly for other values. COMPLETE WITH 935580e
  • LEADERs and POLYLINEs require at least 2 vertices. COMPLETE FOR LEADER AND LWPOLYLINE WITH 905f3ef AND COMPLETE FOR POLYLINE WITH d1d3946

During all of this, I'd like to follow the idea that this library will be able to open nearly any DXF file, valid or otherwise to avoid the situation that AutoCAD is in, namely that it's the most complete/correct implementation but it's rather fussy about what it will accept and easy to make crash.

Do not rely on current culture when parsing double values

First off: nice code. Looks professional!

However, I was scratching my head, when your library threw an ArgumentOutOfRangeException while parsing the following header part:

$TDCREATE
 40
2456478.590142998

Diving deep into your code revealed that you rely on double.TryParse(string s, out double d) which is culture dependent. I'm from germany - decimal separator is comma, thousands separator is dot. Thus, double.TryParse succeeds since it ignores the dot (as if it was a thousands separator) and returns the double value

2456478590142998.0

Now add this to the julian calendar base and someone is scratching his head :-)

I'm not sure what the DXF spec says about decimal separators, but if it is culture invariant, you should use

double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out result)

Support reading/writing XDATA

XDATA starts with 1001 code with the application name as the string value and each 1001 code indicates a new section. Order is important. See page 273 of the DXF 2014 spec.

Enable reporting warnings and better errors.

Enable warnings to be reported on open and report line/offset. Perhaps add a parameter Action<int, string> warningCallback to DxfFile.Load() that returns line/offset and a message. Also, DxfReadException should also contain line/offset.

Unexpected XDATA code pair

Hello,

I got another file that runs into a crash. It crashes in the line 189 of DxFXDataItem

where "throw new DxfReadException("Unexpected XDATA code pair", pair);" is called.

Do you may have an idea?

Thank you

Happe

Attached file (rename it into ce117090.dxf):
ce117090.txt

Can't open 2D export from Google Sketchup

I'm having trouble opening DXF exported (2D) from Google Sketchup 2016.

IxMilia.Dxf.DxfReadException was unhandled by user code
  HResult=-2146233088
  Message=Unexpected code pair group text
  Offset=3399
  Source=IxMilia.Dxf
  StackTrace:
       at IxMilia.Dxf.DxfCodePairGroup.FromBuffer(DxfCodePairBufferReader buffer, String groupName) in E:\IxMilia\Dxf\src\IxMilia.Dxf\DxfCodePairGroup.cs:line 86
       at IxMilia.Dxf.Objects.DxfObject.TrySetExtensionData(DxfCodePair pair, DxfCodePairBufferReader buffer) in E:\IxMilia\Dxf\src\IxMilia.Dxf\Objects\DxfObject.cs:line 135
       at IxMilia.Dxf.Objects.DxfXRecordObject.PopulateFromBuffer(DxfCodePairBufferReader buffer) in E:\IxMilia\Dxf\src\IxMilia.Dxf\Objects\DxfXRecordObject.cs:line 30
       at IxMilia.Dxf.Objects.DxfObject.FromBuffer(DxfCodePairBufferReader buffer) in E:\IxMilia\Dxf\src\IxMilia.Dxf\Objects\DxfObjectGenerated.cs:line 314
       at IxMilia.Dxf.Sections.DxfObjectsSection.ObjectsSectionFromBuffer(DxfCodePairBufferReader buffer) in E:\IxMilia\Dxf\src\IxMilia.Dxf\Sections\DxfObjectsSection.cs:line 43
       at IxMilia.Dxf.Sections.DxfSection.FromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version) in E:\IxMilia\Dxf\src\IxMilia.Dxf\Sections\DxfSection.cs:line 70
       at IxMilia.Dxf.DxfFile.LoadFromReader(IDxfCodePairReader reader) in E:\IxMilia\Dxf\src\IxMilia.Dxf\DxfFile.cs:line 212
       at IxMilia.Dxf.DxfFile.Load(Stream stream) in E:\IxMilia\Dxf\src\IxMilia.Dxf\DxfFile.cs:line 144
       at FloorFlood.---.OpenDxFiles(IEnumerable`1 filePaths)

Lines 3399 to 3419 of DXF file

102
VTR_0.000_0.000_1.000_1.000_GRIDDISPLAY
 70
     3
102
VTR_0.000_0.000_1.000_1.000_GRIDMAJOR
 70
     5
102
VTR_0.000_0.000_1.000_1.000_DEFAULTLIGHTING
280
     1
102
VTR_0.000_0.000_1.000_1.000_DEFAULTLIGHTINGTYPE
 70
     1
102
VTR_0.000_0.000_1.000_1.000_BRIGHTNESS
141
0.0
102
VTR_0.000_0.000_1.000_1.000_CONTRAST
142
0.0
  0

Problem with empty $FINGERPRINTGUID

We have a .CDX file with the following FINGERPRINTGUID section:

"$FINGERPRINTGUID
2

9"

Because no actual GUID is specified in-between, the framework attempts to read an empty string as a GUID. Here is the full stack trace:

at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result) in f:\dd\ndp\clr\src\BCL\system\guid.cs:line 462
at System.Guid.Parse(String input) in f:\dd\ndp\clr\src\BCL\system\guid.cs:line 262
at IxMilia.Dxf.DxfHeader.GuidString(String s) in D:\IxMilia\Dxf\src\IxMilia.Dxf\Sections\DxfHeader.cs:line 87
at IxMilia.Dxf.DxfHeader.SetHeaderVariable(String keyName, DxfCodePair pair) in D:\IxMilia\Dxf\src\IxMilia.Dxf\Sections\Generated\DxfHeaderGenerated.cs:line 4562
at IxMilia.Dxf.Sections.DxfHeaderSection.HeaderSectionFromBuffer(DxfCodePairBufferReader buffer) in D:\IxMilia\Dxf\src\IxMilia.Dxf\Sections\DxfHeaderSection.cs:line 437
at IxMilia.Dxf.Sections.DxfSection.FromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version) in D:\IxMilia\Dxf\src\IxMilia.Dxf\Sections\DxfSection.cs:line 71
at IxMilia.Dxf.DxfFile.LoadFromReader(IDxfCodePairReader reader) in D:\IxMilia\Dxf\src\IxMilia.Dxf\DxfFile.cs:line 257
at IxMilia.Dxf.DxfFile.Load(Stream stream) in D:\IxMilia\Dxf\src\IxMilia.Dxf\DxfFile.cs:line 188

The file can be opened just fine by regular DXF readers.
Would there be any chance this field could get ignored in this situation?

UPDATE:
I pulled the sources locally, and indeed the issue is that the static method DxfHeader.GuidString attempts convert an empty string to a Guid, resulting in an error. If performing a check for NullOrWhitespace before propagating the Guid conversion, and returning an empty Guid otherwise, it seems to work just fine.

Include list of control point weights for splines

The weight property of the DxfSpline class only includes one weight.

However, when working with weighted splines one weight is required per control point as those weights relate to the base function for the control point. Therefore I would suggest replaceing the property Weight with a list of weights or a list of "1.0" entries matching with the number of control points if the number of weights does not match.

Dxf entities mismatch

Hi
First thanks a lot for you great work on this library.
I tried to import a DXF file in attach. But after imported, the entities are mismatch with the entities in DXF file.
I tried to view in LibreCAD. It works well.
Thanks for you review.
presidio_2.zip

DxfPolyline causes crashes in viewer applications

Whenever a DXF file contains a DxfPolyline our viewing software crashes. We have tried it with Autocad 2015 and Autodesk DWG TrueView 2018. We have also tried setting Is3DPolyline to true.
How to reproduce:

var dxfFile = new DxfFile();
dxfFile.Header.SetDefaults();

var vertices = new List();
vertices.Add(new DxfVertex(new DxfPoint(0, 0, 0)));
vertices.Add(new DxfVertex(new DxfPoint(1, 0, 0)));
dxfFile.Entities.Add(new DxfPolyline(vertices));

using (var fs = new FileStream("c:/tmp/file.dxf", FileMode.Create))
{
dxfFile.Save(fs);
}

Create Dxf files with R12

How can I create Dxf files with version R12?
When I set the version like below, no other Dxf Viewer can open the file.

DxfFile oDxfFile = new DxfFile();
oDxfFile.Header.Version = DxfAcadVersion.R12;
DxfLine oLine = new DxfLine();
oLine.P1.X = X1;
oLine.P1.Y = Y1;
oLine.P2.X = X2;
oLine.P2.Y = Y2;
oDxfFile.Entities.Add(oLine);
...
...

Can´t open files from server with readonly permission

As the title says, I encountered the problem that I can´t open DXF-Files from a server where I only have permission to read.

I open it as its said in the description
using (FileStream fs = new FileStream(path, FileMode.Open)) { dxf = DxfFile.Load(fs); }

The Exception that I get from it says that the access got denied.
Is it possible to do something against it without changing permission, or does the library need to be able to do writing?

Polylines in blocks are not parsed correctly

The polylines in the block in the attached file are not parsed correctly. The block "Block02" contains 1 polyline, with 4 vertices. See test-case: test4.zip

The file was generated with Rhinoceros 3d in an Autocad 2004 format. Similar effects were to be seen with different export versions, and files generated with Adobe Illustrator.

Reproducing can be done using the following code:

        using (var fs = new FileStream("data/test4.dxf", FileMode.Open))
        {
            var dxfFile = DxfFile.Load(fs);
            var blocks = dxfFile.Blocks;
            var exampleBlock = blocks.Where(blk => blk.Name == "Block02").First();
            foreach (var item in exampleBlock.Entities)
            {
                Console.WriteLine(item.EntityType);
            }
            var polyline = (DxfPolyline)exampleBlock.Entities.First();

            Console.WriteLine("Polyline has {0} vertices", polyline.Vertices.Count);
        }
        Console.ReadLine();

Will give the following output:

Polyline
Vertex
Vertex
Vertex
Vertex
Seqend
Polyline has 0 vertices

Where of course 1 Polyline with 4 vertices is expected (without vertices as seperate entities, or seperate Seqend entities)

Is Polyline containing Arcs supported?

I have a DXF file with Polyline containing Line and Arc segments. When I parse Polyline, all I see is Vertices. How can I reconstruct the original polyline? In other words, how do I get properties of such an Arc, like center, radius, from/to angle, when all I have is a Vertex?

Looking for Arc, I have found this TODO comment in the source. Does it mean Polyline with Arcs is not supported yet?
https://github.com/IxMilia/Dxf/blob/821416ea712a8acad118ac01a9a3440bba94eb12/src/IxMilia.Dxf/Entities/DxfPolyline.cs#L165

Error while load dxf:“The specified conversion is invalid”

I install package from nuget.Everything is ok.
I just load dxf like this:
DxfFile dxfFile;
using (FileStream fs = new FileStream(@"E:\testifcdata\autocad_2007.dxf", FileMode.Open))
{
dxfFile = DxfFile.Load(fs);
}
I got an error:“The specified conversion is invalid”
something was wrong?

can't write file

I have been trying to simply open a file and rewrite it with no success. The file reads fine and i can view it in my viewer however, when it comes to writing it back autocad shows a blank model page but I can see the content in the layout page.

Here is the code i am using and the file I am testing.
testDXF.zip

                        DxfFile dxfFileReader;
                        using (FileStream fs = new FileStream(inputFile, FileMode.Open))
                        {
                            dxfFileReader = DxfFile.Load(fs);
                        }

                        DxfFile dxfFileWriter = new DxfFile();

                        foreach (DxfEntity entity in dxfFileReader.Entities)
                        {
                                dxfFileWriter.Entities.Add(entity);
                        }

                        dxfFileWriter.Header.SetDefaults();
                        dxfFileWriter.ViewPorts.Clear();
                        using (FileStream fs = new FileStream(output, FileMode.Create))
                        {
                            dxfFileWriter.Save(fs);
                        }

How to deal with Units?

I realized, that dxf files were unitless (once upon a time) and units were something the drawing application would add on top. Furthermore, I could not find version-independent (and human-readable) instructions how to deal with units in DXF files. DXF versions aside, this packages provides a great abstraction level and I was able to find several properties related to units. Problem is, I'm still not sure if my understanding of those properties makes sense. Please confirm or correct me, if I'm wrong.

Preface: Units
There are distance units (meters, millimeters, feet, inch, etc.) and angular units (rad, degree, etc.).
The metric distance system is unique, while the imperial system is not. There are (too) many definitions of a feet, in particular I have to deal with "international feet" (common) and "US survey feet" (still in use by many surveyors).
Additionally, applications may round numbers (e.g. 3 decimal places) to improve readability - lets skip this.

Reading Units from a DXF File
When reading values from a DXF file, you want to convert "their" units to your internal unit system, whatever that may be. Suppose I want all distance values in meters, then the following method would provide the conversion factor. Same could be done for angles.

static double GetDistanceConversionFactor(DxfHeader dxfHeader)
{
    switch (dxfHeader.DefaultDrawingUnits)
    {
        case DxfUnits.Unitless: // assume meters
        case DxfUnits.Meters:
            return 1.0;
        case DxfUnits.Millimeters:
            return 0.001;
        case DxfUnits.Feet:
            return 0.3048; // only valid for international feet
        case DxfUnits.Inches:
            return 0.3048 / 12; // only valid for international feet
        default:
            throw new NotSupportedException("DefaultDrawingUnits=" + dxfHeader.DefaultDrawingUnits);
    }
}

The DXF standard does not provide a way to distinguish international feet and US survey feet. While there is a property ´DxfHeader.DrawingUnits´ which distinguishes "metric" and "english", I don't know what this is good for. I think, I have to ask the user for his preferred system in case of feet/inch.

Writing Values+Unit to DXF
Essentially, this is the opposite direction - convert all values to the target unit before creating the entities. Additionally, set DxfHeader.DefaultDrawingUnits to that unit.

DxfFile dxfFile = new DxfFile();
dxfFile.Header.DefaultDrawingUnits = DxfUnits.Feet;
dxfFile.Header.AngleUnitFormat = DxfAngleFormat.Radians;
dxfFile.Entities.Add( ... ) // use feet/rad here
dxfFile.Save(...);

Anything else, I have to do before saving? Maybe some property to complement the units stuff?

If my understanding of units in DXF files and your library is correct, feel free to reuse this for the main page or a wiki - so others can benefit.

Failed to read old DXF file

I just upgraded my NuGet package to 0.3.1 and now all files fail with the same exception. When debugging, I get about 10 assertion errors before... I'm unable to track it down. Exception stacktrace, debug trace, and example file follow.

IxMilia.Dxf.DxfReadException: Unexpected code pair group text
at IxMilia.Dxf.DxfCodePairGroup.FromBuffer(DxfCodePairBufferReader buffer, String groupName) in DxfCodePairGroup.cs: line 86
at IxMilia.Dxf.Objects.DxfObject.TrySetExtensionData(DxfCodePair pair, DxfCodePairBufferReader buffer) in DxfObject.cs: line 136
at IxMilia.Dxf.Objects.DxfXRecordObject.PopulateFromBuffer(DxfCodePairBufferReader buffer) in DxfXRecordObject.cs: line 30
at IxMilia.Dxf.Objects.DxfObject.FromBuffer(DxfCodePairBufferReader buffer) in DxfObjectGenerated.cs: line 314
at IxMilia.Dxf.Sections.DxfObjectsSection.ObjectsSectionFromBuffer(DxfCodePairBufferReader buffer) in DxfObjectsSection.cs: line 43
at IxMilia.Dxf.Sections.DxfSection.FromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version) in DxfSection.cs: line 73
at IxMilia.Dxf.DxfFile.LoadFromReader(IDxfCodePairReader reader) in DxfFile.cs: line 212
at IxMilia.Dxf.DxfFile.Load(Stream stream) in DxfFile.cs: line 149
at IxMilia.Dxf.Test.UnitTest1.Load(String filename) in UnitTest1.cs: line 31

Debug Trace:
Fail:
Fail: Unexpected end of section/file while parsing group.
Fail:
Fail: Unexpected end of section/file while parsing group.
Fail:
Fail: Unexpected end of section/file while parsing group.
Fail:
Fail:
Fail:
Fail:

This is a dxf file (not supported by github):
Clearance.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.