Can I check if cut_box is emtpy

Dear all,

I want to check if cut_box is not empty, i will save cut_box to image

        cut_box = db.DBox(sub_x2, sub_y2, sub_x1, sub_y1)
        if cut_box is empty:
            print("box is empty")
            print("box is not empty")

        layout_view.save_image_with_options(sub_image_path, pixel_size, pixel_size, 0, 0, 0, cut_box, False)

Here is an example of cut_box is empty images (just a full white image)

Thanks and best regard,


  • Hi hieund,

    begin_shapes_rec_overlapping function returns a list of object that overlapped with given box.

    def shapeInRange(cell, layerIndex, detectBox):
        withShape    = False
        for rsi in cell.begin_shapes_rec_overlapping(layerIndex, cut_box):
            withShape = True
        return withShape
    layerIndex   = 2
    cell         = layout_view.active_cellview().cell
    cut_box      = db.DBox(sub_x2, sub_y2, sub_x1, sub_y1)
    withShape    = shapeInRange(cell, layerIndex, cut_box)
  • edited November 14

    Thank Mr @RawrRanger,
    I try to using shapeInRange function, but this function always return True in every cut_box, May I wrong anything ?

  • edited November 14

    Hi hieund,

    begin_shapes_rec_overlapping is not suitable for filtering shapes with holes,
    if shapes with holes is overlapped with the box this function will still returns True,
    so additional check is using polygon.touches is required.

    Another thing is this function does not check the layer visibility, so hidden layer will requires additional check.

    following test case using three cut box 1~3 corrosbonded to the three white boxes placed in left to rignt order.

    without polygon.touches check, the output for L0/0 (bule) will be True, True, False
    with polygon.touches added, the output for L0/0 (bule) will be False, True, False

    mainWindow   = pya.Application.instance().main_window()
    layout_view  = mainWindow.current_view()                
    cellView     = layout_view.active_cellview()
    cell         = cellView.cell
    def layersVisible(layout_view, layerIndex):
        itr = layout_view.begin_layers()
        while not itr.at_end():
            lyp = itr.current()
            if layerIndex == lyp.layer_index() and lyp.visible:
                return True
        return False
    def shapeInRange(cell, layerIndex, detectBox):
        withShape = False
        unit      = cell.layout().dbu
        for rsi in cell.begin_shapes_rec_overlapping(layerIndex, detectBox):
            if rsi.shape().polygon:
                if (rsi.shape().polygon.transformed(rsi.trans()).to_dtype(unit).touches(detectBox)): 
                    withShape = True
        return withShape
    def shapeInVisibleRange(layout_view, cell, layerIndex, detectBox):
        if layersVisible(layout_view, layerIndex):
            return shapeInRange(cell, layerIndex, detectBox)
        return False
    cut_box1     = pya.DBox(     0, 0,  50000, 50000) # test case overlapped with L(6, 0) only
    cut_box2     = pya.DBox( 65000, 0, 115000, 50000) # test case overlapped with L(0, 0) only
    cut_box3     = pya.DBox(125000, 0, 175000, 50000) # test case overlapped Nothing
    withShape01  = shapeInVisibleRange(layout_view, cell, 0, cut_box1) #L(6, 0)
    withShape02  = shapeInVisibleRange(layout_view, cell, 0, cut_box2) #L(6, 0)
    withShape03  = shapeInVisibleRange(layout_view, cell, 0, cut_box3) #L(6, 0)
    withShape11  = shapeInVisibleRange(layout_view, cell, 1, cut_box1) #L(0, 0)
    withShape12  = shapeInVisibleRange(layout_view, cell, 1, cut_box2) #L(0, 0)
    withShape13  = shapeInVisibleRange(layout_view, cell, 1, cut_box3) #L(0, 0)
    print(withShape01, withShape02, withShape03) #True False False; if L(6, 0) is visible
    print(withShape11, withShape12, withShape13) #False True False; if L(0, 0) is visible
  • Thanks you, Mr @RawrRanger , it works for me !!

Sign In or Register to comment.