How to get polygon/pattern/cell information in a cell?

Hi sir , May I know how to using scripting to get a cell instance / pattern / polygon information?
in DRC function , I knew code as below...

Pattern=input(51,0)
Pattern.data.each.....

after that , we can get the pattern /polygon data from layer #51/0.
but , this code can get data by layer 51/0 only (what the special layer do I define in the input )
Now , I want to know how the pattern layout/ cell instance in the cell named "Bump".
in the cell , that may have pattern in layer 51/0 or 52/0 ....etc...
Is possible to make a code like...
dbGet Info =[dbOpencell $libname Bump]

 info.instance.each....

 info.shape.each...

by the way , even that , I don't know how to read the layer information in a shape....

sorry to trouble you for that , please help it....
Thanks.

p.s another question about "Help" document , in the document , how to read that ?
When I want to using the document data to get some idea about coding , I can get some table , but no example for that.
if I want to learn Klayout script , how to enter the door?

Comments

  • Hi,

    here is some code in Python to print the contents of the current cell:

    # Get currently loaded layout and cell
    # ly is a Layout object:
    #   https://www.klayout.de/doc-qt5/programming/database_api.html#h2-18
    #   https://www.klayout.de/doc-qt5/code/class_Layout.html
    # cell is a Cell object:
    #   https://www.klayout.de/doc-qt5/programming/database_api.html#h2-525
    #   https://www.klayout.de/doc-qt5/code/class_Cell.html
    # For CellView see: 
    #   https://www.klayout.de/doc-qt5/programming/application_api.html#k_7
    #   https://www.klayout.de/doc-qt5/code/class_CellView.html
    ly = pya.CellView.active().layout()
    cell = pya.CellView.active().cell
    
    print("Listing of cell: " + cell.name)
    
    print("Instances:")
    
    # Iterate the instances in the cell
    # inst is an Instance object:
    #   https://www.klayout.de/doc-qt5/programming/database_api.html#h2-877
    #   https://www.klayout.de/doc-qt5/code/class_Instance.html
    for inst in cell.each_inst():
      print("Instance of cell " + ly.cell(inst.cell_index).name + " (" + str(inst) + ")")
    
    print("Shapes:")
    
    # Iterate the layers:
    for layer_index in ly.layer_indexes():
      # layer_info is a LayerInfo object:
      #   https://www.klayout.de/doc-qt5/code/class_LayerInfo.html
      layer_info = ly.get_info(layer_index)
      print("On layer " + str(layer_info) + ":")
      for shape in cell.shapes(layer_index).each():
        # shape is a Shape object:
        #   https://www.klayout.de/doc-qt5/programming/database_api.html#h2-1063
        #   https://www.klayout.de/doc-qt5/code/class_Shape.html
        print(str(shape))
    

    I have added some pointers to documentation.

    You referred to DRC scripts - this is something different. If you want to code universal scripts, you should stay on the API level and use Ruby or Python (easier to learn I guess).

    For learning how to code scripts, I can only offer the documentation. Here is the main entry point: https://www.klayout.de/doc-qt5/programming/introduction.html

    Matthias

  • Hi Sir,
    Thanks very much for your code.
    I still using (Ruby) DRC scripts to do that and get same result after modify some of code.
    the key will be ly.get_info(layer_index) in this case.
    But , May I know how to get the layer name (not layer number /purpose) when I have a layer_index?

  • @jiunnweiyeh If we're talking about GDS files there is no layer name in the layout database. Layers are only addressed by layer number and datatype number. OASIS has layer names (you can get by asking LayerInfo for the name), but that is an optional attribute and it's usually empty.

    The layer properties from the LayoutView's layer table you cannot access from a DRC script. That's an entirely different domain.

    Matthias

Sign In or Register to comment.