Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

want to generate script to open up gds file, show as new top, and run drcs

new to klayout scripting
I am not finding much on how to generate a script to open klayout and a gds file from a command line and run a script
the script will need to change the new top to a certain file, it will be known before running the script and can be updated or passed into the script before running. I am not too concerned about that, but do not know how to "show the new top"
once the new top if set, I need to run drcs.
then exit klayout or keep it open, do not care at this point


  • Hi John,

    how about running the DRC in a separate step, i.e.

    klayout -b -r your.drc
    # or:
    strmrun -r your.drc

    And afterwards opening the layout plus the report:

    klayout your.gds -m your.lyrdb

    Here is a sample for "your.drc":

    report("My DRC", "your.lyrdb")
    l1 = input(1, 0)
    l1.width(0.5).output("Width < 0.5")

    If you don't want to put fixed paths in the scripts, use variables:

    klayout -b -r your.drc -rd input_file=your.gds -rd db_file=your.drc

    with this DRC script:

    report("My DRC", $db_file)
    l1 = input(1, 0)
    l1.width(0.5).output("Width < 0.5")


  • after much data manipulation on my end I have something I can go forward with. thanks. one thing is I am running this via windows and used c:\ when klayout expected c:/ forward slash like unix.

    what I think I will do is generate the bat file to run and open klayout -e gds file -r lydrc file and add a customized header for the drc like cat it on to define my source top cell and report file. ie I believe I will have to generate a specialized drc file for each gds file anyway.

    thanks and I am sure I will need more help in the future

  • edited November 2018


    KLayout also accepts backslashes for file paths, but when you enter them in a script, you have to be careful to use a double-backslash, as Ruby uses it as escape character in double-quoted strings.


    report("My DRC", "c:\\users\\matthias\\test.gds")

    On the command line (in -rd variable=c:\users\matthias\test.gds) you should be able to use backlash characters as usual.


  • ok, i will consider that. but i am good since it appears to work and do not want to muck anything up right now.

    But I am still having issues with top_cell, the drcs run on the cell I list as top_cell and gives results as expected but it reports to the output file the original top cell thus renders the file useless unless modified to the top cell I specify. ie if I open the gds file and go to step through drcs it resets to topcellklayoutchooses instead of the top cell I want mytopcell

    in lydrc file
    source ("Z:/1234.gds", "mytopcell")

    in output stored text file

    while running the script it keeps topcellklayoutchooses highlighted instead of changing the physical top cell.

    I can and will do so modify my output file to the mytopcell, but it would have been nice to find a way to physically change the top cell to mytopcell before running drcs.

  • Hi,

    you can chose among different options when you use the marker browser (that's the "context"). Push the "Configure" button to edit the options. I guess if you choose "current cell" it won't switch the cell.

    I agree that writing the original top cell into the .lyrdb file does not make a lot of sense. Maybe there are internal reasons for this. I'll need to check this. Thanks for giving that feedback.



  • the final intent is to create a batch job that will open up klayout, set the top cell, load and run drcs, save the drcs to a file all without human intervention. once i can get a program installed to run a windows bat file from linux i can do all the above without a human. I have manipulated the top cell stored in the file to the one i run the drcs on. i guess i was looking at a way for automation to physically set the top cell to the one i want and then run drcs. what i have not is not ideal but it works and i can live with it. i was hoping there was a way to change the top cell via automation. then take that file and parse out needed data and feed another program for its needed information.

  • Hi,

    I'm still unsure whether you need to window. So I'd still recommend batch mode (see my first reply).

    What's exactly the thing you want to give to your users? I window that pops up and shows the layout with the DRC results?


  • there are 2 things that is valuable to having the top cell the drcs are ran on in the drc results file, ie not the top cell klayout determines is the top cell. ie klayout determines the viable top cell as the last cell touched or manipulated in the gds file (I am guessing but I can only surmise) instead of the cell that contains the most hierarchy or even has children.

    1) a user can open the data and load the results without manually manipulating the drc results file, that is if they know why the results are not loading in the first place. I am no longer going to have the gds file stay open after the drc run. it is just an option if a user wants to open the gds file and load drcs to see the results of where cds are.
    2) I have code that is expecting this top cell to be the cell the drcs are ran on so I can parse out that data and extract out the cords based upon that cell.

    what I am stating I can not change my top cell to the top cell I want to run drcs on because that appears to not be an option via code, so I add my top cell in the call to the drc (because I see no other option to run drcs on the cell I want to get results for)

    this is what I am using in my lydrc file

    create test cases

    call in bat statment

    klayout -b -r your.drc -rd input_file=your.gds -rd db_file=your.drc

    with this DRC script:


    report("My DRC", $db_file)

    replace source with real source and top cell

    source("J:/xyz/jobno/gds-file", "fracturecell")

    stores text file in the standard output location

    replace report with real directory

    report("qorvocds.txt", "J:/xyz/DRCs_for_CD/jobno.txt")

  • Hi John,

    this is hard readable ... could you use Markdown please (put a triple backtick line before and after the code).



Sign In or Register to comment.