Glade Reference


Programming Glade in Python

The entire Glade database and much of the UI is wrapped in Python using SWIG. This means you can write Python scripts to automate tasks - PCells (parameterised cells) are a good example. Why Python? Well it is an object-oriented language and so it wraps C++ well, unlike some other interpreted languages.

You can enter python commands directly at the command line. Some useful ones:

    getSelectedSet()

returns a python list of the selected objects. You can print information about an object using the print command:

    objs = getSelectedSet()
    for obj in objs :
       print obj

To get the current cellview, use:

    cv = getEditCellView()
  

To open a library, use:

    lib = getLibByName("myLib")
  

To open a cellView, use:

    # 'r' opens an existing cell for read
    # 'a' opens an existing cell for edit
    # 'w' creates a new cell.
    cv = lib.dbOpenCellView("myCell", "layout", 'a')
  

To search for objects, you can use :

    # some search rectangle
    search_rect = Rect(0, 0, 10000, 10000)
    # some layer number
    layer_number = 6
    objlist = cv.getOverlaps(search_rect, layer_number)
    for obj in objs :
      print("object is a", obj.objName())
  

Some python bindings require C style arrays of coordinates. You can use the python intarray function to create an array with a specified size.

      var = intarray(number_of_elements) 
    

The command line interpreter

The message window at the bottom of the Glade main window is split into two parts: the message pane, which shows messages and output from the Python interpreter. You can use the Right Mouse Button to copy text from the message pane. Below the message pane is the command line. You can type Python commands into the command line.

The Python command line supports various control characters to assist in typing in Python commands:

Writing Python scripts

An example of a Python script follows. Don't forget that Python relies on indentation for e.g. for and while loops!

    # Example python script
    print('Starting script...')
    #
    # Create a new library, called 'fred'
    lib = library("fred")
    #
    # Create a new cellView in this library
    cv = lib.dbOpenCellView("test", "layout", 'w')
    #
    # A rectangle. By default database units are 0.001 micron
    width = 10000
    pitch = width * 2
    r = Rect(0, 0, 0, 0)
    #
    # Create four rectangles on layer 1
    layer = 1
    for i in range(2) :
      for j in range(2) :
     	  r.setLeft(j * pitch) 
     	  r.setRight(j * pitch + width)
     	  r.setBottom(i * pitch)
     	  r.setTop(i * pitch + width)
     	  cv.dbCreateRect(r, layer);
    #
    # Update the cellView after creating any objects
    cv.update()
    #
    # Open the cellView for display
    ui().openCellView("fred", "test", "layout")
    #
    # Do a region query
    q = cv.bBox()
    objs = cv.dbGetOverlaps(q, layer)
    obj = objs.first()
    while obj :
       print('found object ', obj.objName(), ' with origin = (', obj.left(), obj.bottom(), ')')
       obj = objs.next()
    #
    print('Finished script...')

 

Database reference

The following sections of the database bindings have been documented.

Contents|Index

Copyright © Peardrop Design 2026.