Hello, Im back!
Firstly, Thank you @Dancergraham & @diff-arch trying to help me! I used youre hints & codes to make it. It took me quite long since Im begineer with python, but Im back here to share my first script which is finally working as intended! File attached at the end.
I know it is simple code but for me its a huge achievement
heres my coda:
__author__ = "Dan"
__version__ = "2019.04.19"
#import libraries
import rhinoscriptsyntax as rs
import math
#start point & end point of truss
pt1 = rs.coerce3dpoint(start)
pt2 = rs.coerce3dpoint(end)
#calculation of span length & division count & segment length = length increment
span = rs.Distance(pt1, pt2)
segments = int(segments)
length_increment = span/segments
#slope calculation from percentage to degrees
slope_perc = slope
slope_ang = math.atan(slope/100)
#calculation of height increment
height_increment = (span/segments)*math.tan(slope_ang)
n = height
height_step = height_increment
length_step = length_increment
#empty variables
a = []
b = []
c = []
d = []
e = []
#slope calculation
slope_perc = slope
slope_ang = math.atan(slope/100)
#generation of bot chord points
j = 0
for i in range(segments+1):
j = j + length_step
bot = rs.AddPoint(j-length_step,0,0)
b.append(bot)
#generation of top chord points
j = 0
for i in range(segments+1):
# print (n)
if i <= segments/2:
n = n + height_step
j = j + length_step
top = rs.AddPoint(j - length_step,0,n - height_step)
else:
n = n - height_step
top = rs.AddPoint(j,0,n - height_step)
j = j + length_step
a.append(top)
#assigning variables
top_pt = a
bot_pt = b
#generation of diagonals_1
j = 0
for i in range(segments):
diagonal = rs.AddLine(bot_pt[j],top_pt[j+1])
j = j + 1
c.append(diagonal)
#generation of diagonals_2
j = 0
for i in range(segments):
diagonal = rs.AddLine(bot_pt[j+1],top_pt[j])
j = j + 1
d.append(diagonal)
#generation of bottom chord and top chords
bot_ch = rs.AddLine(bot_pt[0],bot_pt[segments])
top_ch = [rs.AddLine(top_pt[0],top_pt[int(segments/2)]), rs.AddLine(top_pt[int(segments/2)],top_pt[segments])]
#generation of verticals
j = 0
for i in range(segments+1):
vertical = rs.AddLine(bot_pt[j],top_pt[j])
j = j + 1
e.append(vertical)
#assigning variables
dia_1 = c
dia_2 = d
vert = e
print(truss_type)
#Warren
if truss_type == 0:
if segments/2 % 2 == 1:
dia_11 = dia_2[slice(1, int(segments/2),2)] + dia_1[slice(int(segments/2+1), int(segments),2)]
dia_12 = dia_1[slice(0, int(segments/2),2)] + dia_2[slice(int(segments/2), int(segments),2)]
else:
dia_11 = dia_2[slice(1, int(segments/2),2)] + dia_1[slice(int(segments/2), int(segments),2)]
dia_12 = dia_1[slice(0, int(segments/2),2)] + dia_2[slice(int(segments/2+1), int(segments),2)]
#Warren Flipped
if truss_type == 1:
if segments/2 % 2 == 1:
dia_11 = dia_2[slice(0, int(segments/2),2)] + dia_1[slice(int(segments/2), int(segments),2)]
dia_12 = dia_1[slice(1, int(segments/2),2)] + dia_2[slice(int(segments/2+1), int(segments),2)]
else:
dia_11 = dia_2[slice(0, int(segments/2),2)] + dia_1[slice(int(segments/2+1), int(segments),2)]
dia_12 = dia_1[slice(1, int(segments/2),2)] + dia_2[slice(int(segments/2), int(segments),2)]
#Howe
if truss_type == 2:
if edge_diagonals < segments/2:
dia_11 = dia_1[slice(0, int(edge_diagonals))] + dia_2[slice(int(segments-edge_diagonals), int(segments))]
dia_12 = dia_1[slice(int(edge_diagonals), int(segments/2))] + dia_2[slice(int(segments/2), int(segments-edge_diagonals))]
else:
dia_11 = dia_1[slice(0, int(segments/2))] + dia_2[slice(int(segments/2), int(segments))]
dia_12 = []
#Pratt
if truss_type == 3:
if edge_diagonals < segments/2:
dia_11 = dia_2[slice(0, int(edge_diagonals))] + dia_1[slice(int(segments-edge_diagonals), int(segments))]
dia_12 = dia_2[slice(int(edge_diagonals), int(segments/2))] + dia_1[slice(int(segments/2), int(segments-edge_diagonals))]
else:
dia_11 = dia_2[slice(0, int(segments/2))] + dia_1[slice(int(segments/2), int(segments))]
dia_12 = []
looks like this:
previously looked like this mess:
This is how it WORKS:
The reason of me sharing it is to get some ideas how to improve the script from you people. If you are interested to share some ideas please hit me up in PM or post in the comments.
Next step is to connect it to the @karamba3d to make optimization with #galapagos. Should be easier part for me.
Dan.
Truss_Python_v02.gh (15.6 KB)