Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorrick_omni
    • CommentTimeMar 7th 2018 edited

    Related to this question, there must be a scripting way to iterate through all the vertices of a polygon and a) print them out, or b) delete some of them to clean up a design if they meet certain conditions (eg, if N of them are in a very straight line only the endpoints need to be kept), or c) snap them to a grid if X or Y are within distance D of the grid, etc.

    Also, can this iteration be done over all the polygons in the layer?

    Is there an example of a script like this (in Python or Ruby) that I can use to get started?

    Thanks in advance,


    Here's a starting point. Click on the polygon and run this script in the IDE (press F5 to get the IDE). It simply grabs the points of the polygon. The other functions you mention are certainly possible. For (b), I'd make an array of the xy coordinates, delete one, then make a NEW polygon and write it to the layout. For (c) similarly.

    # Extracts the xy points of the selected shape(s) and puts in csv file.
    module ExtractPoints
      outfile = "C:/path/to/output.csv"
      file =, "w")
      file.puts("x,y") # Header row
      include RBA
      ly = CellView::active.layout
      lv = Application::instance.main_window.current_view
      cell = ly.top_cell
      lv.each_object_selected { |obj|
        shape = obj.shape
        if shape.is_polygon?
          shape.polygon.each_point_hull { |pt|
            x, y = pt.x*ly.dbu, pt.y*ly.dbu
            p "#{x}, #{y}" # Print it to the console
            file.puts "#{x}, #{y}" # Put it in a file
    • CommentAuthorrick_omni
    • CommentTimeMar 7th 2018 edited

    Thanks David,
    That is a great starting point. Examples for Klayout was a great help, also. Item b) is almost working.

    Note to self: this code is Ruby, not Python. Fine - I'm learning two languages for the price of one!


    • CommentAuthorMatthias
    • CommentTimeMar 8th 2018

    Hi David,

    I noticed the "Examples" first time now ... great thing! Thanks a lot!