Exporting the hierarchy

I would like to obtain a text listing of the layout hierarchy,
just as it appears in the fully expanded "Cells" window
when in not-Flat_List_Mode (I suppose the flat format
has its uses too).

I cannot find in the menus any item that would do this.

Obviously the information already exists right in that
window. But it is not copy-able (Copy wants to select
the cell, not text) or printable-to-file.

Maybe there could be a context-menu addition to
"Copy All" (as displayed, as text) to the system paste
buffer, so the info can be taken between applications?

Comments

  • Yes, sure :)

    But there can also be a (Python) script:

    class TreePrinter(object):
      def __init__(self):
        self.text = ""
      def add(self, text, indent):
        self.text += " " * indent + text + "\n"
      def show(self):
        pya.BrowserDialog("<pre>" + self.text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;") + "</pre>").exec_()
    
    def dump_tree(cell, printer, indent):
      printer.add(cell.name, indent)
      child_cells = [ c for c in cell.each_child_cell() ]
      for c in sorted(child_cells, key = lambda c : cell.layout().cell(c).name):
        dump_tree(cell.layout().cell(c), printer, indent + 1)
    
    ly = pya.CellView.active().layout()
    printer = TreePrinter()
    for tc in ly.top_cells():
      dump_tree(tc, printer, 0)
    printer.show()
    

    It opens a browser window from which you can press Ctrl+A to select all and Ctrl+C for copy.

    Best regards,

    Matthias

  • edited October 25

    Hi,

    Is there a way to do this with just the python module and not using the klayout viewer? ie using the Cell class instead of CellView class

    EDIT: I found a solution. Need to clean up the output format using indents but for now this gets me what I need

    import pya
    ly = pya.Layout.new()
    ly.read(layout_filepath)
    output = []
    for tc_index in ly.each_cell_top_down():
      tc = layout.cell(tc_index)
    
      for cc in tc.each_child_cell():
        output.append(tc.name + ":" + tc.layout().cell(cc).name)
    

    Thanks,
    Scott

  • Yes :)

    But it does not print the nice tree ...

    Matthias

Sign In or Register to comment.