Home › Forums › Nazca › Questions and Answers › define pins in a loop
Tagged: raise_pins, loop
- This topic has 6 replies, 2 voices, and was last updated 6 years, 2 months ago by
Chenhui.
-
AuthorPosts
-
20 February 2019 at 23:32 #5440
Chenhui
MemberHello 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
20 February 2019 at 23:45 #5443Ronald
KeymasterDear Chenhui,
Check out the raise_pins() method.
https://nazca-design.org/manual/code.html?highlight=raise_pins#nazca.Instance.raise_pinsIn 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
21 February 2019 at 11:24 #5451Chenhui
MemberHello 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
21 February 2019 at 11:44 #5455Ronald
KeymasterDear 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)])
21 February 2019 at 12:14 #5456Chenhui
MemberDear 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))
21 February 2019 at 12:17 #5458Ronald
KeymasterHi Chenhui,
You are correct.
Just typed it as a concept directly in the edit box rather than in Python.Ronald
21 February 2019 at 12:20 #5459Chenhui
MemberAll right. The concept is most important. Thanks for your support!
-
AuthorPosts
- You must be logged in to reply to this topic.