Problems with Xsection

I've been using KLayout for years without a problem and XSection since 2018. This last week I've found that XSection no longer works for me.
I was running KLayout 0.26.12 (64 bit version) on Windows10 with a .lyp file customised for our CCD process. XSection version was 1.2 and that was fine until last week. We have a few XSection scripts which, according to the windows file properties, have not changed for a couple of years. Last week trying to run XSection suddenly gave this error message and a blank tab.

undefined method 'string to layerinfo' for # in C:/users/rbell/Documents/ccd_with _implants.xs:9

I've tried updating to KLayout 0.27.4 and this still fails but with a longer, and to me completely incomprehensible, error message. I've also updated XSection to 1.4 which didn't help either.
A colleague can run the same XSection script without errors using KLayout 0.25.3.
The issue persists for several .gds files and different .lyp files.
Rolling back KLayout to 0.26.12 did not solve the issue.
I tried a clean install on a different laptop and the problem remains the same.

Any advice welcome!




  • Hi Ray,

    I'm sorry, but this is impossible for me to debug with the information you give me.

    I'd need at least your .xs file or the beginning of it (at least until line 9 of ccd_with _implants.xs). And even if the error message isn't comprehensible to you, you can still paste it here. I may understand it.

    Files don't just get defunct - I'm sure someone has touched something. Maybe your .xs file is loading some layer properties which do no longer exist, maybe they are loaded from a network drive which is no longer mapped ... whatever. I cannot tell without details.

    As a general rule, if you write .xs files that require other resources, make sure these come from relative paths. Keep things inside a single folder and use a configuration management system such as git so your files don't magically get damaged.

    Finally, you can try resetting KLayout's configuration (rename c:\users\your_user_name\KLayout to something else). In c:\users\your_user_name you will also find a file called ".klayout-xsection". You can try removing this file as it holds the last used files. Maybe something is wrong with that one.


  • Thanks Matthias,
    You've given me a few things to check out there.
    Looking at my files I think the problem may have started when I was using KLayout in editor mode to do some boolean operations on a copy of a layout file to build up a crude height map. I was using 0.26.4 or so then , I see there is a new function in 0.27.4 , the 2.5D view which looks as though it may be better suited to my needs anyway but having broken XSection I want to get it fixed before experimenting further.

    I thought I might have found the problem in that I had been a bit careless with the new layers I generated from an xor of existing layers and some of the numbers matched layers used in the xs script. I tried fixing that by deleting these layers from the layout but it didn't solve the problem.

    Is a screenshot of the error message from KLayout 0.27.4. Can you see that and does it help?

    And here are the first 20 or so lines of the ccd_with _implants.xs script.

    __## Standard CCD process flow: 85/85 dielectric, no anti-etalon, diffused n+, single level metal

    patched version of the original output function which

    can be called multiple times. It will override the

    output already present.

    def output(layer_spec, layer_data)

    ls = string_to_layerinfo(layer_spec)
    li = @target_layout.layer(ls)
    shapes = @target_layout.cell(@target_cell).shapes(li)
    shapes.clear # new feature

    # confine the shapes to the region of interest
    @ep.boolean_to_polygon([ ],, RBA::EdgeProcessor::mode_and, true, true).each do |polygon|

    I think they are largely copied from a generic example script.

    I am aware I didn't give you enough information in my original post to troubleshoot. I didn't want to flood the forum with irrelevant details.

    Thanks for your support,


  • P.S. Sorry about the huge font which crept in, I was trying to put the pasted text into Italic!


  • Hi Ray,

    To paste code, you need to put a single line with three backticks before and after the code. Otherwise it's formatted in Markdown convention (# will become a headline etc.).

    I agree the error message is somewhat gross, but it tells everything I need to know.

    To fix the problem you should entirely delete the function definition from "def output(layer_spec, layer_data)" to "end". It is no longer needed and isn't portable. That's why you receive this message. Your colleague probably uses an older XSection system. If you change the file both you and your colleague should switch to the version 1.4 installable from the package manager.

    Kind regards,


  • Thanks Matthias
    That seems to have fixed it.

    Thanks also for providing and supporting this software.


Sign In or Register to comment.