Place BasicTEXT into pcell

edited July 2020 in Layout

I was trying to add a basic text cell into a pcell. However the text is not rendered on the same layer.
def produce_impl(self):

    lib = pya.Library.library_by_name("Basic")
    pcell_decl = lib.layout().pcell_declaration("TEXT")

    param = {"layer": self.layer, "text": "sample text"}

    pv = []
    for p in pcell_decl.get_parameters():
        if p.name in param:
            pv.append(param[p.name])
        else:
            pv.append(p.default)

    t = pya.Trans(0, 0)
    pcell_var = self.layout.add_pcell_variant(lib, pcell_decl.id(), pv)

    self.cell.insert(pya.CellInstArray(pcell_var, pya.Trans.R0))

The layer is also not set in the pcell. What am I doing wrong?
I am using the following class: class pya.PCellDeclarationHelper:

Comments

  • edited July 2020

    Hi,

    The code isn't complete so I can just guess. Basically it's correct - apart from a small enhancement: you don't need to translate the parameters to a list. You can directly pass the hash.

    Here is some working example:

    import pya
    
    class PCell1578(pya.PCellDeclarationHelper):
    
      def __init__(self):
        super(PCell1578, self).__init__()
        self.param("layer", self.TypeLayer, "Layer", default = pya.LayerInfo(1, 0))
    
      def display_text_impl(self):
        return "Discussion 1578 on layer " + str(self.layer)
    
      def produce_impl(self):
    
        lib = pya.Library.library_by_name("Basic")
        pcell_decl = lib.layout().pcell_declaration("TEXT")
    
        param = {"layer": self.layer, "text": "On layer " + str(self.layer)}
    
        pcell_var = self.layout.add_pcell_variant(lib, pcell_decl.id(), param)
    
        self.cell.insert(pya.CellInstArray(pcell_var, pya.Trans.R0))
    
    class PCellLib1578(pya.Library):
      def __init__(self):
        self.description = "Discussion 1578"
        self.layout().register_pcell("PCell", PCell1578())
        self.register("PCellLib1578")
    
    PCellLib1578()
    

    Here is the result:

    BUT: you don't actually need to instantiate a PCell inside your code. You can generate text with the "TextGenerator" class. A PCell does the same but just in a very complicated way. To do so, replace "produce_impl" by this code:

      def produce_impl(self):
    
        text_generator = pya.TextGenerator.default_generator()
        text = text_generator.text("On layer " + str(self.layer), self.layout.dbu)
    
        # NOTE: "layer_layer" is the layer index corresponding to the "LayerInfo" object
        # inside "layer" (add "_layer" to the parameter name)
        self.cell.shapes(self.layer_layer).insert (text)
    

    It's not only shorter, it's also faster and does not generate internal-only subcells.

    Matthias

Sign In or Register to comment.