Fetch all Instance of a cell

edited March 2021 in Python scripting

Hi,
@Matthias I need to fetch all instance of a cell, similar to Browse instance in python script. Any help on how to proceed with that?

Thanks
Vandhana

Comments

  • edited March 2021
     def get_path(l1,path=None):
            if l1.is_top():
                print(path)
                return
            for p in l1.each_parent_inst():
                    p_inst = p.inst()
                    aref = ""
                    if(p_inst.is_regular_array()):
                        aref = "[{},{}]".format(p_inst.na,p_inst.nb)
                    elif(p_inst.size()>1):
                        aref= "(+{}x)".format(p_inst.size() - 1)
    
                    new_path = ""
                    if path:
                        new_path = layout.cell_name(p.parent_cell_index()) + aref + "/"+ path
                    else:
                        new_path = layout.cell_name(p.parent_cell_index()) + aref + "/"
    
    
                    cell = layout.cell(p.parent_cell_index())
                    get_path(cell,new_path)
    

    I figured it out! But what's difference between regular array and instance.size>1? (i.e which instance would not be captured by regular array)

    the definition for complex array is it has magnification or arbitary rotation. This has magnification but it is captured by regular array. Can you please tell what's the difference?

    Thanks

  • edited March 2021

    @vandhana Sorry for the late reply ... and very good your figured it out :) The code will give you the instantiation paths of a specific cell. That's pretty much how the instance browser does it - very good! :)

    The mystery about the size() > 1 instance is twofold: first, a regular array in a special case can have size () == 1, so size () > 1 tells you the instance is actually a "multi-instance". Second, in some cases you may find something which is called "iterated instances". You cannot create such instanced with the editor nor can you see them. But they are present in viewer mode inside the database and when you read certain kind of OASIS files. "iterated instances" are basically instances which come with a list of coordinates rather than array dimensions and step vectors. OASIS uses such instances for compactness and KLayout keeps this representation to reduce the memory footprint for big OASIS files.

    Hence - and only in these cases - you may see instances which are not regular, but have size > 1. You can iterate the members of this iterated instance with "each_trans" or "each_cplx_trans" if you're interested.

    Kind regards,

    Matthias

  • @Matthias
    Thanks for your insights. It's of great help. :)

  • Thank you @vandhana and @Matthias. I'm building up on your work and attempting to extract the coordinates of each instance relative to the top cell, in a similar manner to how the instances browser displays the coordinates. What would be the easiest way to go on about this? Do I need to recursively offset the coordinates based on the instance position within it's parent cell?

    On a related note: is there a way to access the Instance browser through the API? I couldn't find much information in the API documentation regarding this.

    Best,
    Mustafa

  • Hi @Mustafacc,

    no, the script features are not intended to automate UI functions. That's a different level (the script API acts on the database level) and architecture wise, there are no hooks to support that. Maybe native Qt object hacking is an option, but I'd not recommend that. The widget hierarchy is not guaranteed to stay like that and code may not be portable across different Qt versions.

    Matthias

Sign In or Register to comment.