How to copy the sub-cell from an old gds and save it into a new gds?

edited May 11 in Python scripting

Hi Sirs,

I'm going to extract some specify sub-cells from a gds and collect them into a new gds, and I always use pure GUI to complete this kind job.
I would wanna know how can I finish this job in a pymacro field? (I've tried to look for any discussion about it, but failed...)

For example, there is an existing gds (Main.gds) whose top-cell is 'TOP' with 3 sub-cells named 'sub_cell1', 'sub_cell2' and 'sub_cell3'.
I would only want to collect 'sub_cell1' and 'sub_cell3' and relocate these cells from original point with x-step 0.5 um, and then save them into a new gds(New.gds). (It would better if these sub-cells are still under 'TOP' hierarchy)

How can I get this work with a pymacro?
(My klayout version is 0.25)

Thank you so much!
Ming

Comments

  • @Ming Why such an old version? I strongly recommend switching to a new one.

    I understand your question that you actually want to modify the instances - i.e. to move it someplace else, right?

    The code is roughly like that:

    ly = pya.CellView.active().layout()
    for instance ly.top_cell().each_inst():
      if instance.cell.name == "sub_cell1":
        # modify the displacement vector of the instance
        dtrans = instance.dtrans
        dtrans.disp = pya.DVector(100.0, 50.0)   # move to 100,50 (µm)
        instance.dtrans = dtrans
      # other cells ...
    

    Matthias

Sign In or Register to comment.