Hot to export cell instance locaiton (coordinate)?

Hi sir ,
We have multi-top cell in GDSII , and need to export (to csv file) for what the cell name / coordinate in the first level in each top cells.
Can you let me know how to do that?

Comments

  • Hi!

    I think you should look make loop over each cell in layout (Layout.each_cell) and then use Cell.bbox. See documentation and similar code as example.

  • Hi Eugenne,
    Thanks for your answer , but I can't work it into my Klayout.
    I can using(make code) for DRC or Ruby just a little , but I can't code Python....
    do you have another ways to do that?

  • Hi!

    Ruby API is almost same as Python. Most importang thing is to know classes and their methods as well as context of their usage. Python example could serve this purpose :-) You could try to search this forum for Ruby examples of same API.

  • edited April 27

    @jiunnweiyeh
    Quick and Dirty use at your own risk


    from pya import * import numpy as np import csv # Enter your Python code here mw = pya.Application.instance().main_window() layout = pya.Application.instance().main_window().current_view().active_cellview().layout() topcell = pya.Application.instance().main_window().current_view().active_cellview().cell lv = pya.Application.instance().main_window().current_view() if lv == None: raise Exception("No view selected") if layout == None: raise Exception("No layout") cv = pya.Application.instance().main_window().current_view().active_cellview() dbu =layout.dbu cell = pya.Application.instance().main_window().current_view().active_cellview().cell if cell == None: raise Exception("No cell") cstr = "Cells Found" lv.transaction("Undo Selection") #Select All in Cells in Layout and Parse cellname and X,Y coords mw.menu().action("edit_menu.select_menu.select_all").trigger() coords = [] tc = "Topcell"+","+topcell.name sc = "SubCell"+","+ "X " +","+"Y" coords.append([tc]) coords.append([sc]) for sel in lv.each_object_selected(): if sel: if sel.is_cell_inst(): inst = sel.inst() name = inst.cell.name #get the X/Y coordinates of the Instance pX = inst.cplx_trans.disp.x * dbu pY = inst.cplx_trans.disp.y * dbu nxy = name+","+str(pX)+","+str(pY) coords.append([nxy]) #Print to the Console print (cstr.center(40, '#')) np = np.asarray(coords) print(np) print (cstr.center(40, '#')) csv.register_dialect('myDialect', delimiter = '|', quoting=csv.QUOTE_NONE, skipinitialspace=False) #Name this as you want and Export to a CSV file tcs = "E:\\Klayout\\CSV\\" + topcell.name + ".csv" with open(tcs, 'w', newline='') as f: writer = csv.writer(f, dialect='myDialect') for row in np: writer.writerow(row) f.close() #Unselects all Instances mw.menu().action("edit_menu.select_menu.unselect_all").trigger() lv.commit()
  • Hello,

    I use this one for my wafer maps and chip floorplans:

    module MyMacro
    
    
      app = RBA::Application.instance
      mw = app.main_window
      lv = mw.current_view
      cv = lv.active_cellview
    
      if lv == nil
    
        raise "No view selected"
    
      end # if
    
      if !cv.is_valid?
    
        raise "No cell or no layout found"
    
      end # if
    
      # Ask for the file name
    
      filename = RBA::FileDialog.get_save_file_name("Flat Dump", ".", "CSV files (*.csv);; All files (*)")
    
      if filename.has_value?
    
        File.open(filename.value, "w") do |file|
    
          file.puts("Instance,X-coord,Y-coord,Rotation")
    
            cv.cell.each_inst do |inst|
    
                    iindex = inst.cell_index
                    name = cv.layout.cell_name(iindex)
                    itrans = inst.trans.to_s.gsub(",", "\s").split("\s")
                    instrot = itrans[0]
                    instx = (itrans[1].to_i * cv.layout.dbu).round(6)
                    insty = (itrans[2].to_i * cv.layout.dbu).round(6)
    
                if inst.is_regular_array?
    
                    na = inst.na
                    nb = inst.nb
                    a = inst.a * cv.layout.dbu
                    b = inst.b * cv.layout.dbu
    
                    (0..(na-1)).each do |ia|
    
                      (0..(nb-1)).each do |ib|
    
                        instx2 = (instx + ia * a.x + ib * b.x).round(6)
                        insty2 = (insty + ia * a.y + ib * b.y).round(6)
    
                        file.puts("#{name},#{instx2},#{insty2},#{instrot}")
    
                      end # each
    
                    end # each
    
                else
    
                    file.puts("#{name},#{instx},#{insty},#{instrot}")
    
                end # if
    
            end # each_inst  
    
        end # File.open
    
      end # if
    
    
    end # MyMacro
    

    Cheers,

    Tomas

  • @tomas2004

    Excellent I tend to stick to Python

  • edited May 2

    Very good! Thanks for the code!

    Matthias

Sign In or Register to comment.