I have a phyton command in grasshopper that is getting a list of y coordinates, x coordinates, and z coordinates. The command is looping through y and x coordinate values and checks ( if y[i] > y[i-1]+3 or x[i]> x[i-1]+3 ) then it adds A to the list. And if not it writes (βG1β+ X[i]+ Y[i]+ E)
But I want the command to also loop through the z coordinates and check if each z coordinate value is bigger than its previous one (if z[i] > z[i-1] and i>0) Then (if true) I want it to add the followings to the list:
1- β; announce new layer; β
2- β;ββ
3- βM756 Sβ + L
4- βM790 ;execute any new layer actionsβ
5- β;ββ
6- βG1 Zβ+ Z[i] + βFβ + f + β; move to next layer (1)β
7- βG1β+ βXβ+ X[i] + βYβ+ y[i]+ βFβ+ f+ β; move to first perimeter pointβ
And if not I want it to continue writing (βG1β+ X[i]+ Y[i]+ E) (Which was doing before)
but I donβt know how to add the if command of Z to the if command that I already have got, (Or how to combine them)
Thanks for your reply, Yes thatβs what I am trying to do.
The code was good, but it seems to have a problem.
As the Z coordinate value changes from 0 to 1.15, it works alright and inserts the following to the list:
1- β; announce new layer; β
2- β;ββ
3- βM756 Sβ + L
4- βM790 ;execute any new layer actionsβ
5- β;ββ
6- βG1 Zβ+ Z[i] + βFβ + f + β; move to next layer (1)β
7- βG1β+ βXβ+ X[i] + βYβ+ y[i]+ βFβ+ f+ β; move to first perimeter pointβ
However, after that, it keeps inserting them to the list even though the z coordinate value is not changing and is still on 1.15 (After index number 26)
It seems to have been a tolerance issue. Although the Z values seem to be matching at 3 decimal places, at some point there must have been a very small difference. Rounding the Z values before comparing them seems to have fixed it.
Also, do you know any way that I can have the 3D points in order based on Z value?
For example, it first prints all the (x(i) Y(i) z(0)) in the list first, then all the (x(i) Y(i) z(1.15)) and then all the (x(i) Y(i) z(2.3)).
But what currently it is doing, is that it prints all the (x(i), Y(i), z(0)) of curve 1 then (x(i), Y(i), z(1.15)) of curve 1 then (x(i), Y(i), z(2.3)) of curve 1
Then it starts printing the (x(i), Y(i), z(0)) of curve 2 then (x(i), Y(i), z(1.15)) of curve 2 then (x(i), Y(i), z(2.3)) of curve 2
See my reply here for two general methods for sorting in Python based on keys (youβll want method 1 likely):
Also, note that a βsafeβ method for checking if two values (or points) are identical, is to subtract the two and check that the result is smaller than some acceptable tolerance value (for points, calculate the distance between the two and check this is smaller than your tolerance).