How to open each GDSII file and do something?

Hi Sir,
I have many GDSII file in folder D:\bumping.
as below , I want to check all the top_cells (that is mix 2 type of GDS , single top cell and multi top cell)
and do something check in each single GDSII file.
but look like I can't do that as below picture shown what the error message , do you have other idea for that?

main_window = RBA::Application::instance.main_window

filepath="D:\\bumping\\"
file_list =Array.new()
dir=Dir.open(filepath)
while name=dir.read
if name.downcase.match(".gds")  then
file_list << name
end
end
dir.close
layout = RBA::CellView::active.layout
run_process=1
file_list.sort.each do |current_gds_file_name|
cellview = main_window.create_layout(run_process.to_s, 1)
puts "It is reading ..... #{filepath}#{current_gds_file_name}"
cellview.read("#{filepath}#{current_gds_file_name}")
currentlayout = RBA::CellView::active.layout
topcells=currentlayout.top_cells
topnames =Array.new()
topcells.each do |xx|
topnames << xx.name
end
puts "****************************"
puts "it is GDSII filename : #{current_gds_file_name}"
puts "it is top cells : #{topnames}"
run_process+=1
end

#####################

Comments

  • Hi jiunnweiyeh

    CellView object cannot load files directly, use LayoutView load_layout() function instead.

    ** LayoutView can be created without the existance of mainwindow

    example as below:

    filePath     = "D:\\bumping\\"
    fileNameList = Dir.entries(filePath).map {|fname| fname.downcase[-3..-1] == "gds" ? fname : nil }.compact
    
    fileNameList.sort.each do |fileName|
        layoutView = RBA::LayoutView::new()
        cellView   = layoutView.cellview(layoutView.load_layout("#{filePath}#{fileName}"))
        topNames   = cellView.layout.top_cells.map {|cell| cell.name}
        puts "File Name : #{fileName}; Top Cells : #{topNames}"
    end
    
  • edited December 2023

    Hi @jiunnweiyeh,

    Here is another example of making the most of your original code.
    With the main window, all layouts will show up.
    If that is not required, RawrRanger's example is more lightweight and elegant, I think.

    # https://www.klayout.de/forum/discussion/2431/
    
    # [1] Collect the GDS2 files from the KLayout source.
    #     As of version 0.28.13,
    #       there are 48 *.gds files
    #       there are  2 *.gds.gz files
    filepath = ENV['HOME'] + "/GitWork/klayout/testdata/gds/"
    file_list = Array.new()
    dir=Dir.open(filepath)
    while name=dir.read
      if name.downcase.match(".gds") then
        file_list << name
      end
    end
    dir.close
    
    # [2] Examine the top cell(s) of each GDS2 file.
    #     Each layout will show up in the main window.
    main_window = RBA::Application::instance.main_window
    
    run_process = 1
    file_list.sort.each do |current_gds_file_name|
      gds = "#{filepath}#{current_gds_file_name}"
      puts "It is reading ..... #{gds}"
      cellview = main_window.load_layout(gds, 1)
      layout = cellview.layout
      topcells = layout.top_cells
      topnames = Array.new()
      topcells.each do |xx|
        topnames << xx.name
      end
    
      puts "****************************"
      puts "it is GDSII filename : #{current_gds_file_name}"
      puts "it is top cells : #{topnames}"
      run_process += 1
    end
    puts ""
    puts "Processed #{run_process} files"
    

    Outputs

    Running macro /home/sekigawa/.klayout/macros/Forom2431.rb
    It is reading ..... /home/sekigawa/GitWork/klayout/testdata/gds/alm.gds
    ****************************
    it is GDSII filename : alm.gds
    it is top cells : ["TOP"]
    It is reading ..... /home/sekigawa/GitWork/klayout/testdata/gds/alm_au.gds
    : 
    : 
    : 
    it is GDSII filename : t200.gds
    it is top cells : ["TOP"]
    It is reading ..... /home/sekigawa/GitWork/klayout/testdata/gds/t9.gds
    ****************************
    it is GDSII filename : t9.gds
    it is top cells : ["RINGO"]
    
    Processed 50 files
    

  • Hi All,
    Thanks very much for your help , I will try that code.

  • Hi All,
    Can I close the GDSII file after opened ?
    such as code below , (but it is not workable...)

    file_list.sort.each do |current_gds_file_name|
      gds = "#{filepath}#{current_gds_file_name}"
      puts "It is reading ..... #{gds}"
      cellview = main_window.load_layout(gds, 1)
      layout = cellview.layout
      topcells = layout.top_cells
      topnames = Array.new()
      topcells.each do |xx|
      topnames << xx.name
      end
    
      puts "****************************"
      puts "it is GDSII filename : #{current_gds_file_name}"
      puts "it is top cells : #{topnames}"
      run_process += 1
      cellview.close   ####I want to close the GDSII file .
    end
    
  • Hi,

    How about this?

    main_window = RBA::Application::instance.main_window
    
    close_one_by_one = true ### set "false" to finally close everything in one shot
    
    run_process = 1
    file_list.sort.each do |current_gds_file_name|
      gds = "#{filepath}#{current_gds_file_name}"
      puts "It is reading ..... #{gds}"
      cellview = main_window.load_layout(gds, 1)
      layout = cellview.layout
      topcells = layout.top_cells
      topnames = Array.new()
      topcells.each do |xx|
        topnames << xx.name
      end
    
      puts "****************************"
      puts "it is GDSII filename : #{current_gds_file_name}"
      puts "it is top cells : #{topnames}"
      run_process += 1
      if close_one_by_one then
        main_window.call_menu('cm_close')
      end
    end
    
    if not close_one_by_one then
      main_window.call_menu('cm_close_all')
    end
    
    puts ""
    puts "Processed #{run_process} files"
    
  • @sekigawa
    It is workable , Thanks. I will base on this code to building what mind.
    Thanks.

Sign In or Register to comment.