Comments (7)
My collegue opened it in autocad and said it didn't work (and went home) - will add details tomorrow.
from dxf.
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.
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.
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.
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.
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.
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)
- Double Bug in MText rotation HOT 11
- Code 46 not readed from MTEXT HOT 9
- More indexes in code 1, 40 and 290 HOT 3
- How to create a zoom-extents ViewPort?
- Add Aligned Dimension with text above the dimension line and how to increase text size? HOT 1
- spline closed attribute error HOT 3
- How to specify a font for Text? HOT 2
- SPATIAL_FILTER code 40 issue HOT 1
- Ellipse uses wrong extents calculation HOT 1
- From Spline to Dxf HOT 2
- MTEXT AutoCAD 2018 Embedded Object (code 101) issue
- Opening file error "Not a valid DXF file header: `?0`" HOT 9
- How to calculate spline length? HOT 2
- How to get an edge/block's connected units (up & downstream) HOT 1
- How to explicitly set DXF color to black? HOT 1
- Unsupported code pair of dxf is swallowed HOT 2
- load the library from IronPython HOT 2
- DxfEllipse - thickness missing HOT 6
- Mirrored coordinates of some entries. HOT 3
- Support for MLeader HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dxf.