I am working with ETABS API using python. So there is a command like:
SapModel.FrameObj.AddByCoord(x1,y1,z1,x2,y2,z2,"name","section")
where x1 , x2 ,etc are coordinates in Cartesian coordinate system. I have two separate lists that each one consist of 5 sub lists and each sub list contain 5 elements that are X and Y coordinates of different points. Some thing like:
X=[[2,4,5,9,10],[3,6,7,9,11],[10,16,17,19,20],[8,9,15,16,20],[3,12,14,18,21]]
Y=[[0,5,6,8,10],[1,3,7,8,16],[10,13,14,18,23],[6,8,11,14,16],[5,14,15,19,20]]
The output I'm looking for is:
for i in range(3,16,3):
SapModel.FrameObj.AddByCoord(X[0][0],Y[0][0],i,X[1][0],Y[1][0],i,"name","section")
SapModel.FrameObj.AddByCoord(X[1][0],Y[1][0],i,X[2][0],Y[2][0],i,"name","section")
SapModel.FrameObj.AddByCoord(X[2][0],Y[2][0],i,X[3][0],Y[3][0],i,"name","section")
SapModel.FrameObj.AddByCoord(X[3][0],Y[3][0],i,X[4][0],Y[4][0],i,"name","section")
SapModel.FrameObj.AddByCoord(X[0][1],Y[0][1],i,X[1][1],Y[1][1],i,"name","section")
SapModel.FrameObj.AddByCoord(X[1][1],Y[1][1],i,X[2][1],Y[2][1],i,"name","section")
SapModel.FrameObj.AddByCoord(X[2][1],Y[2][1],i,X[3][1],Y[3][1],i,"name","section")
...
...
...
SapModel.FrameObj.AddByCoord(X[0][4],Y[0][4],i,X[1][4],Y[1][4],i,"name","section")
SapModel.FrameObj.AddByCoord(X[1][4],Y[1][4],i,X[2][4],Y[2][4],i,"name","section")
SapModel.FrameObj.AddByCoord(X[2][4],Y[2][4],i,X[3][4],Y[3][4],i,"name","section")
SapModel.FrameObj.AddByCoord(X[3][4],Y[3][4],i,X[4][4],Y[4][4],i,"name","section")
I have no idea how to do that. Can you help me with that?
CodePudding user response:
You can iterate as follows
for _x, _y, _xs, _ys in zip(X,Y,X[1:],Y[1:]):
for x, y, xs, ys in zip(_x, _y, _xs, _ys):
print(x, y, xs, ys)
or
for _x, _y, _xs, _ys in zip(zip(*X), zip(*Y) , zip(*X[1:]), zip(*Y[1:])):
for x, y, xs, ys in zip(_x, _y, _xs, _ys):
print(x, y, xs, ys)
The second way would produce 4-pairs in the exact order as in your example:
2 0 3 1
3 1 10 10
10 10 8 6
8 6 3 5
4 5 6 3
6 3 16 13
16 13 9 8
9 8 12 14
5 6 7 7
7 7 17 14
17 14 15 11
15 11 14 15
9 8 9 8
9 8 19 18
19 18 16 14
16 14 18 19
10 10 11 16
11 16 20 23
20 23 20 16
20 16 21 20
CodePudding user response:
It looks like you want to avoid duplication of code here. You could make loops for those indices that vary:
for i in range(3, 16, 3):
for j in range(6):
for k in range(4):
SapModel.FrameObj.AddByCoord(X[k][j],Y[k][j],i,X[k 1][j],Y[k 1][j],i,"name","section")
CodePudding user response:
Would this work for you?
for z in range(3,16,3):
for x, y in zip(zip(*X), zip(*Y)):
for i in range(len(x)-1):
SapModel.FrameObj.AddByCoord(x[i], y[i], z, x[i 1], y[i 1], z,"name","section")
Output:
SapModel.FrameObj.AddByCoord(2, 0, 3, 3, 1, 3,"name","section")
SapModel.FrameObj.AddByCoord(3, 1, 3, 10, 10, 3,"name","section")
SapModel.FrameObj.AddByCoord(10, 10, 3, 8, 6, 3,"name","section")
SapModel.FrameObj.AddByCoord(8, 6, 3, 3, 5, 3,"name","section")
SapModel.FrameObj.AddByCoord(4, 5, 3, 6, 3, 3,"name","section")
...
SapModel.FrameObj.AddByCoord(16, 14, 15, 18, 19, 15,"name","section")
SapModel.FrameObj.AddByCoord(10, 10, 15, 11, 16, 15,"name","section")
SapModel.FrameObj.AddByCoord(11, 16, 15, 20, 23, 15,"name","section")
SapModel.FrameObj.AddByCoord(20, 23, 15, 20, 16, 15,"name","section")
SapModel.FrameObj.AddByCoord(20, 16, 15, 21, 20, 15,"name","section")