About " each_shape " function under cell class

Hello Matthias:

Somehow I lost my top cell after I run below code, not sure the " each_shape " function will erase the cell where it exist ? or I missed something important ?

layout = pya.Application.instance().main_window().current_view().active_cellview().layout()
top = pya.Application.instance().main_window().current_view().active_cellview().cell
pin = layout.layer(95, 0)
label = top.each_shape(pin) <-----

Thanks for your reply always :)

Comments

  • No, each shape will not erase anything. But the code is lacking the body of the loop. It should look like

    top.each_shape(pin) do |shape|
      ... do something with "shape" ..
    end
    

    Matthias

  • Hello Matthias, Thank a lot.

  • Hello Matthias :

    Below is a simple code to centralize the text in box, but I still lost my top cell and text after running. I just made it write a new GDS file to cover temporary. Would you give me some idea when free? Thank you ~

    import pya
    
    top = pya.Application.instance().main_window().current_view().active_cellview().cell
    
    pin = layout.layer(95, 0)
    pad = layout.layer(2, 0)
    
    label = top.each_shape(pin)
    box = top.each_shape(pad)
    
    Pin_name = []
    Pad = []
    
    while True:
        try:
            label_item = next(label)
            Pin_name.append(label_item)
            box_item = next(box)
            Pad.append(box_item)
        except StopIteration:
            break
    
    for x in range(0, len(Pin_name)):
        for y in range(0, len(Pad)):
            if pya.DPolygon(Pad[y].dbbox()).inside(pya.DPoint(Pin_name[x].text_dpos.x, Pin_name[x].text_dpos.y)) is True:
                Pin_name[x].text_dpos = pya.DVector(Pad[y].dbbox().center())
            else:
                None
    
    layout.write("Label align.gds")
    
  • First, "layout" is a variable which is not assigned anything. I think you want to say

    cellview = pya.CellView.active()
    layout = cellview.layout()
    top = cellview.cell
    

    Second, the first loop just iterates over the pins and labels in the same loop. I think you want to have two separate loops for collecting pins and labels. This is a simple version using array comprehension:

    Pin_name = [ s for s in top.each_shape(pin) ]
    Pad = [ s for s in top.each_shape(pad) ]
    

    Third, you can iterate over the arrays themselves, drop the "else" (with the "None" which is simply nonsense) and simplify the inside check:

    for pin in Pin_name:
        for pad in Pad:
            if pad.dbbox().contains(pin.text_dpos):
                pin.text_dpos = pad.dbbox().center()
    

    Matthias

  • Hello Matthias,

    Wow.. this updated code is amazing to me !! Can't not wait to use this skill to other script.
    Somehow, after running the updated code, I still lost my top cell. I think re-location the shape coordinate

    pin.text_dpos = pad.dbbox().center()

    already means " ... do something with "shape" .. " , but it's OK to re-write a new GDS to cover it, not too much time , thanks a lot

  • Could you explain what you mean by "lost my top cell"? It's still there - the code does not change that. And when I tried the code I still see the top cell and it's still active.

    Matthias

  • edited April 2022

    Hello Matthias,

    Maybe it is due to my own computer's problem, please have below 3 pictures,
    a) Picture-1 : use box 100 x 200 um to test
    b) Picture-2 : top cell is disappear after running below code
    c) Picture-3 : choose both text & box by mouse dragging, found the text already be centralized,
    I found after the code run, just save file and re-open it, everything will be normal, thanks



    import pya  
    
    cellview = pya.CellView.active()
    layout = cellview.layout()
    top = cellview.cell
    
    pin = layout.layer(95, 0)
    pad = layout.layer(2, 0)
    
    label = top.each_shape(pin)
    box = top.each_shape(pad)
    
    Pin_name = []
    Pad = []
    
    Pin_name = [ s for s in top.each_shape(pin) ]
    Pad = [ s for s in top.each_shape(pad) ]
    
    
    for pin in Pin_name:
        for pad in Pad:
            if pad.dbbox().contains(pin.text_dpos):
                pin.text_dpos = pad.dbbox().center()
    
  • Thanks for the images.

    This is weird. The cell must be there still, but I don't know why it is not displayed. I have not seen an effect like this before.

    What Windows version are you using?

    Matthias

  • Hmmm..... Windows 7 " professional " SP1 , maybe it is time to upgrade.. :*

    Vincent

  • Oh well, maybe :)

    I'm not aware of any compatibility issues, but maybe it's a graphic driver thing or similar. I guess only the cell name isn't painted. Data is still there.

    Matthias

  • Got it with thanks

    Vincent

Sign In or Register to comment.