Adding a PCell to a DataType layer

edited January 2016 in Ruby Scripting

Hello,

I am having difficulties adding a PCell to a certain DataType layer. I can add it to the right layer but not to a certain DataType. It will always add it to DataType zero. I am trying to add a text(serial number) using a PCell to layer 45 and datatype 45 and the script will always add it to 45/0.

This is the line i am using to assign layer and data type.

param = { "text" => $SN, "layer" => RBA::LayerInfo::new($layer.to_i, $dataType.to_i), "mag" => $magnification.to_i, "inverse"=> invertedBool }

Here is the full code

module MyMacro

  # 1. Open command line in directory "C:\Program Files\KLayout (64bit)\klayout_app.exe"
  # 2. Run command: klayout_app.exe -b -r C:\TEMP\hello\addSerialNumber.lym -rd inputFile=C:\TEMP\hello\700-2000-00Ctemp.gds -rd outputFile=C:\TEMP\hello\my_layout3.gds -rd mirror=TRUE -rd rotation=23 -rd X=-6000 -rd Y=8000 -rd layer=9 -rd dataType=210 -rd SN=55AB -rd magnification=600 -rd inverseText=TRUE

  include RBA
  ly = RBA::Layout::new
  ly.read($inputFile)

  # create new cell TOP
  #cell_index = ly.add_cell($SN)
  cell = ly.cell(ly.top_cell.cell_index)


  # Find the lib
  lib = RBA::Library.library_by_name("Basic")
  lib || raise("Unknown lib 'Basic'")

  # Find the pcell
  pcell_decl = lib.layout.pcell_declaration("TEXT")
  pcell_decl || raise("Unknown PCell 'TEXT'")


  if $mirror.to_s == "TRUE" 
     mirror = TRUE
  else
     mirror = FALSE
  end

  if $inverseText.to_s == "TRUE" 
     invertedBool = TRUE
  else
     invertedBool = FALSE
  end

  # assume the coordinates are micron units
  x = ($X.to_f / ly.dbu + 0.5).floor
  y = ($Y.to_f / ly.dbu + 0.5).floor

  # Set the parameters (text string, layer to 10/0, magnification to 2.5)
  param = { "text" => $SN, "layer" => RBA::LayerInfo::new($layer.to_i, $dataType.to_i), "mag" => $magnification.to_i, "inverse"=> invertedBool }

  # Build a param array using the param hash as a source.
  # Fill all remaining parameter with default values.
  pv = pcell_decl.get_parameters.collect do |p|
    param[p.name] || p.default
  end

  # Create a PCell variant cell
  pcell_var = ly.add_pcell_variant(lib, pcell_decl.id, pv)

  t = RBA::CplxTrans::new(1, $rotation.to_i, mirror, x, y)

  #Get top cell of file
  ly.top_cells.each { |curCell|
      pcell_inst = ly.cell(curCell.name).insert(RBA::CellInstArray::new(pcell_var, t))
      ly.rename_cell(curCell.cell_index, curCell.name + ":" + $SN.to_s)
    break
  }

  #Rename the TEXT we just inserted else later when we merge this will cause data to be loss
  ly.each_cell_top_down { |curCell|
    if ly.cell(curCell).name == "TEXT"
        ly.rename_cell(curCell,"TEXT:" + $SN.to_s )
    end
  }

  #ly.rename_cell(ly.top_cell.cell_index, $SN)        
  ly.write($outputFile)
end

Any help would be great.

Thanks,
Keil

Comments

  • edited November -1

    Hi Keil,

    thanks for this well-prepared test case!

    However I'm afraid I can't reproduce that immediately. I tried with version 0.24.4. Lacking your input file I tried with an empty file (no layers, just a single top cell) and the command line you give in the script. The result is a rotated and mirrored text on layer 9/210 as expected.

    Matthias

  • edited November -1

    Ok thanks for trying. I will play around with it more and see if i can figure it out.

  • edited November -1

    Nevermind my fault the code works fine. I was not calling the script from the command line correctly in my program. So when the script didn't have dataType as a command line argument it just assigned it a zero.

    Sorry about creating this discussion it can be deleted.

    Thanks for your help Matthias.

  • edited November -1

    Hi Keil,

    never mind. Thanks for giving feedback.

    Matthias

Sign In or Register to comment.