Finding the size of a DXF file using EZDXF Python

The system variables EXTMIN & EXTMAX store the lower-left & upper-right corners of the smallest rectangular frame which encloses all geometry in the drawing or in your case, DXF.

The values of these system variables are 3D points expressed relative to the World Coordinate System (WCS) of the drawing. The coordinate values of the points will be expressed in the units of the DXF (e.g. as given by the INSUNITS system variable), or may be unitless.

You can use the difference between the X & Y coordinate values of the points given by the EXTMAX & EXTMIN system variables respectively to obtain the dimensions (and hence aspect ratio) of the DXF, enabling you to create an image scaled to the same aspect ratio.


LIMMIN & LIMMAX also store 3D WCS points corresponding to the lower-left & upper-right corners of a rectangular area, however, this area is merely a user-imposed restriction on the available drawing area when new objects are created after limit checking has been enabled (LIMCHECK = 1).

Whilst the LIMMIN & LIMMAX system variables theoretically provide an upper-bound on the dimensions of the bounding box surrounding all geometry in the DXF, this is an unreliable measure, as objects can be created with limit checking disabled and such objects will not be removed when limit checking is enabled.


As addition to the answer of Lee Mac, if you create or modify a DXF drawing by ezdxf:

Header vars EXTMAX and EXTMIN are not maintained or updated by ezdxf.

The extents of DXF entities, blocks or model space has to be calculated by application, therefore the application has to render the entities, which is not a problem for CAD applications, but ezdxf is not a CAD application nor has a rendering engine, and the extends of DXF entities are often not defined by the DXF Reference, problematic entities are:

  • Text and MText depends on font rendering and font availability, which differs from application to application and computer to computer.

  • Splines by fit points, the algorithm AutoCAD calculates control points from fit points is not know, it is NOT the often on the internet documented "Global Interpolation"

  • Geometry of embedded ACIS data like 3DSOLID, BODY, REGION or SURFACE is not available for ezdxf

Calculation of extents by ezdxf would often be wrong or just guessing and is therefore not implemented, maybe i will add someday an add-on for approximated extents, but this is not very likely, because it is much work for entities like INSERT (with nested INSERT), HATCH (complex boundary paths and islands) or MTEXT (complex font rendering), with only small benefits if you can't rely on it. I am not thrilled to sacrifice my free time for this.

FYI because you are using Python2: Python 2 support of ezdxf will be removed with next release v0.9.0

Update 2021-01-14:

The next release v0.16 of ezdxf has a bbox module to calculate the extents of DXF entities and whole layouts. The limitations mentioned above are still valid, therefore the results for some entities are not 100% accurate. All calculations are done in Python. So don't expect quick results when working with a lot of objects.

Tags:

Python

Dxf