I am trying to get the shape's dimensions, from dxf files. I tried looking into dxfgrabber and ezdxf libraries, I took the lowest and highest points to get the dimensions, but the result was wrong. Using dxfgrabber:
import dxfgrabber
import numpy as np
import sys
dxf = dxfgrabber.readfile(sys.argv[1])
shapes = dxf.entities.get_entities()
minX, maxX, minY, maxY = 999999,0,999999,0
for shape in shapes:
print('dxftype', shape.dxftype)
if shape.dxftype == 'LINE':
x, y = shape.start[0], shape.start[1]
if x < minX:
minX = x
if y < minY:
minY = y
if x >= maxX:
maxX = x
if y >= maxY:
maxY = y
x, y = shape.end[0], shape.end[1]
if x < minX:
minX = x
if y < minY:
minY = y
if x >= maxX:
maxX = x
if y >= maxY:
maxY = y
if shape.dxftype == 'ARC':
x, y = shape.center[0], shape.center[1]
if x < minX:
minX = x
if y < minY:
minY = y
if x >= maxX:
maxX = x
if y >= maxY:
maxY = y
print('minX', minX, 'minY', minY)
print('maxX', maxX, 'maxY', maxY)
print('x1', 0, 'y1', 0)
print('x2', maxX-minX, 'y2', maxY-minY)
Using ezdxf:
modelspace = dwg.modelspace()
for e in modelspace:
if e.dxftype() == 'LINE':
print("start point: ", e.dxf.start)
print("end point: ", e.dxf.end)
if e.dxftype() == 'ARC':
print("ARC on layer: ", e.dxf.layer)
print("center point ", e.dxf.center)
And manually took the minX minY maxX maxY.
Is there any way of calculating, or any existing libraries to get the dimensions ?