How to interface DRC engine to Ruby engine in Klayout?

edited June 2 in Ruby Scripting

Hi,

How to interface DRC engine to the Ruby engine in Klayout?
such that I can transfer Ruby variable values between the two engines?

In the Example script, how to I pass the variable "Die_Orientation" from the calling ruby script to the DRC engine?
and viceversa, how to I pass the content of the variable "l10" from DRC engine to Ruby?

module MyMacro

include RBA

mydrc = <<DRC
l10 = input(15)
l1 = input(1)
(l10 ^ l1).sized(-0.002).output(100, 0)
DRC

Die_Orientation = "vertical"
eng = DRC::DRCEngine::new
eng.instance_eval(mydrc)
eng._finish

end

Thank you in advance
Best regards
Giovanni

Comments

  • Hi Giovanni,

    there are many ways to achieve this ... it's all built into Ruby. The DRCEngine class is a ordinary Ruby class, and "instance_eval" is a standard Ruby method.

    The dirty solution is to use global variables, e.g. "$die_orientation".

    A more elegant solution is to wrap the drc code into a block. The block has access to the variables outside:

    Die_Orientation = "vertical"
    
    eng = DRC::DRCEngine::new
    eng.instance_eval do
      l10 = input(15)
      l1 = input(1)
      (l10 ^ l1).sized(-0.002).output(100, 0)
      # use Die_Orientation in this code
    end
    eng._finish
    

    Matthias

Sign In or Register to comment.