Home Forums Nazca Subtraction of two layers

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6637
    Andreas19
    Participant

    I would like to know if there is a way to directly subtract two layers because I could not figure it out yet.

    My case is the following:
    1) I generate a text with the following command: nd.text(text='Nazca-Design', height=50, layer='layer1', align='lc', box_layer='layer2').put(0, 0)
    2) I generate a rectangle shape with the command: nd.strt(length=500, width=400, layer='layer1').put(0,0)

    Now I would like to subtract from layer1 the layer2 (generated by the nd.text function).

    How can I do that?

    Thanks for your help!

    #6644
    Xaveer
    Moderator

    Dear Andreas,

    Nazca does not do boolean operations on cells or layers (yet). However boolean operations are possible on polygons. So something as shown below might do the trick for you.

    import nazca as nd
    
    def invert_text(cell, layer1, layer2):
        lay1 = []
        lay2 = []
        layer1 = nd.get_layer(layer1)
        layer2 = nd.get_layer(layer2)
        for pgon in cell.polygons:
            node, Poly = pgon
            x0, y0, _ = node.xya()
            if Poly.layer == layer1:
                lay1.append([[x + x0, y + y0] for x, y in Poly.points])
            elif Poly.layer == layer2:
                lay2.append([[x + x0, y + y0] for x, y in Poly.points])
        with nd.Cell("newtxt") as newtxt:
            inverse = nd.clipper.diff_polygons(lay2, lay1)
            for pol in inverse:
                nd.Polygon(points=pol, layer=layer2).put()
        return newtxt
    
    txt = nd.text(
        "Nazca-design", layer=1, box_layer=2, box_buf=20, align="cc"
    )
    inv = invert_text(txt, 1, 2)
    inv.put()
    
    nd.export_gds()
    

    Xaveer

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.