Random perturbation of individual cells in an array

I have a square array of cells, and wish to move each cell within the array a random distance in x and y (From -1 to +1 micron, say). This perturbation would be different for each individual cell.

I know that this can be done manually by flattening the hierarchy and moving each cell a distance specified by an externally generated random number, but could this be done in Python instead?

Comments

  • Ha! I love these requests ... that's what I integrated scripting. This is a feature I guess no one would build into an application :)

    Here is the code:


    import random # This assumes the top cell is called "TOP" (where the instances go to) # and the cell you want to place is called "CELL" top_name = "TOP" cell_name = "CELL" # The array pitch in x and y direction in micrometers xpitch = 10.0 ypitch = 10.0 # The number of placements in x and y direction xdim = 100 ydim = 100 # The variation of x position (-xvar ... xvar) and y position xvar = 1.0 yvar = 1.0 view = pya.LayoutView.current() view.transaction("Random placement of cells") # undo/redo support try: ly = pya.CellView.active().layout() top_cell = ly.cell(top_name) if top_cell == None: raise RuntimeError("No cell called " + top_name) placed_cell = ly.cell(cell_name) if placed_cell == None: raise RuntimeError("No cell called " + cell_name) for ix in range(0, xdim): for iy in range(0, ydim): dx = xvar * (random.random() * 2.0 - 1.0) dy = yvar * (random.random() * 2.0 - 1.0) xpos = ix * xpitch + dx ypos = iy * ypitch + dy inst = pya.DCellInstArray(placed_cell.cell_index(), pya.DTrans(pya.DVector(xpos, ypos))) top_cell.insert(inst) finally: view.commit() # undo/redo support

    Enjoy!

    Matthias

Sign In or Register to comment.