find the cellname list.

edited November 29 in KLayout Support

Hi All,
Do you have any way to output the name of top cells to scrent without Klayout user-interface (klayout can runing in the
background)?
In our team , we have some user didn't know how to using Klayout , who is not designer but he is an photo enginner .
so , I want to using a DOS command to link into Klayout command , just output what the top cellnames to screen for he/she preview.
Firstly , I make a icon that is a dos batch file , I want to click and drag the *.gds file into this icon to get the answer.
I also make a VBA in excel , to let the user to read the "GDS_filelog.txt" do I export.
The script in Klayout can been process.
But look like I can't using DOS command to run Klayout and get the answer .
Do you have any idea for that?
The key point will be that , our photo enginner is not the expert for Klayout
It is why I try to using DOS command to link they and this software.

DOS:
@FOR %%C IN (*.gds) DO C:\Users\%username%\AppData\Roaming\KLayout\klayout_app -r \bp-zk\OBU3\Mask\Sample\klayout\drc_118.lydrc %%C

Klayout srcipt: (drc_118.lydrc )

layoutfile = RBA::Application::instance.main_window.current_view.active_cellview.name
layoutLibrary = RBA::Application::instance.main_window.current_view.active_cellview.filename
currentfilepath=layoutLibrary.sub(layoutfile,"")
layoutView = RBA::Application::instance.main_window.current_view.active_cellview.layout
eachcells = layoutView.each_cell
username=ENV['USERNAME']
topcells = layoutView.top_cells
outputdata=Array.new()
topcells.each do |xx|
outputdata << xx.name
puts xx.name
end

log_filename="C:\\users\\#{username}\\Desktop\\GDS_filelog.txt"
aFile = File.new("#{log_filename}", "w+")
outputdata.each do |yy|
aFile.syswrite("#{yy}\n")
end
aFile.close

Comments

  • edited November 30

    Hi jiunnweiyeh,

    I'm not very much sure if my idea satisfies your requirements.
    However, my idea is to provide your photo engineers with a simple GUI tool using KLayout Python Module (https://www.klayout.org/klayout-pypi/).

    Assumptions and prerequisites:

    1. Your engineers work in the Windows environment (most likely Windows 11).
    2. You can set up the Python environment for your engineers. More precisely, you can:

      1) install the standard Python3
      2) add some core Python modules, including klayout and PyQt5 by:
      % python3 -m pip install kalyout
      % python3 -m pip install PyQt5

    Watch the attached demo video shot on Mac.
    I hope the function is straightforward and self-explanatory.
    If a design file (GDS or OASIS) has a single top cell, its name is printed in blue. If there is more than one, it is printed in red.


    I made two types (Type-A and Type-B) of the tool. Their behaviors are identical.
    Only the implementation approach differs. Refer to the "ReadMe.txt" file in the attached ZIP file.
    However, I prefer Type-B because I can split the GUI design work and coding.
    I have tested both types on Mac, Linux, and Windows 11.
    The images below are from Windows 11.


    The file export function is not provided for simplicity. But you can copy and paste the output like other ordinary GUI tools.

    Kazzz-S

  • Cont.

    I haven't tried your original batch file, but I often ask ChatGPT for help when encountering problems.
    The following is for your reference.

    Kazzz-S


    Chat with ChatGPT o1-preview:

    Question

    A batch file for Windows. Correct errors if any.
    
    @FOR %%C IN (*.gds) DO C:\Users\%username%\AppData\Roaming\KLayout\klayout_app -r \bp-zk\OBU3\Mask\Sample\klayout\drc_118.lydrc %%C
    

    Answer (Think for 34 seconds)

    The batch file provided has several potential issues that need correction to function properly.
    Here's the corrected version:

    @FOR %%C IN (*.gds) DO "C:\Program Files\KLayout\klayout.exe" -r "\\bp-zk\OBU3\Mask\Sample\klayout\drc_118.lydrc" "%%C"
    

    Corrections and Explanations:

    1. Incorrect Path to KLayout Executable:
    • Original: C:\Users\%username%\AppData\Roaming\KLayout\klayout_app
    • Issue: The path points to a directory, not the executable. Additionally, the executable is usually located in C:\Program Files\KLayout.
    • Correction: Use the full path to the executable and include the .exe extension:
      • "C:\Program Files\KLayout\klayout.exe"
    1. Incorrect Path to DRC File:
    • Original: \bp-zk\OBU3\Mask\Sample\klayout\drc_118.lydrc
    • Issue: A single backslash at the beginning denotes the root of the current drive, which might not be intended. If it's a network path, it should start with double backslashes.
    • Correction: Use double backslashes for a network path:
      • "\bp-zk\OBU3\Mask\Sample\klayout\drc_118.lydrc"
    1. Quoting Paths and Filenames:
    • Issue: Paths containing spaces or special characters should be enclosed in quotes to prevent errors.
    • Correction: Enclose all paths and filenames in double quotes:
      • "C:\Program Files\KLayout\klayout.exe"
      • "\bp-zk\OBU3\Mask\Sample\klayout\drc_118.lydrc"
      • "%%C"
    1. Using the Correct Variable Syntax in Batch Files:
    • Issue: The FOR loop variable %%C is correctly used for batch files.
    1. Optional - Using Environment Variables:
    • If you prefer using %USERNAME%, ensure the path is correct and points to the executable:
      • "C:\Users\%USERNAME%\AppData\Roaming\KLayout\klayout.exe"

    Final Corrected Batch File:

    @FOR %%C IN (*.gds) DO "C:\Program Files\KLayout\klayout.exe" -r "\\bp-zk\OBU3\Mask\Sample\klayout\drc_118.lydrc" "%%C"
    

    Note: Make sure that:

    • The paths used (klayout.exe and the DRC file) are accessible and correct.
    • You have the necessary permissions to execute files in these locations.
    • If the executable or DRC file is located elsewhere, adjust the paths accordingly.
  • edited December 2

    Cont.

    I have slightly improved Type-B to Type-B2.
    Now the results are exported to an Excel file, as shown below.

    To use F2631B2.py, you need to python3 -m pip install pandas openpyxl.

    Kazzz-S


    P.S.
    In a Windows environment, I recommend renaming the extension from .py to .pyw to associate these Qt-based Python script files with the Windowed tool (pythonw3.exe). This tool is a Python interpreter version designed not to display a console window.
    Also added Type-B3 with a different UI.

  • Hi sekigawa-san,
    @sekigawa
    Thanks a lot for your help , I will try the batch file you mention.
    What the issue in my side is that , our photo enginner didn't using another software to do the simple work,
    even that just click and select and didn't need he/her to make any cording.
    They also want to know the layer information /some special size/distance/density in some cell that have a key word.
    I can make a Klayout script to export what the information they needs as a GDS report base on our internal format.
    But , this script need running in Klayout.... we have to training they for basic operate in Klayout.
    Anyway , let me check your idea , Thanks.

Sign In or Register to comment.