Adjust Cell Origin using the Python API

How can I adjust the cell origin using the Python API? I couldn't find any method in the Cell class documentation taking care of this.
In the GUI, it is done using Edit/Cell/Adjust Origin (see the screenshot below):

Comments

  • Hello Rima,
    I use the following procedure inside Klayout:

    import pya    
    layout = pya.Application.instance().main_window().current_view().active_cellview().layout()
    
    def adjustOrigin(layoutB,topcell):
              bbox= topcell.bbox()
              trans = pya.Trans.new(-bbox.center())  # center point
            #  trans = db.Trans(db.Point((-bbox.left), (-bbox.bottom))) #Lower Left Corner
              for inst in layoutB.top_cell().each_inst():
                  layoutB.top_cell().transform(inst,trans)
              for li in layoutB.layer_indices():
                for shape in layoutB.top_cell().each_shape(li):
                  layoutB.top_cell().shapes(li).transform(shape,trans)
    
              layoutB.update()
              return(layoutB)
    
    layout = adjustOrigin(layout,layout.top_cell())
    
  • edited October 2021

    @andyL Thanks for sharing your code

    Since 0.26.7, KLayout has a method which should simplify that code:

    layoutB.top_cell().transform(trans)
    

    should do the job of the instance and shape loops.

    Matthias

  • Great! Thank you very much for your answers!

Sign In or Register to comment.