This touches upon the core idea behind Nazca: “Make a cell, put a cell”.
Creating a cell and putting it zero or more times in a layout (in other words: instantiating it zero or more times in a parent cell) are two distinct activities.
As soon as you finish creating a cell, you can by definition not add anything new to it anymore; The cell is closed. It may feel like a restriction, but actually it is not and it guarantees a consistent cell hierarchy. Hence, anything you put in a cell just has to be done before it is closed.
Your example attempts to instantiate cell ‘mmb’ to a pin inside the already closed cell ‘mmi1x2’, i.e. it tries to add ‘mmb’ into ‘mmi1x2’:
However, you don’t want to connect ‘mmb’ to the cell ‘mmi1x2’ but to the ‘copy’ of mmi1x2, i.e. its instance. More precise ‘mmi1x2().put()’ instantiates cell ‘mmi1x2’ in the “active cell”, i.e the open cell you are constructing. Note that you are always in an active layout cell one way or another, e.g. Nazca automatically creates a cell named ‘nazca’ for you at the start.
Solution to connect mmb to mmi1x2:
A = mmi1x2.put() mmb.put(A.pin['a0'])
The put() method returns a reference to the instance, here assigned to ‘A’, of the cell it puts, here ‘mmi1x2’. It’s like using a stamp to make prints: ‘mmi1x2’ is the stamp and ‘A’ is its print in the layout. You can reuse stamp ‘mmi1x2’ as much as you like, and each print it creates is an instance (a reference to the stamp).
In order to connect to the print/instance, or any number of prints/instances in scope in the active cell, just keep a reference of it when putting it. It looks something like this:
A = mmi1x2.put(0) # place mmi1x2 at x=0 and call the resulting instance A B = mmi1x2.put(100) # place a 2nd mmi1x2 at x=100 and call the resulting instance B mmb.put(A.pin['a0']) # place mmb connected pin 'a0' of A mmb.put(A.pin['b0']) # place a 2nd mmb connected pin 'b0' of A mmb.put(B.pin['a0']) # place a 3rd mmb connected to pin 'a0' of B
Nazca gives the following message when connecting to closed cell
(which is a compressed version of the story above):
Exception: You are trying to connect to a closed Cell object:
The construction found is similar to
Connect not to the Cell but to an instance of the cell instead
$ instance = cell.put()