Replies: 3 comments 4 replies
-
I think the advantage that the drawing frontend has rather than working with the dxf entities directly is that it takes this long list of complex entity types and converts them to and small number of simple primitive types, then passes those primitives to the backend. This functionality would be useful if it was available in a stand-alone form not requiring a frontend object to be created. In most cases at least, it should be possible to implement some kind of There would obviously be some information loss in this conversion (such as HATCH becoming just a collection of Path primitives without the semantic information to know which are holes etc), but the conversion is always going to be lossy so it's a choice about which information is useful to keep most of the time. I think keeping just the geometry makes sense for most use cases but I'm not sure. Then if you have an insert entity or something which contains LINE, POLYLINE, LWPOLYLINE entities etc, and you want all the line segments to get my_insert = ...
my_lines = [primitive for primitive in my_insert.primitives() if isinstance(primitive, LinePrimitive)] you could provide standalone functions like bb = bounding_box(primitive for insert in layout.query('INSERT') for primitive in insert.primitives()) This might be more usable than providing only methods for calculating bounding boxes (although helper This is all just a suggestion, there are probably lots of ways to achieve a similar result. I have seen projects often use ezdxf for these kinds of things but always do a custom conversion from the dxf entities that they are interested in and extracting information about a subset of those entities. If ezdxf offered a way to handle all the complexity of the difference between LWPOLYLINE and POLYLINE for example then these projects would be more robust, handle more entity types and be simpler to maintain (as the complexity is maintained in ezdxf). Here is one random example I picked that uses ezdxf. This type of processing would benefit massively from this kind of api being offered directly from ezdxf. |
Beta Was this translation helpful? Give feedback.
-
I think we mean the same thing, but I'm not 100% sure. In the last paragraphs of my post I came to the conclusion that writing a non-graphical backend for the drawing add-on is maybe not the right way, but I didn't show what I thought of instead.
Suggestions for function and module names are welcome:
|
Beta Was this translation helpful? Give feedback.
-
First bounding boxes calculated by ezdxf, and as I expected without matplotlib support the bounding boxes for text are much too wide (monospace-font calculation), but the rest is not bad: |
Beta Was this translation helpful? Give feedback.
-
The first idea is to use a non-graphical drawing backend to simplify entities
for the estimation of bounding boxes and layout extends.
The result of such a simplification is a collection of construction tools:
Path()
entities for linear entities and text entitiesMeshBuilder()
for all face based 2D/3D entities.Bounding Box detection for
Path()
byflattening()
is fast, if the C-extensionis available. Bounding box for
MeshBuilder()
is easy.Linear entities as Path()
Text entities as a Path() rectangle
Using mono-spaced text width calculation:
I will not invest much time into bounding box detection for text entities, it
will never be perfect - so simple and easy should be sufficient.
3D entities as MeshBuilder()
MeshBuilder()
fromTraceBuilder()
Collection of construction tools
Ignored entities
which just raises the complexity
This structure raises the question, if the implementation as a drawing backend
is a good idea?
This representation could also represent 3D text, which is not supported by the
drawing front end. Property resolving is not required. The
matplotlib
libraryis not required, therefore it could be added as a core tool.
Beta Was this translation helpful? Give feedback.
All reactions