Receive xy coordinate of selected instance of a cell

With the Klayout python module I'm struggling to receive the x,y coordinates of a selected Instance of a cell in a wafer map.

selectedCell = next(pya.LayoutView.current().each_object_selected())
cell_id = selectedCell .cell_index()
bbox = layout.cell(cell_id).bbox()

Would this be the correct way to receive the x,y ?
Main target is to replace a selected instance with one from a gds file.

Thanks and best regards,
Andy

Comments

  • Hi Andy,

    I think you can do all of that in a single step. I'd recommend to open the GDS file with the substitution cell and copy/paste it into your wafer map layout first. Then the task is to substitute each selected instance with this cell. You can use this script for this purpose (edit "cell_to_use_instead" to specify the new cell's name):

    # CAUTION: this cell MUST EXIST in the layout
    cell_to_use_instead = "SUBSTITUTE"
    
    lv = RBA::LayoutView.current
    
    begin
    
      # Undo/redo support
      lv.transaction("Replace cell")
    
      lv.each_object_selected do |sel|
    
        if sel.is_cell_inst
    
          # Replace the cell
          new_cell_index = sel.layout.cell(cell_to_use_instead).cell_index
          sel.inst.cell_index = new_cell_index
    
        end
    
      end
    
    ensure
    
      lv.commit
    
    end
    

    Regards,

    Matthias

  • Hello Matthias,
    thanks for your feedback. Your solution worked very well but I decided finally to use the X,Y coordinates. Reason is that I need a solution where I could store the values into a config file. For the program I use for viewing and direct editing klayout and your klayout python package to manage the data.
    I'd like to thank you for providing klayout - there is no request we can't overcome by using the programming API. Thanks for all the effort to put such a great tool together.
    Here my solution I worked out:
    ``

    def loadMarkerCell(self):   
        markerFilename = pya.FileDialog.ask_open_file_names("Load Marker", self.gdsDir, "gds* (*.gds*);;oas (*.oas)")
        if os.path.exists(markerFilename[0]):
                dialog.markerText.setText(markerFilename[0])
    
    def changeCell(self):
        if 'none' in dialog.markerText.text :
            print('Please select a marker cell first ...')
        else:
                layout = pya.Application.instance().main_window().current_view().active_cellview().layout()
                lv = pya.LayoutView.current()
                TOP = layout.top_cell()
                for sel in lv.each_object_selected():
                    if sel:
                        if sel.is_cell_inst():
                            self.inst = sel.inst()
                            self.pX = self.inst.cplx_trans.disp.x # get the coordinates
                            self.pY = self.inst.cplx_trans.disp.y
                            self.inst.delete() # delete the selected instance
                            markerFilename= dialog.markerText.text  # get the marker cell
                            layoutM = pya.Layout()
                            layoutM.read(markerFilename)
                            layoutM = self.adjustOrigin(layoutM,layoutM.top_cell()) # ensure origin center
                            TopM = layout.create_cell(layoutM.top_cell().name)
                            TOP.insert(pya.CellInstArray(TopM.cell_index(), pya.Trans(pya.Point(self.pX,self.pY))))
                            TopM.move_tree(layoutM.top_cell())
                            layoutM.destroy()
                        layout_filename = pya.Application.instance().main_window().current_view().active_cellview().filename()
                        layout.write(layout_filename)        
                    else:
                        pya.MessageBox.info("Error", "No Instance selected. Select an instance first ... ")
    

    ``

  • You're welcome :)

    Thanks for sharing your code.

    Matthias

Sign In or Register to comment.