Macro Development, choosing the fiel encoding.


I am running in a frustrating issue. I am writing some DRC which run perfectly (thanks Klayout).
And it works so well that I made a nice put to start the DRC script with one click, again success.
But I realize that Klayout save the DRC script in a weird encoding, transforming my '>' symbol to some '&gt'.
All the other text readers see that the text is changed to '&gt' but not Klayout.
And if I correct manually the script is loaded correctly but Klayout.

Can I change the encoding used by Klayout ? Is my understanding of the issue correct ?



  • Hi, Alexandre!

    Is your script is .lym file? If so, it must be valid XML format and that assume encoding of special characters. Actually you could put body of script in separate Ruby file (so there are no need for special symbols encoding) and only call entry point from .lym file.

  • Hi Eugene,

    You are definitely right. That's the problem, my script is a lydrc and it's read as plain text instead of XML.
    What you propose is an solution indeed. But ideally, I would like to find out how to read this file properly.
    Klayout is obviously capable of it, I need to find out how it is done.

  • edited June 2021

    The solution I choose for now is very simple. I take the text between the tag and replace the "problematic" symbol. It's not ideal but it works as a temporary solution.
    drc ="myfile",encoding:'UTF-8')
    drc = drc.split("<text>")[1]
    drc = drc.split("</text>")[0]
    drc = drc.gsub("&gt;", ">")
    eng = DRC::DRCEngine::new

  • I think html.unescape() from html module is better solution.

  • @alexandrePhoton .lydrc should be XML always. You mean you're editing it externally?

    XML can store more metadata like menu binding information. If you don't need that, you can use plain text. Use the ".drc" suffix then.


  • Indeed I could use plain ruby but I need the XML to use the script in two different places. It's a bit lazy but really convenient.


Sign In or Register to comment.