It looks like you're new here. If you want to get involved, click one of these buttons!
Hi Matthias,
I would like to query a PCell for it's internal parameters which were calculated in coerce_parameters_impl. Similar to how in Python classes, we can query any variable created by self.xxx.
class MyPCell(pya.PCellDeclarationHelper):
def __init__(self):
super(MyPCell, self).__init__()
self.param("width", self.TypeDouble, "Width", default=10.0)
self.param("height", self.TypeDouble, "Height", default=5.0)
self.param("area", self.TypeDouble, "Area", default=0.0, readonly=True)
def coerce_parameters_impl(self):
self.area = self.width * self.height
then create a library and a layout:
pcell = ly.create_cell('MyPCell',library, {} )
inst = cell.insert(CellInstArray(pcell.cell_index(), pya.Trans()))
and get the value area:
print(pcell.pcell_parameter('area'))
print(inst.pcell_parameter('area'))
But instead of the calculated value 50.0, I get the default value 0.
Similarly, I tried using the properties, but I do not get any properties returned from a PCell.
Is there a way to do this?
Thank you
Lukas
Comments
I think you missed some codes, I cannot reproduce your code. Once I run your code, I get some errors. Can you provide all codes, I mean a successful one?
This is a good question, as I tested, it seems that the value defined in
__init__()is not been passed tocoerce_parameters_impl(), and I tried to print value undercoerce_parameters_impl(), and I getNone.Hi @lukasc,
I tried with the PCell example code (the Circle). This creates a hidden parameter called "ru" which is the effective radius. It is determined from the handle or the input, whatever is more recent.
I used this call to get that parameter from the selected instance:
To me that seems to work and "ru" is updated along with the entered value, if you use the UI.
However, when create the instance from script, the parameter is not set.
The reason is, that during layout generation, "coerce_parameters" is called, but the results are not stored inside the PCell:
That is not a functional issue, as the behavior is reproducible, but the internal parameters are not available to the outside world, only internally. The reason for the technical decision is to maintain a stateless model for the purpose of layout generation. Stateful models would lead to a number of reproducibility issues.
You can't attach properties to the generated cell right now, as the cell lives in the library, and the properties are not translated into the client layout. This is something I can change.
I could also add a generic function callback that allows extracting computed values from a PCell.
Right now, I don't have a good solution for tunneling information from the production code to the outside world. Texts on hidden layers may be a solution.
Another solution that is readily available is to make use of the dynamic nature of Python.
I can add a Python method to my PCellDeclarationHelper-derived class, like for "Circle":
After this, I can call this method on the instance:
Ideally, you should wrap that into "try .. catch", in case your PCell does not support "get_area". But thanks to duck typing, you can add "get_area" to all of your classes, and it will work the same way everywhere.
Matthias