LayoutScript for Python is an alternative scripting interface to the build-in C++ Macros having the same Application Programming Interface (API). It is an an extension module to a stand alone Python installation. It is a pure scripting interface without any graphical output and runs independent to the LayoutEditor application. It is build as an easy to use scripting feature for all kind of designs and can be use with all other extension modules Python offers. You can try and run LayoutScript without a license key for small designs. For designs with unlimited size a full version of the LayoutEditor is required.
If you need scripting to adjust the user interface with new menu entry, create parametric cells from the schematic or callback macros after changing device parameter, please use LayoutEditor C++ Macros.
Using LayoutScript is very simple. You can start a python script from the integrated TextEditor by pressing the execute button. No setup required. In the script the line "import LayoutScript" will load the module and the line from LayoutScript import * will enable to use any LayoutScript command without a prefix. The Application Programming Interface (API) is identical to the LayoutEditor. The LayoutScript module is independent of any open layout window. So please don't forget to save the result in the script. Afterwards the created file can be load in the LayoutEditor.
# load the LayoutScript module import LayoutScript # use LayoutScript without prefix from LayoutScript import * #create a new layout object l=project.newLayout(); #rename a layer layers.num(6).name="new text" c=l.drawing.currentCell c.cellName="test-cell-python" c.addBox(0,0,5000,7000,5) c.addRoundedBox(10000,0,5000,7000,500,5) c.addChamferedBox(20000,0,5000,7000,500,5) c.addCircleBox(point(0,10000),point(5000,17000),5) c.addEllipse(5,point(12500,15000),2500,3500) c.addPolygonArc(point(22500,15000),2500,3500,0,340,5) e=c.addText(5,point(25,25000),layers.num(6).name) e.setWidth(1000) l.drawing.saveFile("/home/username/testout.gds") print("Python script completed")
import LayoutScript from LayoutScript import * import random,sys l=project.newLayout(); c=l.drawing.currentCell c.cellName="randomCircleArray" sizeX=10000 #array width sizeY=10000 #array height diameter=100 #circle diameter count=2000 #number circles layer =11 #layer for circles space=50 #minimum circle to circle distance ds=diameter+space; for i in range (0,count): try_=0 found=False while (found== False): try_+=1 x=random.randint(0,sizeX) y=random.randint(0,sizeY) p=point(x,y); e=c.nearestElement(p) if (e==None): found=True else: p2=point() radius=pointerInt() # set value with # radius.assign(45); # read with # print (radius.value()) if e.thisElement.isCircle(p2,radius): if (p2.x()>x+ds): found=True elif (p2.x()<x-ds): found=True elif (p2.y()<y-ds): found=True elif (p2.y()>y+ds): found=True if (try_>1000): sys.exit() c.addCircle(layer,p,diameter/2) # save result in your home folder import os l.drawing.saveFile( os.path.expanduser('~')+"/testout.gds") #l.drawing.saveFile("/Users/apple/testout.gds") print ("circle array completed" )
These example and many further Python scripts using LayoutScript are including in any LayoutEditor package under macros/examples. These examples can be open with the integrated TextEditor under Utilities/LayoutEditor/Open Example Macro.
LayoutScript for Python is available for Windows, Linux and Mac. It is include in the Windows packages, in all Linux packages and in the package for the newest Mac OS systems. LayoutScript is not included in the Windows XP package and the package for older Mac Systems. On Linux it is recommended to use the package for your distribution. The general Linux package also includes it, but it may interfere with the installed python version. To use LayoutScript from outside the LayoutEditor set the enviourment variables PATH, LD_LIBRARY_PATH, PYTHONHOME and PYTHONPATH to the correct values before starting python. OpenAccess Script cannot be started from outside the LayoutEditor.