It looks like you're new here. If you want to get involved, click one of these buttons!
I am generating a layout with a Python script. I have a couple questions that I have not been able to sort out.
This is the beginining of my code:
import pya
def SetupLayer(num, dt, name):
if pya.Application.instance().main_window().current_view() is not None:
pya.Application.instance().main_window().current_view().add_missing_layers()
li = pya.Application.instance().main_window().current_view().begin_layers()
while not li.at_end():
lp = li.current()
if ((lp.source_layer == num) and (lp.source_datatype == dt)):
lp.name = name
lp.visible = True
lp = li.next()
L = pya.Layout()
L.visible = True
TOP = L.create_cell("TOP")
PartOutline = L.layer(100, 0)
SetupLayer(100, 0, "PartOutline")
ScribeOutline = L.layer(200, 0)
SetupLayer(200, 0, "ScribeOutline")
Pads = L.layer(300, 0)
SetupLayer(300, 0, "Pads")
Pin_Number = L.layer(400, 0)
SetupLayer(400, 0, "Pin_Number")
Functional_Signal = L.layer(500, 0)
SetupLayer(500, 0, "Functional_Signal")
Net_Name = L.layer(600, 0)
SetupLayer(600, 0, "Net_Name")
If I run the same code with a blank layout window created, it seems to run the block of code where I set the layer name but as near as I can tell, it is not the correct layout view that it is operating against. I can't seem to make the layout view I have created visible.
Mike
Comments
Hi Mike,
The core idea is to work with layout views rather than layout objects (pya.Layout). Layout objects are standalone and not connected with the views.
Your SetupLayer should then use "view" to set the layer properties.
Regards,
Matthias
Thanks for looking at my problem. I've made some progress but it seems like I've taken one step forward and two steps back. Now my GDS loads and the layer properties save correctly but now I don't have any shapes in my layout. I am expecting a polygon on 100/0 but I have no layers at all.
I am clearly struggling with comprhending the layout vs view models and I am sure my mistake is probably pretty simple but I can't see it. ;-)
What am I missing?
I've made some further progress this evening. In fact, for the most part what I am trying to do is working. The only issue I am running into now is when I try to run my script as batch script from the command line it doesn't generate a GDS file. If I run the same script from the Macro Development GUI it runs to completion and I end up with the GDS file.
This is my current solution:
I am getting close. I don't see anything obvious as to why this wouldn't run in -b mode.
There are different batch modes available. Some have a main window, some don't. "klayout -b" will enter "bare metal" batch mode where there is no main window and "pya.MainWindow.instance()" will be None.
I tried your script in this mode:
and for me I got "t.gds" and "t.lyp" files. You can also add "-nc -rx" which avoids side effects such as updating the configuration file.
Matthias
Thanks, I can replicate the results using the same switches so that works for me!
Last question (I hope) - can I do the same on Windows? When I use the same command I don't see any results and "klayout_app -h" on the Windows command line doesn't return anything like it does on Linux.
KLayout isn't compiled as a console application on Windows (as then an ugly command terminal pops up), so it won't print anything to the console.
But if you use a bash from cygwin or MSYS it will do. Also redirection to a file should work.
Matthias
Hi all,
I am trying to use klayout python module.
First thing I would like to load a dxf file and visualize it from a python script.
I have tried with the following code (inspired by this thread):
Unfortunately it breaks at the second line with following error message: