Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.
1 to 7 of 7
use the pya.Region object. The "-" operator will do the subtraction. You can insert the results into your output cell.
This a way to do it though I am not sure if this is the most straightforward one.
scell = layout.convert_cell_to_static(pcell_var)
scell = layout.cell(scell)
it = layout.begin_shapes(scell, layout.layer(N,0)) # N is the the layer index
r = pya.Region(it) + pya.Region() # add an empty region to loose the reference to the cell
You end up with a standard region which can be used in boolean operations.
@Christian: thanks for this suggestion. If you put in two regions (even if derived from an iterator) into a boolean operation, they will become flat anyway. So you don't need to add the empty region.
But I need to say that once again: PCells and layout generation different worlds. PCells are supposed to bring in layout automation into the editor. They provide a complex interface to achieve this. But why would everybody use that interface when people are just interested in layout generation? All PCells build into KLayout are very simple (maybe apart from TEXT). So why spending so much effort in handling PCells when it's less effort and more flexible to code the layout generation itself? For example, a circle can be generated as a simple polygon and with a few lines of code, compared to many more if you want to use the CIRCLE PCell. IMHO, even TEXT is not big enough to justify the PCell handling complexity.
I completely agree. I use PCells only to generate text. With regards to the empty Region: I observed that the shapes are "cleaned" (no error but they disappear) when I delete the cell they are coming from.
One remark on the scripting engines. It would be very pythonic if the iterator object was actually an python iterator. Currently
for elem in layout.begin_shapes(scell, layout.layer(N,0)):
generates an error.
yes, the TEXT PCell is everybody's darling ... Maybe I can mitigate the PCell instantiation issue by providing a text synthesizing function in the normal pya.Region (i.e. pya.Region.createGlyphs("MY TEXT")).
Your remark about the Python iterator is valid. Most of the simple sequences (like Shapes.each) are well mapped to Python iterators. But the RecursiveShapeIterator is a very versatile tool and can be configured in many respects. So it's beyond a normal iterator. And please don't emphasize "Pythonic" too much ... I intentionally provided two language bindings to overcome some tribal mentality. Plus, Python is not my personal favorite, but never mind ...
Any you're right. The Region is actually a reference to avoid creating unnecessary deep copies. But those are resolved whenever a modification happens. If you just want to store a region away, than your approach is a feasible and smart solution. If you want to perform boolean operations anyway, adding an empty region is simply overhead and you don't need to worry about any changes in the sources.