Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthornezrick
    • CommentTimeFeb 5th 2018
    Hi Matthias,

    I would like to know if it is possible to create a text file with a Ruby script. My idea is to get a summary of parameters and calculations at the end of the macro execution.
    Project name: xxxx
    Area: yyyy
    CD: zzzz

    Thanks in advance for your answer.
    • CommentAuthordavidnhutch
    • CommentTimeFeb 6th 2018 edited

    Outputting a text file from Ruby can be done in several ways -- search google for other examples if the below doesn't suit.

    I will also note that there is a relatively easy way to just get a hash with all of the variables in it. So, if in your code you've calculated project_name, area, cd, ..., then you run this code to generate a hash with everything you want, then output it to txt file.

    project_name = 'something'
    area = 1.1
    cd = 1.2
    hash = {}
    local_variables.each{ |sym|
      var = "#{sym}"
      val = eval(var)
      unless var == "hash" # ie. ignore the variable called "hash"
        hash[var] = val # append it to the hash
    # Print out the result to the console
    p hash
    # The write that hash to a file
    yourfile = 'C:\Users\davidnhutch\Downloads\something.txt', 'w') { |file| 
      file.write(hash) # I haven't attempted to format this in the same way you did, but that can be done
    • CommentAuthornezrick
    • CommentTimeFeb 7th 2018
    Thank you David for your answer and your proposal.

    I used the following code that it perfectly works for my need:

    summaryfile = 'C:\Users\xxxxh\KLayout\Rep_travail\Template\Summary.txt', 'w') do |out|

    out << "Project name: #{project_name.text} \n"
    out << "Design area : #{area} \n"
    out << "CD: #{cd} \n"