How to import a file, perform XOR on two layers and write back?

The XOR output layer will be one of the input layer. Thanks!

Comments

  • DRC script?

    source("your_input.gds")
    target("your_output.gds")
    
    # A = 1/0, B = 2/0 (example)
    a = input(1, 0)
    b = input(2, 0)
    
    # run XOR and output to 2/0
    x = a ^ b
    x.output(2, 0)
    
    # copy A to output
    a.output(1, 0)
    
  • Python, THANKS!
  • Like this?

    ly = pya.Layout()
    ly.read("input.gds")
    
    l1 = ly.layer(1, 0)
    l2 = ly.layer(2, 0)
    
    r1 = pya.Region(ly.top_cell().begin_shapes_rec(l1))
    r2 = pya.Region(ly.top_cell().begin_shapes_rec(l2))
    
    rxor = r1 ^ r2
    
    ly.clear_layer(l1)
    ly.top_cell().shapes(l1).insert(rxor)
    
    ly.write("output.gds")
    
  • Thanks, Matthias! I haven't tried yet but I believe it will work.
    I suggest you add some overview page with block diagram quickly describing each class with the connection between these classes. There are users like me who may not be ready to read through everything but just to quickly start with something. I searched in the documentation before asking but there is no easy way to quickly find that it is the Region class which will work for me. Now I found it and see the example code. I think that will save you a lot of time answering those elementary questions here. I am not that lazy, but without any general direction, I may give up after searching for a while because I have no idea how far I am to the destination. Just my two cents. Or maybe you already have that in the documentation. If so please redirect me to that page. Thanks!
  • Also, like for this XOR operation. I tried to search "XOR", "boolean" etc. I didn't find a page describing boolean operations and what class can be used as input.

  • edited September 2019

    Hi, Matthias. I tried the code. It works. Thanks.

Sign In or Register to comment.