It looks like you're new here. If you want to get involved, click one of these buttons!
I'm a new beginner in Klayout pymacro.
I'd like to transform the gds to center(0,0). I used to execute this function in GUI, and recently I try to execute by pymacro, but I have no idea why the results are different between these 2 approaches.
And the result by GUI is as my expected, that the gds is completed shifted to the center (0,0).
execute in pymacro: I refer to andyL's code in the discussion "Adjust Cell Origin using the Python API". (Many thanks for andyL)
Please check the following code:
import pya layout_file = "/.../layout_path/input.gds" output_file = "/.../layout_path/input_shift.gds" layout = pya.Layout.new() layout.read(layout_file) def adjustOrigin(layoutB,topcell): bbox= topcell.bbox() trans = pya.Trans.new(-bbox.center()) # center point 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()) layout.write(output_file)
I checked the new output_file from pymacro, and it did transform but the final bbox/layout placements are not as same as the result by GUI.
It's just my guess that the code would shift the layout in sub-cell coordinate due to the instance for loop.
I'd like to ask which part should I modify this code to get the same result as GUI...
(The Klayout version is 0.25)
Thank you so much!