Flatten instance from Search And Replace?


I find the custom queries in the Search and Replace function extremely useful. Is there way to flatten instances (1 to multiple hierarchy levels) once they are found from using Search and Replace?



  • edited March 2020

    Hi Dan,

    You can try this ("via" is that name pattern I picked):

    with instances of cells ..via do inst.flatten

    But there is no warranty this works properly. There are too many interactions and manipulation of the hierarchy tree during the query isn't supported well. There is too much potential interference between the query and hierarchy manipulations.

    If this fails, you can basically use queries to tag instances with user properties:

    with instances of cells ..via do inst.set_property("X", 1)

    After this, it's a matter of a short script to flatten these tagged instances:

    ly = pya.CellView.active().layout()
    insts_to_flatten = []
    # NOTE: iteration of instances while deleting them is
    # critical. Better first scan and the delete
    for cell in ly.each_cell():
      for inst in cell.each_inst():
        if inst.property("X") == 1:
    ly.start_changes()  # if performance matters
    for i in insts_to_flatten:
    ly.end_changes()  # needs to match start_changes()

    You can also use "flatten" without the "1" argument for "all levels", but you risk to flatten away an instances with itself are flagged. Avoiding this case is difficult.


  • Matthais,

    Thank you for the help!
    You were correct, flattening from search and replace would skip over some instances.
    Tagging the instances then flattening from the script worked great!

    Thanks again,

Sign In or Register to comment.