Python can be used as an alternative scripting interface to the built-in C++ macros, using the same Application Programming Interface (API). Scripts are started from the integrated TextEditor and use the LayoutScript module (import LayoutScript / from LayoutScript import *).
Starting with LayoutEditor version 20260628, Python can run in-process inside the application. This is now the default execution mode. The previous mode — a separate Python process without a live connection to open windows — remains available as an alternative.
If you need scripting to adjust the user interface with new menu entries, create parametric cells from the schematic, or run callback macros after changing device parameters, C++ macros may still be the better choice in some cases. See LayoutEditor C++ Macros. In-process Python, however, covers most layout and schematic editing tasks with immediate visual feedback.
Available from LayoutEditor 20260628 onward.
In-process Python runs an embedded Python interpreter inside the LayoutEditor via the pyscript plugin. The script executes in the same process as the application and operates on the currently open layout or schematic window. Any change to the design is reflected in the graphical display immediately after the script finishes — the same behaviour as a C++ macro.
Key characteristics:
project.currentLayout(), project.currentSchematic(), and project.currentTextEditor() to access the active windows.layout.drawing property returns the drawing field of the open layout window (with proper GUI locking while the script runs).layout.executeMacro(filename, parameter).print, errors) is captured and shown in a report dialog.Execution mode: In-process scripting is the default. You can verify or change this under Setup → Installation → Python execution method → in-process (pyscript plugin, live windows).
If the pyscript plugin cannot be loaded, the LayoutEditor automatically falls back to external execution and shows an information message. This happens, for example, on RHEL 8 or when OpenAccess PyCell is active.
In external mode, Python runs in a separate process, even when the script is started from the LayoutEditor TextEditor. This is the classic LayoutScript behaviour that existed before in-process scripting was added.
Key characteristics:
PATH, LD_LIBRARY_PATH, PYTHONHOME, and PYTHONPATH to the correct values before starting Python.Execution mode: Choose Setup → Installation → Python execution method → external (separate python process) to always use this mode.
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.
Using Python scripting from the TextEditor is very simple. Open or create a .py file and press the Execute button (or Ctrl+E). No additional setup is required.
In the script, the line import LayoutScript loads the module and from LayoutScript import * enables all LayoutScript commands without a prefix. The API is identical for both execution modes; only the way you obtain the layout object differs:
l = project.currentLayout()l = project.newLayout() (or open a file with l.drawing.openFile(...))
In-process example — modify the currently open layout:
import LayoutScript
from LayoutScript import *
l = project.currentLayout()
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)
layers.num(6).name = "new text"
e = c.addText(5, point(25, 25000), layers.num(6).name)
e.setWidth(1000)
print("Python script completed")
External example — create a new layout and save it to disk:
import LayoutScript
from LayoutScript import *
l = project.newLayout()
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")
Random circle array (external mode):
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 of 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()
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)
import os
l.drawing.saveFile(os.path.expanduser('~') + "/testout.gds")
print("circle array completed")
These examples and many further Python scripts using LayoutScript are included in any LayoutEditor package under macros/examples. They can be opened with the integrated TextEditor under Utilities/LayoutEditor/Open Example Macro.
LayoutScript for Python is available for Windows, Linux, and macOS. It is included in the Windows packages, all Linux packages, and the package for macOS systems.
In-process mode uses the Python interpreter bundled with the LayoutEditor. No manual configuration of environment variables is needed when running scripts from the TextEditor.
External mode: To use LayoutScript from outside the LayoutEditor, set the environment variables PATH, LD_LIBRARY_PATH, PYTHONHOME, and PYTHONPATH to the correct values before starting Python.
On RHEL 8, in-process Python is not available; the LayoutEditor automatically uses external execution instead.