pythonautocaddxfezdxf

Using ezdxf to extract HATCH details from BLOCK REFERENCES in dxf files


I tried to extract the HATCH entities along with their pattern types which are inserted in drawings as BLOCK REFERENCES using INSERT tag. The dxf drawing is https://drive.google.com/open?id=1SnGDaIh8XiMe0QKAQy1RXzpT-rLNcLk7

I used the following code using updated package ezdxf-0.12 on python-3.6

import ezdxf
import argparse

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", required=True,
    help="path to input dxf file")
args = vars(ap.parse_args())
file = args["input"]    
doc = ezdxf.readfile(file)

msp = doc.modelspace()

for flag_ref in msp.query('INSERT'):
    for entity in flag_ref.virtual_entities():
        if entity.dxftype() == 'HATCH':

            print("HATCH", entity.dxf.pattern_name)

The code did not print HATCH entities having ANSI31 patterns. There are 2 of them in the dxf file, which can be viewed in Autocad (or even looked up using regular text editors). It may be noted that the HATCH entities having SOLID patterns in the given dxf file were printed as usual.

Is there any bug in the code or the package update?


Solution

  • The block references #385 and #38E of block "TC" have non uniform scaling (-1, 1, 1), which ezdxf ignores by default (mirroring has nearly the same complexity as non uniform scaling), you have to explicit activate non uniform scaling by virtual_entities(non_uniform_scaling=True). But non uniform scaling produces incorrect results for some entities - this is still an experimental feature. And there was also a bug in the HATCH entity which will be fixed with the next release v0.12.1 of ezdxf.