Python script for extracting information from Autocad block attributes in multiple documents.
- Uses package EZDXF Sequence of operations
- FOR loop for checking unreadable files.
- Define the function for extracting information from cad files.
- Select Autocad block types and defines user-customised parameter for filtering between selected blocks.
- For each attribute extracts tag information and value in a Python dictionary.
- FOR loop to run the function on each file in the dxf file folder and return a Python dictionary.
- Checks number of files read and number of files saved for discrepancy.
- Pandas dataframe creation and excel export.
Reach me out for any help!
def extract_attr_dxf(cartella, nomefile):
doc = ezdxf.readfile("{}/{}".format(cartella, nomefile))
modelspace = doc.modelspace()
for n in modelspace:
if n.dxftype()=="INSERT":
articolo={}
if n.has_attrib("NUMEROARTICOLO")==True:
for attrib in n.attribs:
articolo[attrib.dxf.tag]=attrib.dxf.text
user_defined_dictionary[articolo["NUMEROARTICOLO"]]=articolo
for nomefile in os.listdir(cartella):
if nomefile.endswith(".dxf"):
extract_attr_dxf(cartella,nomefile)