subtracting two layers in KLayout using python.

edited March 7 in General

This is the code which shows three hexagon with the same center but different size. I want to subtract layer 1 from layer two. so that its look like u have hollow hexagon, that have the smaller hexagon in it. can anyone help me with this. thank you

import pya
import math

layout = pya.Layout()
top_cell = layout.create_cell("TOP")

l1 = layout.layer(1, 0)
l2 = layout.layer(2, 0)
l3 = layout.layer(3, 0)

hex_size = 1000 # microns sides of the hexagon

hollow_size = 500 #

cts_size=250

x0=0
y0=0

def create_hexagon(center, size):
angle_deg = 60
angle_rad = angle_deg * math.pi / 180
points = []
for i in range(6):
x = center.x + size * math.cos(i * angle_rad)
y = center.y + size * math.sin(i * angle_rad)
points.append(pya.Point(x, y))
return pya.Polygon(points)

for i in range(1):
x=0
y=0
center = pya.Point(x, y)
hexagon1 = create_hexagon(center, hex_size)
top_cell.shapes(l1).insert(hexagon1)
hexagon2 = create_hexagon(center, hollow_size)
top_cell.shapes(l2).insert(hexagon2)
hexagon3 = create_hexagon(center,cts_size)
top_cell.shapes(l3).insert(hexagon3)

layout.write("hexagons_7.gds")