Skip to content
Snippets Groups Projects
analyze_dxf.py 1.71 KiB
Newer Older
#!/usr/bin/env python

import numpy as np
import ezdxf 
import random

# class dxf_editor:
#     def __init__(self,path,dxf_file):
#         self.dwg=ezdxf.readfile(path+dxf_file)


# def main():
#     path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
#     dxf_file='graph-silhouette.dxf'
#     edit=dxf_editor(path,dxf_file)
    

# if __name__ == '__main__':
#     main()

path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
dxf_file='graph-silhouette.dxf'
dwg=ezdxf.readfile(path+dxf_file)
# iterate over all entities in model space
def print_entity(e):
    print("LINE on layer: %s\n" % e.dxf.layer)
    print("start point:",e.dxf.start)
    print("end point:" , e.dxf.end)
    print("color:", e.dxf.color)
msp = dwg.modelspace()
# for e in msp:
#     if e.dxftype() == 'LINE':
#         print_entity(e)
i=0
# entity query for all LINE entities in model space
for e in msp.query('LINE[color==1]'):
    i+=1
    print_entity(e)

print(i)
# for z in msp.query('CIRCLE'):
#     print(z)
if not 'Isolation' in dwg.layers:
    dwg.layers.new(name='Isolation',dxfattribs={'linetype':'DASHED','color':2})

msp.add_line((0,0),(50,50),dxfattribs={'layer':'Isolation'})


def get_random_point():
    """Creates random x, y coordinates."""
    x = random.randint(-100, 100)
    y = random.randint(-100, 100)
    return x, y

# Create a block with the name 'FLAG'
flag = dwg.blocks.new(name='FLAG')

# Add DXF entities to the block 'FLAG'.
# The default base point (= insertion point) of the block is (0, 0).
# flag.add_polyline2d([(0, 0), (0, 5), (4, 3), (0, 3)])  # the flag as 2D polyline
flag.add_circle((0, 0), .4, dxfattribs={'color': 5})  # mark the base point with a circle

msp.add_blockref('FLAG',(40,40))



dwg.save()