Git Product home page Git Product logo

Comments (7)

nzain avatar nzain commented on July 16, 2024

My collegue opened it in autocad and said it didn't work (and went home) - will add details tomorrow.

from dxf.

brettfo avatar brettfo commented on July 16, 2024

DxfPolyline wraps multiple DxfVertex entities, each of which can specify a layer, color, thickness, etc. so this line:

.Select(point => new DxfVertex(new DxfPoint(point.X, point.Y, 0)))

Should also set those to match that of the DxfPolyline.

This does bring up an interesting question on whether or not it's possible for a DxfPolyline to have vertices that live on a different layer; the spec doesn't mention anything about this, but it is valid to have a different color/thickness on each vertex, so at a minimum that'll have to be specified for each one.

I'm not sure what the issue could be with DxfLwPolyline, I'll have to dig into that one.

from dxf.

nzain avatar nzain commented on July 16, 2024

Okay, so the DXF API (not your library) itself is even more error prone than I expected. Users without strong DXF background (like me) will run into this and scratch heads.

The evil consumer of your library might expect, that some kind of automatic validation logic happens when the file is written, so that each entity validates its internal state and eventually fills missing fields or throws exceptions at the developer, who didn't know/care. Of course this is an endless route, especially because testing with one program (say AutoCad) tells little about other applications (say QCAD).

sigh

How do you evaluate the correctness of DXF file generation? My goal is to write code, using your library, that creates dxf files, that our customers can open with their favorite application. How can I do it right? How can I write highly compatible DXF code?

To make it more complicated, I don't have an AutoCad license (but my collegue does). Feel free to close this ticket.

from dxf.

brettfo avatar brettfo commented on July 16, 2024

I already attempt to normalize the DXF file on saving, but it looks like it's worth doing entity validation, too. When I originally started this project I wanted to allow the developer to explicitly control every aspect of DXF generation, but as time has gone on I've discovered how difficult it actually is to do the right thing and I've been taking more and more control away to ensure that everything is correct, and this is a perfect example of where I should go further. As soon as I get some free time I'll add DxfPolyline/DxfVertex normalization, but I'll have to spend some time thinking about how to handle color and thickness, since it is possible for those to differ.

You're correct in that the DXF spec is very loose and my testing methods are essentially what you've described; save a file and try to open it in QCAD or in the Teigha Viewer by the Open Design Alliance. I do have some tests that directly invoke the Teigha Converter and some that launch AutoCAD to do some simple verification, but my trial license has expired.

from dxf.

nzain avatar nzain commented on July 16, 2024

For your interest, I tried several minimalistic ways to store a DxfLwPolyline, but with no success. It never shows in QCad.

I was able to fix my layer/color issue for DxfPolyline: as you suggested, by explicitely specifying the polyline layer & DxfColor.ByEntity for each vertex.

However, I was neither able to set DxfLineWeight.Standard for a polyline nor for a layer. You said, each vertex has a thickness too. There is StartingWidth and EndingWidth on DxfVertex, but that's a double. The polyline additionally has Thickness, DefaultStartingWidth, DefaultEndingWidth, and LineweightEnumValue. I've set all those double values to 0.0001 for vertices and the polyline - no effect.

How would I change the line thickness, just QCad's "standard" for the whole line? :-)

from dxf.

nzain avatar nzain commented on July 16, 2024

Surprise! I solved all my problems by

dxfFile.Header.Version = DxfAcadVersion.R2013;

It seems the default version DxfAcadVersion.R12 does not support DxfLwPolyline and dxfFile.Header.DefaultDrawingUnits. Now I successfully create lw-polylines via

private static DxfLwPolyline ToLwPolyline(Point2D[] points, string layerName = "0")
{
    int n = points.Length;
    DxfLwPolylineVertex[] vertices = new DxfLwPolylineVertex[n + 1];
    for (int i = 0; i <= n; i++)
    {
        Point2D p = points[i % n]; // repeat points[0] to close the line
        vertices[i] = new DxfLwPolylineVertex
        {
            Bulge = 0,
            X = p.X,
            Y = p.Y
        };
    }
    return new DxfLwPolyline(vertices)
    {
        Layer = layerName,
        Color = DxfColor.ByLayer,
        IsClosed = true,
        LineweightEnumValue = DxfLineWeight.ByLayer.Value, // almost works, QCAD says "by block"
    };
}

Now QCAD shows exactly, what I want to produce, except for the polyline's lineweight, which shows from block instead of from layer, although I specified DxfLineWeight.ByLayer.

from dxf.

nzain avatar nzain commented on July 16, 2024

Thinking some more about my initial problem - it would be good to see exceptions, when certain elements are not supported by the specified AcadVersion.

from dxf.

Related Issues (20)

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.