-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunti.py
31 lines (22 loc) · 833 Bytes
/
unti.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import ezdxf
from shapely.geometry import Polygon
from shapely.ops import unary_union
def dxf_to_polygon(dxf_path):
doc = ezdxf.readfile(dxf_path)
msp = doc.modelspace()
polygons = []
for entity in msp.query("LWPOLYLINE"):
points = [tuple(p[:2]) for p in entity]
polygons.append(Polygon(points))
return unary_union(polygons)
def save_polygon_to_dxf(polygon, dxf_path):
doc = ezdxf.new(dxfversion="R2010")
msp = doc.modelspace()
points = list(polygon.exterior.coords)
msp.add_lwpolyline(points, close=True)
doc.saveas(dxf_path)
def booll():
polygon1 = dxf_to_polygon("docouter.dxf")
polygon2 = dxf_to_polygon("docinter.dxf")
result_polygon = polygon1.difference(polygon2)
save_polygon_to_dxf(result_polygon, "result.dxf")