Home Forums Nazca Questions and Answers define pins in a loop

Tagged: ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #5440
    Chenhui
    Member

    Hello Ronald,

    I have a question about Pin definition.

    In a cell, I put a lot of blocks (for example a defined function). Can I define the Pin for each block through an easier way? like a loop?

    Besides, if there is something inappropriate in the code, could you please point it out?

    Thanks.

    Chenhui

    # create a pad block from predefined geometries
    def bump (pad=30):
        name = "bump_{}".format(pad)
        with nd.Cell(name=name) as C:
            winC = geom.circle(radius=pad, N=300)
            nd.Polygon(points=winC, layer=2).put(0)
    
            winC = geom.circle(radius=0.8*pad,N=300)
            nd.Polygon(points=winC,layer=3).put(0)
            nd.Pin('out'+str(0)).put(0)
    
        return C
    
    # create a building block
    # IDT
    def idt1ch(pad = 30):
        name = "IDT1ch_{}".format(pad)
        with nd.Cell(name=name) as C:
    
            padN1 = bump(pad=pad).put(293.14, 114.02, 0)
            nd.Pin('out'+ str(0)).put(padN1.pin['out0'])
    
            padN2 = bump(pad=pad).put(368.14, 113.31, 0)
            nd.Pin('out'+ str(1)).put(padN2.pin['out0'])
    
            #...???
    
    return C
    #5443
    Ronald
    Keymaster

    Dear Chenhui,

    Check out the raise_pins() method.
    https://nazca-design.org/manual/code.html?highlight=raise_pins#nazca.Instance.raise_pins

    In your example ‘padN1’ is an instance of cell ‘bump’ in parent cell ‘C’. The raise_pins raises the pins of padN1 to the parent level.

    padN1.raise_pins()

    Ronald

    #5451
    Chenhui
    Member

    Hello Ronald,

    Thanks for your quick reply. This is a very useful function.

    Firstly, in my case, I should use

    padN1.raise_pins(['out0'],['out'+str(1)])

    Secondly, I want to make it even easier, for example, using a loop to define all of the PIN together. This should be a basic function in Python. please check below wrong code.

    
    for i in range (2):
        'padN'+str(i).raise_pins(['out0'],['out'+str(i)])
    
    #AttributeError: 'str' object has no attribute 'raise_pins'

    Chenhui

    #5455
    Ronald
    Keymaster

    Dear Chenhui,

    Thank you, good catch, I edited it in the original post.

    Your example raises pins for multiple instances. If the instances are added to a list you can iterate over them.

    padN = [] 
    with ...
        ...
        padN.append(bump(pad=pad).put(293.14, 114.02, 0))
        padN.append(bump(pad=pad).put(368.14, 113.31, 0))
    for i, pad in enumerate(padN):
        pad.raise_pins(['out0'], ['out'+str(i)])
    #5456
    Chenhui
    Member

    Dear Ronald,

    Thanks a lot.

    This is great! The list can be used like this. This will be very convenient for me.

    However, I modified the code, since can’t run yours. Did I misunderstand your code “with…”?

    padN=[]
    padN.append(bump(pad=pad).put(293.14,114.02,0))
    padN.append(bump(pad=pad).put(368.14,113.31,0))
    #5458
    Ronald
    Keymaster

    Hi Chenhui,

    You are correct.
    Just typed it as a concept directly in the edit box rather than in Python.

    Ronald

    #5459
    Chenhui
    Member

    All right. The concept is most important. Thanks for your support!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.