It looks like you're new here. If you want to get involved, click one of these buttons!
Hi all,
I found a lot of ways to create layers from scripts during my (re)search in the forum, and some of them work for some cases but not for all, or they just stop, and, in general, is a hot topic that always recurs to the most of the KLayout users.
I wanted to ask, is there a code example with a correct way to add a new layer with custom layer properties (e.g. dither_pattern and xfill), and return the index of this layer so it can be used to draw a new object?
Thank you in advance,
Chris
Comments
For reference, this is what I currently use, unsuccessfully:
Hi Chris,
actually, this is is the best way I can think of as well. It features everything you require in the general case.
The API underwent some development, so in the forum there might be outdated versions. Yours is making the right use of the API features, so that's very good.
I wonder whether you really like auto-picking of the stream numbers, but that's up to you of course. I personally think that if you work with named layers alone you should have a mapping table (see File/Writer Options) when you write such a layout to a GDS file. Only then the mapping is deterministic. But that's a personal viewpoint.
I have a few general comments:
Thanks for sharing this code,
Matthias
Hi Matthias,
Thank you for confirming that this function should work, as I thought that this is the part of my code I should put my efforts on to correct, and for your enhancement comments.
I updated my version with your last two comments, but as for the first comment, is there any other way I can retrieve the 'layer_index' of the new layer if I don't create it that way?
Currently, this function creates two layers that are both used when I draw a DBox.
Also, I should describe the part of the flow that this function does not work as it should:
We have a PCell and let's say that the generation of the geometry "failed" because "reasons". So we are inside the 'produce_impl' procedure of the PCell, and we need a dummy indication that this PCell failed in its generation. For example, a box with a text that will say "PCell failed" or something (and that's why I don't really care about the stream number and the datatype). This is a corresponding sample code I would like to have:
After the User changes PCell properties and the PCell is successfully generated, this dummy layer and shape will be deleted. Also is there any chance to add a layer, and set it as invisible in the Layers tab?
Chris
Hi Chris,
The second comment is valid if you don't need the layer index .. if your code does then "layer" is the right function to use.
Regarding the question about the PCell error layer: currently you can't create a hidden, but visible dummy layer. But it's basically a good suggestion to have such a global error layer. It could be used for many purposes, not just PCell layout generation.
But basically, if your PCell layout generation code throws an exception, this would be shown as text in the layout. Is there something wrong with this feature?
Kind regards,
Matthias
Hi Matthias,
OK, I see.
For development purposes, it is just fine, but I don't want the user seeing "internal" failures. It is more UX friendly to prompt a "black box" failure.
Chris
So you mean you want to tailor the text you see?
I guess a feature for this is easier to make than an entire new layer.
Matthias
Hi Matthias,
Well, as for the contents of the failure message, I've developed something using display_text_impl, but it is not about the text message only. I want to display a box, with a corresponding blinking effect, to indicate that something went astray.
The problem, as I see it, is that I create the layer inside produce_impl so KLayout does not "see"/"know" the new layer properties so it creates extra layer properties and index, independently from what I've already created, with the same stream number and datatype.
Chris
Hi Chris,
you cannot create a layer within a PCell - you can just access an existing one.
I need to repeat once again that a PCell is not executed within the target layout. In fact, the layout object a PCell is run in is unspecified. Whatever you do to the layout the PCell is executed in won't necessarily affect your target layout. So please don't try. There are good reasons for this decision (i.e. caching), so this will not be changed.
The projected solution to your problem is: include an error marker layer in your design package (aka technology/layer properties). Define a hidden parameter of layer type with the error layer as the default (via LayerProperties). This parameter will become available in the PCell code and you can output anything there like you would on a usual layer.
Will this be feasible?
Matthias
Hi Matthias,
Ok, I thought that it is possible to create a layer to the main layout from wherever you are, whenever you want.
Thank you for your answer, I think this will be my solution to this issue thank you.
Chris