smile2 offers a series of modules for the Python scripting language. Depending of your license options, several litho.* Python modules can be used to
- modify or create documents and structure elements.
- extend smile2 with new nodes, tools, commands and user interface elements.
- customize and automate the lithography process.
- create your own “lithography” application.
Python is high-level dynamic programming language. Arguments for its usage as the ‘scripting language’ in smile2 are:
- It is easy and fast to learn for beginners.
- Python is modular, extensible and wide-spread. In fact for almost all tasks one is able to find a python module that is ‘doing the job’. Especially for scientific use there are many powerful modules like NumPy, SciPy, OpenCV, etc. See the link section for some links to useful python modules
- It makes it possible to run the same scripts as independent applications or as a smile2 extensions.
- Many valuable extensions (modules) and other resources are available for Python.
There are many good resources and free books available on the Internet. Here, a small collection:
Using Python in and with smile2
All smile2 Python modules are grouped in the litho package. Some of them can be used independent of the smile2 application, and others only make sense to be used from a running smile2 session.
The litho package includes the following modules:
core- The lithography framework
cmd- An easy to use interface to quickly call smile2 commands
smile- Tools and interfaces to access, modify and extend the smile2 application
shapefinder- A easy to use and robust pattern recognition system
The smile module works only inside smile. If you purchased an extended version license option, then all other modules can be used from any python script.
Creating your first scripts
The following tutorials assume an understanding of the Python syntax.
- Click the New Document icon in the main toolbar to create a new document. If the write field size is not 200 µm, you may change it to 200.
- After opening the script editor, choose from the script editors main menu.
Now, you are ready to type in some Python code.
- The Script
- Our script should add the text “Hello World” to the current smile2 document. For this, we use the litho.cmd module to call the createText command. The code to do this looks the following:
import litho.cmd as cmd cmd.createText(text="Hello World", height=20, font="Arial")
A second example
This script calculates a spiral and creates a wire from it:
import litho.cmd as cmd from math import * # some settings for the spiral n_start=1 # start number for spiral generation n_stop = 100 # final number for spiral generation width=0.3 # ribbon width degree=3 # ribbon curve degree resolution=6 # ribbon curve resolution sign = 1 # 1 or -1: spiral winding # will hold the spiral data as line (list of points) a = list() # generate the spiral for j in range(n_start,n_stop): i = j + 1 r = sqrt(i) theta = r * 2 * pi x = cos(theta)*r y = -sin(theta)*r a.append((x,sign*y)) # create a ribbon from the genrated spiral cmd.createRibbon(paths=a, width=width, degree=degree, resolution=resolution)
Resources and examples
In the Script Example pages, more examples can be found, ordered by topic and complexity.
Smile Python Manual: Table of contents
- Using Python Scripts
- Script Examples
- The litho package
- Quick Reference