check plugs

# 1. Reset
Delete(All)

# 2. Force Variable Creation (Prevents "Undefined" errors)
d_beam = 400
w_plate = 200
t_plate = 16
t_flange = 10
bolt_gauge = 60

# 3. Create Sliders linked to those variables
# Syntax: Slider(Min, Max, Increment)
d_beam = Slider(200, 800, 10)
SetCaption(d_beam, "Beam Depth")
# Re-assert value to be safe
SetValue(d_beam, 400)

w_plate = Slider(100, 500, 10)
SetCaption(w_plate, "Plate Width")
SetValue(w_plate, 200)

t_plate = Slider(5, 50, 1)
SetCaption(t_plate, "Plate Thk")
SetValue(t_plate, 16)

t_flange = Slider(5, 30, 1)
SetCaption(t_flange, "Flange Thk")
SetValue(t_flange, 10)

# 4. Define Geometry Points
# Origin
O = (0, 0)

# Plate Corners (Flush with beam depth)
# Note: We use the variables defined above
Plate_BL = (0, -d_beam / 2)
Plate_TL = (0, d_beam / 2)
Plate_TR = (t_plate, d_beam / 2)
Plate_BR = (t_plate, -d_beam / 2)

# 5. Draw the Plate
PolyPlate = Polygon(Plate_BL, Plate_TL, Plate_TR, Plate_BR)
SetColor(PolyPlate, "Blue")
SetFilling(PolyPlate, 0.5)

# 6. Draw the Beam (Side View - I Section)
# Top Flange
TF_BL = (0, d_beam / 2 - t_flange)
TF_TL = (0, d_beam / 2)
TF_TR = (-500, d_beam / 2)
TF_BR = (-500, d_beam / 2 - t_flange)
PolyTF = Polygon(TF_BL, TF_TL, TF_TR, TF_BR)
SetColor(PolyTF, "DarkGray")

# Bottom Flange
BF_TL = (0, -d_beam / 2 + t_flange)
BF_BL = (0, -d_beam / 2)
BF_BR = (-500, -d_beam / 2)
BF_TR = (-500, -d_beam / 2 + t_flange)
PolyBF = Polygon(BF_TL, BF_BL, BF_BR, BF_TR)
SetColor(PolyBF, "DarkGray")

# Web
Web_BL = (-500, -d_beam / 2 + t_flange)
Web_TL = (-500, d_beam / 2 - t_flange)
Web_TR = (0, d_beam / 2 - t_flange)
Web_BR = (0, -d_beam / 2 + t_flange)
PolyWeb = Polygon(Web_BL, Web_TL, Web_TR, Web_BR)
SetColor(PolyWeb, "LightGray")
SetFilling(PolyWeb, 0.25)

# 7. Add Bolts (Visual circles)
# Top Bolt
BoltTop = Circle((t_plate / 2, d_beam / 2 - 60), 8)
SetColor(BoltTop, "Red")

# Bottom Bolt
BoltBot = Circle((t_plate / 2, -d_beam / 2 + 60), 8)
SetColor(BoltBot, "Red")

# 8. Labels
Text("Flush End Plate", (50, d_beam / 2), true, true)d


# 1. Clear everything first
Delete(All)

# 2. Force-create variables with simple numbers first
# This prevents "Undefined" errors
angle = 10
D_col = 500
D_raft = 350
L_haunch = 900
D_haunch = 300
t_plate = 20

# 3. Convert them to Sliders safely
# We re-assign them as sliders one by one
angle = Slider(0, 25, 1)
SetCaption(angle, "Angle")
SetValue(angle, 10)

D_col = Slider(200, 800, 10)
SetCaption(D_col, "Col Depth")
SetValue(D_col, 500)

D_raft = Slider(200, 600, 10)
SetCaption(D_raft, "Rafter Depth")
SetValue(D_raft, 350)

L_haunch = Slider(500, 1500, 50)
SetCaption(L_haunch, "Haunch Len")
SetValue(L_haunch, 900)

D_haunch = Slider(100, 500, 10)
SetCaption(D_haunch, "Haunch Depth")
SetValue(D_haunch, 300)

t_plate = Slider(10, 40, 1)
SetCaption(t_plate, "Plate Thk")
SetValue(t_plate, 20)

# 4. Define Direction Vectors (Trigonometry)
# We do this step-by-step to avoid long commands
angRad = angle * pi / 180
vx = cos(angRad)
vy = sin(angRad)
px = sin(angRad)
py = -cos(angRad)

# 5. Define Column (Fixed Vertical)
# Origin (0,0) is the Top-Right corner of the Column
C_TR = (0, 0)
C_TL = (-D_col, 0)
C_BL = (-D_col, -1500)
C_BR = (0, -1500)

PolyCol = Polygon(C_TL, C_TR, C_BR, C_BL)
SetColor(PolyCol, "Gray")
SetFilling(PolyCol, 0.25)

# 6. Define End Plate
# Attached to the right of the column (starts at x=0, ends at x=t_plate)
# It extends slightly up (50mm) and deep down below the haunch
Plate_Top = 50
Plate_Bot = -D_raft - D_haunch

EP_TL = (0, Plate_Top)
EP_TR = (t_plate, Plate_Top)
EP_BR = (t_plate, Plate_Bot)
EP_BL = (0, Plate_Bot)

PolyPlate = Polygon(EP_TL, EP_TR, EP_BR, EP_BL)
SetColor(PolyPlate, "Blue")
SetFilling(PolyPlate, 0.5)

# 7. Define Rafter (Sloped)
# Starts at the face of the plate (x = t_plate)
StartPt = (t_plate, 0)

# Top Flange (Goes up-right along vector vx,vy)
R_TopEnd = StartPt + (2000 * vx, 2000 * vy)

# Bottom Flange (Offset down by D_raft along vector px,py)
# We calculate the offset vector first
Off_X = D_raft * px
Off_Y = D_raft * py

R_BotStart = StartPt + (Off_X, Off_Y)
R_BotEnd = R_TopEnd + (Off_X, Off_Y)

PolyRafter = Polygon(StartPt, R_TopEnd, R_BotEnd, R_BotStart)
SetColor(PolyRafter, "LightGray")
SetFilling(PolyRafter, 0.25)

# 8. Define Haunch (Triangle Stiffener)
# Starts at Rafter Bottom
H_Top = R_BotStart

# Ends further along the rafter (L_haunch)
# We calculate the tip position
Tip_X = L_haunch * vx
Tip_Y = L_haunch * vy
H_Tip = R_BotStart + (Tip_X, Tip_Y)

# Bottom Corner (At the Plate)
# Connects to the bottom of the plate
H_Corner = (t_plate, Plate_Bot)

PolyHaunch = Polygon(H_Top, H_Tip, H_Corner)
SetColor(PolyHaunch, "Purple")
SetFilling(PolyHaunch, 0.5)

# 9. Labels
Text("Knee Joint", (-D_col, 200), true, true)

# 1. Clear All
Delete(All)

# 2. Initialize Safe Variables (Prevent Undefined Errors)
angle = 10
D_col = 500
D_raft = 400
L_haunch = 1000
D_haunch = 300
t_plate = 20
L_span = 3000

# 3. Create Sliders
angle = Slider(0, 30, 0.5)
SetCaption(angle, "Roof Angle (°)")
SetValue(angle, 10)

D_col = Slider(300, 800, 10)
SetCaption(D_col, "Col Depth")
SetValue(D_col, 500)

D_raft = Slider(200, 600, 10)
SetCaption(D_raft, "Rafter Depth (Perp)")
SetValue(D_raft, 400)

D_haunch = Slider(100, 500, 10)
SetCaption(D_haunch, "Haunch Depth (Vert)")
SetValue(D_haunch, 300)

L_haunch = Slider(500, 2000, 50)
SetCaption(L_haunch, "Haunch Length")
SetValue(L_haunch, 1200)

t_plate = Slider(10, 40, 1)
SetCaption(t_plate, "End Plate Thk")
SetValue(t_plate, 20)

# 4. MATH: Calculate Vertical Geometry (The "Plumb Cut" Logic)
# To avoid gaps, we calculate where the rafter lines hit the vertical plate line x=t_plate.
# Convert angle to radians
rad = angle * pi / 180

# Vertical Depth of Rafter (hypotenuse of the cut)
# If D_raft is the perpendicular depth, the vertical cut length is D_raft / cos(angle)
Vert_Raft_D = D_raft / cos(rad)

# 5. Define KEY POINTS at the Connection Interface (x = t_plate)
# Connection Top (Pivot Point)
P_Conn_Top = (t_plate, 0)

# Connection Rafter Bottom (Where Rafter Web meets Plate)
P_Conn_Raft_Bot = (t_plate, -Vert_Raft_D)

# Connection Haunch Bottom (Where Haunch meets Plate)
P_Conn_Haunch_Bot = (t_plate, -Vert_Raft_D - D_haunch)

# 6. Define RAFTER GEOMETRY (Sloped)
# Top Flange End Point (Span Length)
# x = t_plate + L_span
# y = L_span * tan(angle)
Tip_X = t_plate + L_span
Tip_Y = L_span * tan(rad)
R_Top_End = (Tip_X, Tip_Y)

# Bottom Flange End Point
# It is parallel to top, dropped by Vert_Raft_D
R_Bot_End = (Tip_X, Tip_Y - Vert_Raft_D)

# Create Rafter Polygon
# Note: We use P_Conn_Raft_Bot as the start of the bottom flange for the main rafter body
PolyRafter = Polygon(P_Conn_Top, R_Top_End, R_Bot_End, P_Conn_Raft_Bot)
SetColor(PolyRafter, "LightGray")
SetFilling(PolyRafter, 0.25)

# 7. Define HAUNCH GEOMETRY
# Haunch Tip Logic:
# The Haunch ends at 'L_haunch' distance from the plate.
# At that X position, its Y must match the Rafter Bottom Flange.
Haunch_Tip_X = t_plate + L_haunch
Haunch_Tip_Y = (L_haunch * tan(rad)) - Vert_Raft_D
P_Haunch_Tip = (Haunch_Tip_X, Haunch_Tip_Y)

# Create Haunch Polygon
# Points: RafterBottomStart -> HaunchTip -> HaunchBottomStart
PolyHaunch = Polygon(P_Conn_Raft_Bot, P_Haunch_Tip, P_Conn_Haunch_Bot)
SetColor(PolyHaunch, "Purple")
SetFilling(PolyHaunch, 0.5)

# 8. Define END PLATE GEOMETRY
# The plate height is driven by the total connection height
# Top Extension (Stick up)
Plate_StickUp = 25
EP_TL = (0, Plate_StickUp)
EP_TR = (t_plate, Plate_StickUp)

# Bottom Extension (Usually flush or slightly below haunch)
EP_BR = (t_plate, -Vert_Raft_D - D_haunch)
EP_BL = (0, -Vert_Raft_D - D_haunch)

PolyPlate = Polygon(EP_TL, EP_TR, EP_BR, EP_BL)
SetColor(PolyPlate, "Blue")
SetFilling(PolyPlate, 0.6)

# 9. Define COLUMN GEOMETRY (Auto-Updating)
# The Column Inner Face aligns with the Plate Back Face (x=0)
# The Column Top aligns with the Plate Top (EP_TL)
Col_Inner_Top = (0, Plate_StickUp)
Col_Outer_Top = (-D_col, Plate_StickUp)
Col_Outer_Bot = (-D_col, -2000)
Col_Inner_Bot = (0, -2000)

PolyCol = Polygon(Col_Inner_Top, Col_Outer_Top, Col_Outer_Bot, Col_Inner_Bot)
SetColor(PolyCol, "Gray")
SetFilling(PolyCol, 0.25)

# 10. Connection Bolts (Dynamic)
# Calculate Bolt Line based on angle? Usually bolts are vertical relative to plate.
Bolt_X = t_plate / 2
Bolt_Top = Circle((Bolt_X, -50), 8)
Bolt_Bot = Circle((Bolt_X, -Vert_Raft_D - D_haunch + 50), 8)
SetColor(Bolt_Top, "Red")
SetColor(Bolt_Bot, "Red")

# 11. Labels
Text("Rigid Knee Joint", (-D_col, 200), true, true)
Text("Plumb Cut Face", (t_plate + 10, -50), true, true)


# 1. Reset Environment
Delete(All)

# 2. Create Input Sliders (Standardized)
# Roof Angle
Angle = Slider(0, 30, 0.5)
SetCaption(Angle, "Roof Slope (°)")
SetValue(Angle, 10)

# Dimensions
D_col = Slider(200, 1000, 10)
SetCaption(D_col, "Column Depth")
SetValue(D_col, 500)

D_raft = Slider(200, 600, 10)
SetCaption(D_raft, "Rafter Depth")
SetValue(D_raft, 400)

L_haunch = Slider(500, 2000, 50)
SetCaption(L_haunch, "Haunch Len")
SetValue(L_haunch, 1200)

D_haunch = Slider(100, 500, 10)
SetCaption(D_haunch, "Haunch Dp")
SetValue(D_haunch, 300)

t_plate = Slider(10, 40, 1)
SetCaption(t_plate, "Plate Thk")
SetValue(t_plate, 20)

# 3. GLOBAL MATH (Dynamic Variables)
# These act as 'functions' that update whenever sliders move
# We use a standard Tangent slope: y = x * tan(Angle)
rad = Angle * pi / 180
SlopeFactor = tan(rad)
# Vertical Height of Rafter Web (Plumb Cut)
Vert_Raft_H = D_raft / cos(rad)

# 4. COLUMN GEOMETRY (The Fix)
# We define the top points using the Slope Formula explicitly
# Inner Top (Pivot Point at Origin 0,0)
C_Top_In = (0, 0)

# Outer Top (Auto-Adjusts height based on Depth & Angle)
# x = -D_col
# y = (-D_col) * SlopeFactor
C_Top_Out = (-D_col, -D_col * SlopeFactor)

# Bottom Points (Fixed depth for display)
C_Bot_Out = (-D_col, -2500)
C_Bot_In = (0, -2500)

# Draw Column
PolyCol = Polygon(C_Top_In, C_Top_Out, C_Bot_Out, C_Bot_In)
SetColor(PolyCol, "Gray")
SetFilling(PolyCol, 0.25)

# 5. END PLATE GEOMETRY
# Sits from x=0 to x=t_plate
# Top follows the slope line
EP_TL = (0, 0)
EP_TR_Y = t_plate * SlopeFactor
EP_TR = (t_plate, EP_TR_Y)

# Bottom is determined by Rafter Depth + Haunch Depth
# It must be vertically below the top face point
Face_Bot_Y = EP_TR_Y - Vert_Raft_H - D_haunch
EP_BR = (t_plate, Face_Bot_Y)
EP_BL = (0, Face_Bot_Y)

PolyPlate = Polygon(EP_TL, EP_TR, EP_BR, EP_BL)
SetColor(PolyPlate, "Blue")
SetFilling(PolyPlate, 0.6)

# 6. RAFTER GEOMETRY
# Starts at End Plate Face (x = t_plate)
Raf_Start_Top = EP_TR
Raf_Start_Bot = (t_plate, EP_TR_Y - Vert_Raft_H)

# Ends at Span (3000mm away)
# Top Point follows slope: y = x * SlopeFactor
Tip_X = t_plate + 3000
Tip_Y = Tip_X * SlopeFactor
Raf_End_Top = (Tip_X, Tip_Y)

# Bottom Point is parallel (Vertical Drop = Vert_Raft_H)
Raf_End_Bot = (Tip_X, Tip_Y - Vert_Raft_H)

PolyRafter = Polygon(Raf_Start_Top, Raf_End_Top, Raf_End_Bot, Raf_Start_Bot)
SetColor(PolyRafter, "LightGray")
SetFilling(PolyRafter, 0.25)

# 7. HAUNCH GEOMETRY
# Starts at Rafter Bottom
Haunch_Start = Raf_Start_Bot

# Ends at Tip (L_haunch away from plate)
# Tip Y must lie on the Rafter Bottom Line
Haunch_Tip_X = t_plate + L_haunch
Haunch_Tip_Y = (Haunch_Tip_X * SlopeFactor) - Vert_Raft_H
Haunch_Tip = (Haunch_Tip_X, Haunch_Tip_Y)

# Bottom Corner (At Plate)
Haunch_Corner = EP_BR

PolyHaunch = Polygon(Haunch_Start, Haunch_Tip, Haunch_Corner)
SetColor(PolyHaunch, "Purple")
SetFilling(PolyHaunch, 0.5)

# 8. VISUAL CHECK
# Draw a red line to prove the column top is correct
CheckLine = Segment(C_Top_Out, Raf_End_Top)
SetColor(CheckLine, "Red")
SetLineStyle(CheckLine, 2)

# 1. Clear Environment
Delete(All)

# 2. Input Sliders (Parametric Inputs)
# Angle: Controls the Master Slope
Angle = Slider(0, 25, 0.5)
SetCaption(Angle, "Roof Slope (°)")
SetValue(Angle, 10)

# Column Depth (Left side width)
D_col = Slider(300, 1000, 10)
SetCaption(D_col, "Col Depth")
SetValue(D_col, 500)

# Rafter Depth (The small end / shallow part)
D_raft = Slider(200, 600, 10)
SetCaption(D_raft, "Rafter Small Depth")
SetValue(D_raft, 350)

# Haunch Geometry (How much deeper it gets at the wall)
D_haunch = Slider(100, 800, 10)
SetCaption(D_haunch, "Haunch Add Depth")
SetValue(D_haunch, 400)

L_haunch = Slider(500, 2000, 50)
SetCaption(L_haunch, "Haunch Length")
SetValue(L_haunch, 1200)

# End Plate Thickness
t_plate = Slider(10, 40, 1)
SetCaption(t_plate, "End Plate Thk")
SetValue(t_plate, 20)

# 3. MASTER MATH (The "Brain" of the Geometry)
# Everything revolves around the Pivot Point (0,0) at the Col/Plate interface.
# 1. Slope Factor (Rise over Run)
Slope = tan(Angle * pi / 180)

# 2. Vertical Depths (Plumb Cut conversions)
# We convert perpendicular depth to vertical depth to keep the face vertical.
# Cosine factor
CosF = cos(Angle * pi / 180)
Vert_Raft_Small = D_raft / CosF
Vert_Total_Deep = (D_raft + D_haunch) / CosF

# 4. COLUMN GEOMETRY (Auto-Beveled Top)
# Inner Top Corner (Pivot)
C_In_Top = (0, 0)
# Outer Top Corner (Auto-adjusts to match Slope Line extended left)
# Formula: y = x * Slope
C_Out_Top = (-D_col, -D_col * Slope)

C_Out_Bot = (-D_col, -2500)
C_In_Bot = (0, -2500)

PolyCol = Polygon(C_In_Top, C_Out_Top, C_Out_Bot, C_In_Bot)
SetColor(PolyCol, "Gray")
SetFilling(PolyCol, 0.25)

# 5. END PLATE GEOMETRY (Vertical Strip)
# Sits between x=0 and x=t_plate
# Top follows Slope
P_Plate_TL = (0, 0)
P_Plate_TR = (t_plate, t_plate * Slope)
# Bottom is flush with the Deep Rafter
P_Plate_BR = (t_plate, (t_plate * Slope) - Vert_Total_Deep)
P_Plate_BL = (0, (t_plate * Slope) - Vert_Total_Deep)

PolyPlate = Polygon(P_Plate_TL, P_Plate_TR, P_Plate_BR, P_Plate_BL)
SetColor(PolyPlate, "Blue")
SetFilling(PolyPlate, 0.6)

# 6. INTEGRATED RAFTER (Single Polygon Logic)
# 5 Points: 
# 1. Start Top (At Plate)
# 2. End Top (At Span)
# 3. End Bottom (At Span)
# 4. Haunch Transition Point (At L_haunch)
# 5. Start Bottom (Deepest Point at Plate)

# Point 1: Start Top
R_Top_Start = P_Plate_TR

# Point 2: End Top (3000mm Span)
Span = 3000
Tip_X = t_plate + Span
Tip_Y = Tip_X * Slope
R_Top_End = (Tip_X, Tip_Y)

# Point 3: End Bottom (Small Depth)
R_Bot_End = (Tip_X, Tip_Y - Vert_Raft_Small)

# Point 4: Haunch Transition (The "Kink")
# Located at L_haunch from the plate face
Kink_X = t_plate + L_haunch
Kink_Y_Top = Kink_X * Slope
# Depth here is still the Small Depth (standard rafter section starts here)
R_Kink = (Kink_X, Kink_Y_Top - Vert_Raft_Small)

# Point 5: Start Bottom (Deep Section)
# Depth = Small + Haunch
R_Bot_Start = P_Plate_BR

# Draw the Built-Up Rafter
PolyRafter = Polygon(R_Top_Start, R_Top_End, R_Bot_End, R_Kink, R_Bot_Start)
SetColor(PolyRafter, "LightGray")
SetFilling(PolyRafter, 0.25)

# 7. VISUAL GUIDES
# Dashed red line to show the continuous slope alignment
SlopeLine = Segment(C_Out_Top, R_Top_End)
SetLineStyle(SlopeLine, 2)
SetColor(SlopeLine, "Red")

# Text Labels
Text("Integrated Built-Up Rafter", (t_plate + 200, -200), true, true)
Text("Beveled Col Top", (-D_col + 10, C_Out_Top(y) + 50), true, true)


# 1. RESET
Delete(All)

# 2. CREATE SLIDERS
Angle = Slider(0, 25, 0.5)
SetCaption(Angle, "Roof Slope")
SetValue(Angle, 10)

D_raft = Slider(200, 800, 10)
SetCaption(D_raft, "Rafter Depth")
SetValue(D_raft, 400)

t_plate = Slider(10, 50, 1)
SetCaption(t_plate, "Plate Thk")
SetValue(t_plate, 20)

L_disp = Slider(1000, 3000, 100)
SetCaption(L_disp, "Length")
SetValue(L_disp, 1500)

# 3. CALCULATE MATH (Numbers Only)
rad = Angle * pi / 180
Slope = tan(rad)
VertH = D_raft / cos(rad)

# 4. DEFINE POINTS (Right Side)
P_Peak = (0, 0)
P_R_PlateTR = (t_plate, -t_plate * Slope)
P_R_PlateBR = (t_plate, (-t_plate * Slope) - VertH)
P_R_PlateBL = (0, -VertH)

Tip_R_X = t_plate + L_disp
Tip_R_Y = -Tip_R_X * Slope
P_R_RaftTop = (Tip_R_X, Tip_R_Y)
P_R_RaftBot = (Tip_R_X, Tip_R_Y - VertH)

# 5. DEFINE POINTS (Left Side)
P_L_PlateTL = (-t_plate, -t_plate * Slope)
P_L_PlateBL = (-t_plate, (-t_plate * Slope) - VertH)
P_L_PlateBR = (0, -VertH)

Tip_L_X = -(t_plate + L_disp)
Tip_L_Y = -abs(Tip_L_X) * Slope
P_L_RaftTop = (Tip_L_X, Tip_L_Y)
P_L_RaftBot = (Tip_L_X, Tip_L_Y - VertH)

# 6. DRAW LINES (Using 'Segment' instead of 'Polygon')

# --- Right Plate Outline ---
# Top Bevel
Line_RP_Top = Segment(P_Peak, P_R_PlateTR)
SetColor(Line_RP_Top, "Blue")
SetLineThickness(Line_RP_Top, 3)

# Right Vertical Face
Line_RP_Right = Segment(P_R_PlateTR, P_R_PlateBR)
SetColor(Line_RP_Right, "Blue")
SetLineThickness(Line_RP_Right, 3)

# Bottom Horizontal
Line_RP_Bot = Segment(P_R_PlateBR, P_R_PlateBL)
SetColor(Line_RP_Bot, "Blue")
SetLineThickness(Line_RP_Bot, 3)

# Center Vertical (Shared Seam)
Line_Center = Segment(P_Peak, P_R_PlateBL)
SetColor(Line_Center, "Blue")
SetLineThickness(Line_Center, 2)
SetLineStyle(Line_Center, 1) # Solid

# --- Right Rafter Outline ---
# Top Flange
Line_RR_Top = Segment(P_R_PlateTR, P_R_RaftTop)
SetColor(Line_RR_Top, "Black")

# End Vertical Cut
Line_RR_End = Segment(P_R_RaftTop, P_R_RaftBot)
SetColor(Line_RR_End, "Black")

# Bottom Flange
Line_RR_Bot = Segment(P_R_RaftBot, P_R_PlateBR)
SetColor(Line_RR_Bot, "Black")

# Vertical Interface (Rafter meets Plate)
Line_RR_Face = Segment(P_R_PlateTR, P_R_PlateBR)
SetColor(Line_RR_Face, "Black")
SetLineStyle(Line_RR_Face, 2) # Dashed to show contact surface

# --- Left Plate Outline ---
# Top Bevel
Line_LP_Top = Segment(P_L_PlateTL, P_Peak)
SetColor(Line_LP_Top, "Blue")
SetLineThickness(Line_LP_Top, 3)

# Left Vertical Face
Line_LP_Left = Segment(P_L_PlateTL, P_L_PlateBL)
SetColor(Line_LP_Left, "Blue")
SetLineThickness(Line_LP_Left, 3)

# Bottom Horizontal
Line_LP_Bot = Segment(P_L_PlateBL, P_L_PlateBR)
SetColor(Line_LP_Bot, "Blue")
SetLineThickness(Line_LP_Bot, 3)

# --- Left Rafter Outline ---
Line_RL_Top = Segment(P_L_RaftTop, P_L_PlateTL)
SetColor(Line_RL_Top, "Black")

Line_RL_End = Segment(P_L_RaftTop, P_L_RaftBot)
SetColor(Line_RL_End, "Black")

Line_RL_Bot = Segment(P_L_RaftBot, P_L_PlateBL)
SetColor(Line_RL_Bot, "Black")

Line_RL_Face = Segment(P_L_PlateTL, P_L_PlateBL)
SetColor(Line_RL_Face, "Black")
SetLineStyle(Line_RL_Face, 2)

# 7. EXTRAS
# Continuous Slope Check Line
CheckLine = Segment(P_L_RaftTop, P_R_RaftTop)
SetColor(CheckLine, "Red")
SetLineStyle(CheckLine, 3) # Dotted

Text("Wireframe Apex", (0, 200), true, true)


# 1. RESET
Delete(All)

# 2. CREATE SLIDERS
Angle = Slider(0, 25, 0.5)
SetCaption(Angle, "Roof Slope")
SetValue(Angle, 10)

D_raft = Slider(200, 800, 10)
SetCaption(D_raft, "Rafter Depth")
SetValue(D_raft, 400)

t_plate = Slider(10, 50, 1)
SetCaption(t_plate, "Plate Thk")
SetValue(t_plate, 20)

L_disp = Slider(1000, 3000, 100)
SetCaption(L_disp, "Length")
SetValue(L_disp, 1500)

# 3. DEFINE DYNAMIC POINTS (Formulas entered directly)
# Note: We use the slider names (Angle, D_raft) inside the definitions
# This forces GeoGebra to update them whenever the slider moves.

# Peak
P0 = (0, 0)

# --- Right Side Points ---
# Plate Top Right (x=t, y varies with Angle)
TR_Plate = (t_plate, -t_plate * tan(Angle * pi/180))

# Plate Bottom Right (Vertical drop based on Rafter Depth)
# Drop = D_raft / cos(Angle)
BR_Plate = (t_plate, -t_plate * tan(Angle * pi/180) - (D_raft / cos(Angle * pi/180)))

# Plate Bottom Left (Vertical drop from Peak)
BL_Plate = (0, -(D_raft / cos(Angle * pi/180)))

# Rafter End Top (at L_disp)
X_End_R = t_plate + L_disp
TR_Raft = (X_End_R, -X_End_R * tan(Angle * pi/180))

# Rafter End Bottom
BR_Raft = (X_End_R, -X_End_R * tan(Angle * pi/180) - (D_raft / cos(Angle * pi/180)))

# --- Left Side Points (Mirror) ---
# Plate Top Left (x = -t)
TL_Plate = (-t_plate, -t_plate * tan(Angle * pi/180))

# Plate Bottom Left (Mirror of Right Bottom)
BL_Plate_L = (-t_plate, -t_plate * tan(Angle * pi/180) - (D_raft / cos(Angle * pi/180)))

# Rafter End Top
X_End_L = -(t_plate + L_disp)
# Note: Use abs() logic or just negative slope math
TL_Raft = (X_End_L, -abs(X_End_L) * tan(Angle * pi/180))

# Rafter End Bottom
BL_Raft = (X_End_L, -abs(X_End_L) * tan(Angle * pi/180) - (D_raft / cos(Angle * pi/180)))


# 4. DRAW LINES (SEGMENTS)

# --- Right Plate ---
L1 = Segment(P0, TR_Plate)
SetColor(L1, "Blue")
SetLineThickness(L1, 4)

L2 = Segment(TR_Plate, BR_Plate)
SetColor(L2, "Blue")
SetLineThickness(L2, 4)

L3 = Segment(BR_Plate, BL_Plate)
SetColor(L3, "Blue")
SetLineThickness(L3, 4)

L4 = Segment(BL_Plate, P0)
SetColor(L4, "Blue")
SetLineThickness(L4, 2) 

# --- Right Rafter ---
L5 = Segment(TR_Plate, TR_Raft)
SetColor(L5, "Black")

L6 = Segment(TR_Raft, BR_Raft)
SetColor(L6, "Black")

L7 = Segment(BR_Raft, BR_Plate)
SetColor(L7, "Black")

# --- Left Plate ---
L8 = Segment(TL_Plate, P0)
SetColor(L8, "Blue")
SetLineThickness(L8, 4)

L9 = Segment(TL_Plate, BL_Plate_L)
SetColor(L9, "Blue")
SetLineThickness(L9, 4)

L10 = Segment(BL_Plate_L, BL_Plate)
SetColor(L10, "Blue")
SetLineThickness(L10, 4)

# --- Left Rafter ---
L11 = Segment(TL_Plate, TL_Raft)
SetColor(L11, "Black")

L12 = Segment(TL_Raft, BL_Raft)
SetColor(L12, "Black")

L13 = Segment(BL_Raft, BL_Plate_L)
SetColor(L13, "Black")

# 5. VISUAL CHECK
CheckLine = Segment(TL_Raft, TR_Raft)
SetColor(CheckLine, "Red")
SetLineStyle(CheckLine, 2)

Text("Lines-Only Apex Splice", (0, 200), true, true)


# 1. CLEAR AND PREPARE
Delete(All)
SetPerspective("G")
ShowGrid(true)

# 2. CREATE SLIDERS (Must be created first)
# -- Global Geometry --
# Roof Slope (Degrees)
RoofSlope = Slider(0, 25, 0.5)
SetCaption(RoofSlope, "Roof Slope")
SetValue(RoofSlope, 10)

# Total Rafter Length
RafLen = Slider(5000, 20000, 500)
SetCaption(RafLen, "Rafter Length")
SetValue(RafLen, 10000)

# Thicknesses
Tp = Slider(10, 50, 1)
SetCaption(Tp, "Plate Thk")
SetValue(Tp, 20)

Tf = Slider(5, 30, 1)
SetCaption(Tf, "Flange Thk")
SetValue(Tf, 12)

# -- PEB DEPTH CONFIGURATION --
# Number of cross-sections (2=Tapered, 3=Haunched, 4=Double)
NumPts = Slider(2, 4, 1)
SetCaption(NumPts, "Num Sections")
SetValue(NumPts, 3)

# -- DEPTH VALUES (Web Height) --
# D1: Start Depth (at Plate)
D1 = Slider(200, 1500, 50)
SetCaption(D1, "Start Depth")
SetValue(D1, 900)

# D2: First Change (e.g., End of Haunch)
D2 = Slider(200, 1500, 50)
SetCaption(D2, "Mid Depth A")
SetValue(D2, 500)

# D3: Second Change (Optional)
D3 = Slider(200, 1500, 50)
SetCaption(D3, "Mid Depth B")
SetValue(D3, 400)

# D4: End Depth (at Ridge)
D4 = Slider(200, 1500, 50)
SetCaption(D4, "End Depth")
SetValue(D4, 400)

# -- LOCATIONS (Distance from Plate) --
# L2: Location of First Change
L2 = Slider(1000, 8000, 100)
SetCaption(L2, "Loc A (Haunch)")
SetValue(L2, 2500)

# L3: Location of Second Change
L3 = Slider(2000, 12000, 100)
SetCaption(L3, "Loc B")
SetValue(L3, 6000)

# 3. CALCULATIONS (The "Brain")
# Slope Unit Vectors (Defines the axis)
Rad = RoofSlope * pi / 180
# Vaxis = Along the roof
Vaxis = (cos(Rad), sin(Rad))
# Vdepth = Perpendicular down
Vdepth = (sin(Rad), -cos(Rad))

# 4. CREATE DYNAMIC LISTS
# These lists change size automatically based on 'NumPts'
# This logic ensures we never ask for a variable that isn't needed
DistList = If(NumPts == 2, {0, RafLen}, If(NumPts == 3, {0, L2, RafLen}, {0, L2, L3, RafLen}))
DepthList = If(NumPts == 2, {D1, D4}, If(NumPts == 3, {D1, D2, D4}, {D1, D2, D3, D4}))

# 5. GENERATE POINTS (SEQUENCE COMMAND)
# Origin at the face of the End Plate
OriginPt = (Tp, 0)

# Calculate Top Points (Reference Line)
PtsTop = Sequence(OriginPt + Element(DistList, i) * Vaxis, i, 1, NumPts)

# Calculate Bottom Points (Offset by Depth)
PtsBot = Sequence(Element(PtsTop, i) + Element(DepthList, i) * Vdepth, i, 1, NumPts)

# 6. DRAW POLYGONS
# -- Web Polygon --
# Join Top points (Left->Right) and Bottom points (Right->Left)
PolyWeb = Polygon(Join(PtsTop, Reverse(PtsBot)))
SetColor(PolyWeb, "LightGray")
SetFilling(PolyWeb, 0.5)

# -- Top Flange Polygon --
# Offset Top Points Upwards (Negative Vdepth)
Vup = -1 * Vdepth * Tf
PtsTF = Sequence(Element(PtsTop, i) + Vup, i, 1, NumPts)
PolyTopFlg = Polygon(Join(PtsTop, Reverse(PtsTF)))
SetColor(PolyTopFlg, "Red")

# -- Bottom Flange Polygon --
# Offset Bottom Points Downwards (Positive Vdepth)
Vdown = Vdepth * Tf
PtsBF = Sequence(Element(PtsBot, i) + Vdown, i, 1, NumPts)
PolyBotFlg = Polygon(Join(PtsBot, Reverse(PtsBF)))
SetColor(PolyBotFlg, "Blue")

# -- End Plate (Visual) --
PlateH = D1 + 200
PlatePoly = Polygon((0,0), (Tp,0), (Tp, -PlateH), (0, -PlateH))
SetColor(PlatePoly, "Green")

# 7. VIEW ADJUSTMENT
ZoomIn(-1000, -2000, RafLen + 1000, 2000)

# 1. CLEAN SLATE
Delete(All)
SetPerspective("G")
ShowGrid(true)

# 2. CREATE SLIDERS FIRST (The Inputs)
# We define these BEFORE doing any math.

# Angle (A)
A = Slider(0, 30, 0.5)
SetCaption(A, "Slope Angle")
SetValue(A, 10)

# Column Width (W)
W = Slider(200, 1000, 10)
SetCaption(W, "Col Width")
SetValue(W, 500)

# Plate Thickness (T)
T = Slider(10, 60, 1)
SetCaption(T, "Plate Thk")
SetValue(T, 25)

# Rafter Length (L)
L = Slider(3000, 12000, 100)
SetCaption(L, "Rafter Len")
SetValue(L, 6000)

# Haunch Length (Lh)
Lh = Slider(500, 4000, 50)
SetCaption(Lh, "Haunch Len")
SetValue(Lh, 1500)

# -- DEPTHS --
# Depth at Knee (D1)
D1 = Slider(300, 1200, 10)
SetCaption(D1, "Depth Knee")
SetValue(D1, 800)

# Depth at Haunch End (D2)
D2 = Slider(200, 1000, 10)
SetCaption(D2, "Depth Haunch")
SetValue(D2, 450)

# Depth at Ridge (D3)
D3 = Slider(200, 1000, 10)
SetCaption(D3, "Depth Ridge")
SetValue(D3, 300)

# 3. MATH CONSTANTS
# Define these now so the points can use them.
Rad = A * pi / 180
# Slope (m)
m = tan(Rad)
# Cosine (cs) and Sine (sn) for perpendicular offsets
cs = cos(Rad)
sn = sin(Rad)

# 4. DEFINE POINTS (Coordinate Geometry)
# Reference: (0,0) is the Top-Right corner of the Column (Interface with Plate)

# -- COLUMN POINTS (Left of x=0) --
# C1: Top Right (Pivot)
C1 = (0, 0)
# C2: Top Left (Beveled down by slope)
C2 = (-W, -W * m)
# C3: Bottom Left
C3 = (-W, -3000)
# C4: Bottom Right
C4 = (0, -3000)

# -- END PLATE POINTS (Between x=0 and x=T) --
# P1: Top Right of Plate
P1 = (T, T * m)
# P2: Bottom Right of Plate (Start of Rafter)
# We go Down Perpendicularly by D1
# Vector Down = (D1 * sin, -D1 * cos)
P2 = (T + D1*sn, (T*m) - D1*cs)

# -- RAFTER POINTS (Right of x=T) --
# R1: Top Start (Same as Plate Top Right)
R1 = P1

# R2: Top at Haunch End
# x coordinate = T + Lh
x_h = T + Lh
y_h = x_h * m
R2 = (x_h, y_h)

# R3: Top at Ridge (End)
x_end = T + L
y_end = x_end * m
R3 = (x_end, y_end)

# -- RAFTER BOTTOM POINTS --
# R4: Bottom Start (Same as Plate Bottom Right)
R4 = P2

# R5: Bottom at Haunch (Perpendicular drop D2)
# Vector Down = (D2 * sin, -D2 * cos)
R5 = (x_h + D2*sn, y_h - D2*cs)

# R6: Bottom at Ridge (Perpendicular drop D3)
R6 = (x_end + D3*sn, y_end - D3*cs)


# 5. DRAW SEGMENTS (Connect the dots)
# We use standard Segment(A, B) commands.

# -- Draw Column --
SegColTop = Segment(C1, C2)
SetColor(SegColTop, "Black")
Segment(C2, C3)
Segment(C3, C4)
Segment(C4, C1)

# -- Draw End Plate --
# Top
Segment(C1, P1)
# Bottom (Connects Column face to Rafter Start)
Segment((0, y(P2)), P2)
# Vertical Faces
Segment(C1, (0, y(P2)))  # Left face of plate
Segment(P1, P2)          # Right face of plate

# -- Draw Rafter --
# Top Flange (Continuous Red Line)
SegTop1 = Segment(R1, R2)
SegTop2 = Segment(R2, R3)
SetColor(SegTop1, "Red")
SetColor(SegTop2, "Red")
SetLineThickness(SegTop1, 4)
SetLineThickness(SegTop2, 4)

# Bottom Flange (Haunch and Run)
SegHaunch = Segment(R4, R5)
SegRun = Segment(R5, R6)
SetColor(SegHaunch, "Blue")
SetColor(SegRun, "Blue")
SetLineThickness(SegHaunch, 4)
SetLineThickness(SegRun, 4)

# End Closure
Segment(R3, R6)

# 6. SETUP VIEW
# Force the camera to look at the Knee
ZoomIn(-1000, -1500, 4000, 1500)


# 1. CLEAN SLATE
Delete(All)
SetPerspective("G")
ShowGrid(true)

# 2. CREATE SLIDERS FIRST (The Inputs)
# We define these BEFORE doing any math.

# Angle (A)
A = Slider(0, 30, 0.5)
SetCaption(A, "Slope Angle")
SetValue(A, 10)

# Column Width (W)
W = Slider(200, 1000, 10)
SetCaption(W, "Col Width")
SetValue(W, 500)

# Plate Thickness (T)
T = Slider(10, 60, 1)
SetCaption(T, "Plate Thk")
SetValue(T, 25)

# Rafter Length (L)
L = Slider(3000, 12000, 100)
SetCaption(L, "Rafter Len")
SetValue(L, 6000)

# Haunch Length (Lh)
Lh = Slider(500, 4000, 50)
SetCaption(Lh, "Haunch Len")
SetValue(Lh, 1500)

# -- DEPTHS --
# Depth at Knee (D1)
D1 = Slider(300, 1200, 10)
SetCaption(D1, "Depth Knee")
SetValue(D1, 800)

# Depth at Haunch End (D2)
D2 = Slider(200, 1000, 10)
SetCaption(D2, "Depth Haunch")
SetValue(D2, 450)

# Depth at Ridge (D3)
D3 = Slider(200, 1000, 10)
SetCaption(D3, "Depth Ridge")
SetValue(D3, 300)

# 3. MATH CONSTANTS
# Define these now so the points can use them.
Rad = A * pi / 180
# Slope (m)
m = tan(Rad)
# Cosine (cs) and Sine (sn) for perpendicular offsets
cs = cos(Rad)
sn = sin(Rad)

# 4. DEFINE POINTS (Coordinate Geometry)
# Reference: (0,0) is the Top-Right corner of the Column (Interface with Plate)

# -- COLUMN POINTS (Left of x=0) --
# C1: Top Right (Pivot)
C1 = (0, 0)
# C2: Top Left (Beveled down by slope)
C2 = (-W, -W * m)
# C3: Bottom Left
C3 = (-W, -3000)
# C4: Bottom Right
C4 = (0, -3000)

# -- END PLATE POINTS (Between x=0 and x=T) --
# P1: Top Right of Plate
P1 = (T, T * m)
# P2: Bottom Right of Plate (Start of Rafter)
# We go Down Perpendicularly by D1
# Vector Down = (D1 * sin, -D1 * cos)
P2 = (T + D1*sn, (T*m) - D1*cs)

# -- RAFTER POINTS (Right of x=T) --
# R1: Top Start (Same as Plate Top Right)
R1 = P1

# R2: Top at Haunch End
# x coordinate = T + Lh
x_h = T + Lh
y_h = x_h * m
R2 = (x_h, y_h)

# R3: Top at Ridge (End)
x_end = T + L
y_end = x_end * m
R3 = (x_end, y_end)

# -- RAFTER BOTTOM POINTS --
# R4: Bottom Start (Same as Plate Bottom Right)
R4 = P2

# R5: Bottom at Haunch (Perpendicular drop D2)
# Vector Down = (D2 * sin, -D2 * cos)
R5 = (x_h + D2*sn, y_h - D2*cs)

# R6: Bottom at Ridge (Perpendicular drop D3)
R6 = (x_end + D3*sn, y_end - D3*cs)


# 5. DRAW SEGMENTS (Connect the dots)
# We use standard Segment(A, B) commands.

# -- Draw Column --
SegColTop = Segment(C1, C2)
SetColor(SegColTop, "Black")
Segment(C2, C3)
Segment(C3, C4)
Segment(C4, C1)

# -- Draw End Plate --
# Top
Segment(C1, P1)
# Bottom (Connects Column face to Rafter Start)
Segment((0, y(P2)), P2)
# Vertical Faces
Segment(C1, (0, y(P2)))  # Left face of plate
Segment(P1, P2)          # Right face of plate

# -- Draw Rafter --
# Top Flange (Continuous Red Line)
SegTop1 = Segment(R1, R2)
SegTop2 = Segment(R2, R3)
SetColor(SegTop1, "Red")
SetColor(SegTop2, "Red")
SetLineThickness(SegTop1, 4)
SetLineThickness(SegTop2, 4)

# Bottom Flange (Haunch and Run)
SegHaunch = Segment(R4, R5)
SegRun = Segment(R5, R6)
SetColor(SegHaunch, "Blue")
SetColor(SegRun, "Blue")
SetLineThickness(SegHaunch, 4)
SetLineThickness(SegRun, 4)

# End Closure
Segment(R3, R6)

# 6. SETUP VIEW
# Force the camera to look at the Knee
ZoomIn(-1000, -1500, 4000, 1500)


# 1. SETUP
Delete(All)
SetPerspective("GS")
ShowGrid(true)

# 2. CREATE SLIDERS (Inputs)
# We create them with simple names first.

# Slope (Ang)
Ang = Slider(0, 30, 0.5)
SetCaption(Ang, "Slope Angle")
SetValue(Ang, 10)

# Column Width (ColW)
ColW = Slider(200, 1000, 10)
SetCaption(ColW, "Col Width")
SetValue(ColW, 500)

# Plate Thickness (PltT)
PltT = Slider(10, 60, 1)
SetCaption(PltT, "Plate Thk")
SetValue(PltT, 25)

# Rafter Length (RafL)
RafL = Slider(3000, 12000, 100)
SetCaption(RafL, "Rafter Len")
SetValue(RafL, 6000)

# Haunch Length (HchL)
HchL = Slider(500, 4000, 50)
SetCaption(HchL, "Haunch Len")
SetValue(HchL, 1500)

# Depths
DpKnee = Slider(300, 1200, 10)
SetCaption(DpKnee, "Depth Knee")
SetValue(DpKnee, 800)

DpHaunch = Slider(200, 1000, 10)
SetCaption(DpHaunch, "Depth Haunch")
SetValue(DpHaunch, 450)

DpRidge = Slider(200, 1000, 10)
SetCaption(DpRidge, "Depth Ridge")
SetValue(DpRidge, 300)

# 3. SETUP SPREADSHEET
# We use direct assignment (A1 = "Text") instead of SetCell

A1 = "Slope Angle"
B1 = Ang

A2 = "Column Width"
B2 = ColW

A3 = "Plate Thk"
B3 = PltT

A4 = "Rafter Length"
B4 = RafL

A5 = "Haunch Length"
B5 = HchL

A6 = "Depth Knee"
B6 = DpKnee

A7 = "Depth Haunch"
B7 = DpHaunch

A8 = "Depth Ridge"
B8 = DpRidge

# 4. CALCULATE MATH
# Now that Sliders exist, we can do the math.

# Convert Angle to Radians
RadVal = Ang * pi / 180

# Calculate Slope (tan), Sine, Cosine
slopeVal = tan(RadVal)
sinVal = sin(RadVal)
cosVal = cos(RadVal)

# 5. CALCULATE COORDINATES
# Reference Point: (0,0) is Col Top Right

# -- COLUMN --
# C1: Top Right
C1 = (0, 0)
# C2: Top Left (Beveled)
C2 = (-ColW, -ColW * slopeVal)
# C3: Bottom Left
C3 = (-ColW, -3000)
# C4: Bottom Right
C4 = (0, -3000)

# -- END PLATE --
# P1: Top Right of Plate
P1 = (PltT, PltT * slopeVal)
# P2: Bottom Right of Plate (Vector drop from P1)
# Drop by DpKnee perpendicular to slope
P2 = P1 + (DpKnee * sinVal, -DpKnee * cosVal)

# -- RAFTER TOP --
# R1: Start (Same as Plate Top Right)
R1 = P1

# R2: Haunch End (Top)
# x = PlateThk + HaunchLen
xh = PltT + HchL
yh = xh * slopeVal
R2 = (xh, yh)

# R3: Ridge (Top)
# x = PlateThk + RafterLen
xend = PltT + RafL
yend = xend * slopeVal
R3 = (xend, yend)

# -- RAFTER BOTTOM --
# R4: Start (Same as Plate Bottom Right)
R4 = P2

# R5: Haunch End (Bottom)
# Drop from R2 by DpHaunch
R5 = R2 + (DpHaunch * sinVal, -DpHaunch * cosVal)

# R6: Ridge (Bottom)
# Drop from R3 by DpRidge
R6 = R3 + (DpRidge * sinVal, -DpRidge * cosVal)


# 6. DRAW LINES
# -- Column Lines --
SegColTop = Segment(C1, C2)
SetColor(SegColTop, "Black")
Segment(C2, C3)
Segment(C3, C4)
Segment(C4, C1)

# -- Plate Lines --
Segment(C1, P1)
Segment((0, y(P2)), P2)
Segment(C1, (0, y(P2)))
Segment(P1, P2)

# -- Rafter Top Flange (Red) --
SegTop1 = Segment(R1, R2)
SegTop2 = Segment(R2, R3)
SetColor(SegTop1, "Red")
SetColor(SegTop2, "Red")
SetLineThickness(SegTop1, 5)
SetLineThickness(SegTop2, 5)

# -- Rafter Bottom Flange (Blue) --
SegBot1 = Segment(R4, R5)
SegBot2 = Segment(R5, R6)
SetColor(SegBot1, "Blue")
SetColor(SegBot2, "Blue")
SetLineThickness(SegBot1, 5)
SetLineThickness(SegBot2, 5)

# -- End Closure --
Segment(R3, R6)

# 7. VIEW
ZoomIn(-1000, -1500, 4000, 1500)




now at height h<= min(h1 , h2)  make a straight  horizontal refernce line in red color  (the top of web line is on this horizontal reference line )  which starts from (stpt) right size flange of left side column to left side flange of right side column,  ( right side flange of left side column is innerflange of left side column , (c1) , which is slant (depend upon lower web depth and upper web depth of c1 ) , and similarly the left side flange of the right side column is inner flange of right side column (c2) which is slant (depending upon the lower and upper web depth of c2) , now this horizontal refernce line touches (endpt )the right side column inner flange and end their   write the  script for geogebra which will calculate the stpt and endpt according to h , start web depth of c1 ,end web depth of c1 , start web depth of c2 , end web depth of c2 , and strict note that the building width bw is measured from left flange of left column C1 to right flange of right column c2 thwsi means parameters are Bw , h, d1 ,d2 , d3, d4 , where d1 is bottom web depth of left column , d2 is top web depth of  left column , d3 is bottom web depth of right  column and d4 is top web depth of right column now extend the previous s


you have drawn 2 vectors at the right points but i asked you to join the red point to the tip of these vectors and i never asked you to draw these vectors  but if its auxilary calcualtion then it is okay you can do it but i need the red refernce horizontal line which will connect the tip of the vecto


# 1. Define Sliders for Basic Dimensions
# Syntax: Variable = Slider(Min, Max, Increment)

# Building Width (W) - Distance from outer flange C1 to outer flange C2
W = Slider(10, 50, 0.5)

# Heights of the columns
h1 = Slider(5, 30, 0.5)
h2 = Slider(5, 30, 0.5)

# Column 1 Widths (Left Column) - d1 (wd1) and d2 (wd2)
wd1 = Slider(1, 10, 0.1)
wd2 = Slider(1, 10, 0.1)

# Column 2 Widths (Right Column) - d3 (wd3) and d4 (wd4)
wd3 = Slider(1, 10, 0.1)
wd4 = Slider(1, 10, 0.1)

# Flange Thicknesses
tf1 = Slider(0.05, 2, 0.05)
tf2 = Slider(0.05, 2, 0.05)

# Reference Line Height (h)
h = Slider(0, 30, 0.5)

# 2. Define Points for Column 1 (Left Column)
# Left edge is strictly vertical at x=0.
P1_BotL = (0, 0)
P1_BotR = (wd1, 0)
P1_TopL = (0, h1)
P1_TopR = (wd2, h1)

# 3. Define Points for Column 2 (Right Column)
# Right edge is strictly vertical at x=W.
P2_BotR = (W, 0)
P2_BotL = (W - wd3, 0)
P2_TopR = (W, h2)
P2_TopL = (W - wd4, h2)

# 4. Draw Column 1 Outline
Col1_LineLeft = Segment(P1_BotL, P1_TopL)
Col1_LineRight = Segment(P1_BotR, P1_TopR)
Col1_LineBot = Segment(P1_BotL, P1_BotR)
Col1_LineTop = Segment(P1_TopL, P1_TopR)

# 5. Draw Column 1 Flange Thickness Lines (Inner)
P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))
P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))
Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)

P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))
P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))
Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)

# 6. Draw Column 2 Outline
Col2_LineLeft = Segment(P2_BotL, P2_TopL)
Col2_LineRight = Segment(P2_BotR, P2_TopR)
Col2_LineBot = Segment(P2_BotL, P2_BotR)
Col2_LineTop = Segment(P2_TopL, P2_TopR)

# 7. Draw Column 2 Flange Thickness Lines (Inner)
P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))
P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))
Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)

P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))
P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))
Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)

# 8. Calculate Reference Line Start/End Points (Stpt, Endpt)
# Note: Uppercase names force GeoGebra to create Points, not Vectors.

# Stpt: Intersection with C1 Inner Right Flange
# Formula: StartX + (ChangeInWidth * FractionOfHeight)
Stpt_x = (wd1 - tf1) + ((wd2 - tf1) - (wd1 - tf1)) * (h / h1)
Stpt = (Stpt_x, h)

# Endpt: Intersection with C2 Inner Left Flange
# Formula: StartX + (ChangeInWidth * FractionOfHeight)
# StartX (Bottom) is (W - wd3 + tf2)
# EndX (Top) is (W - wd4 + tf2)
Endpt_x = (W - wd3 + tf2) + ((W - wd4 + tf2) - (W - wd3 + tf2)) * (h / h2)
Endpt = (Endpt_x, h)

# 9. Draw Reference Line connecting the tips
RefLine = Segment(Stpt, Endpt)
SetColor(RefLine, "Red")
SetLineThickness(RefLine, 3)


# 1. Define Sliders for Dimensions
# Syntax: Variable = Slider(Min, Max, Increment)

# Building Width (Bw)
Bw = Slider(10, 50, 0.5)

# Heights of the columns
h1 = Slider(5, 30, 0.5)
h2 = Slider(5, 30, 0.5)

# Safe Height Limit (The crucial missing variable)
hh = Min(h1, h2)

# Column 1 Widths (Left Column): d1 (Bottom), d2 (Top)
d1 = Slider(1, 10, 0.1)
d2 = Slider(1, 10, 0.1)

# Column 2 Widths (Right Column): d3 (Bottom), d4 (Top)
d3 = Slider(1, 10, 0.1)
d4 = Slider(1, 10, 0.1)

# Flange Thicknesses
tf1 = Slider(0.05, 2, 0.05)
tf2 = Slider(0.05, 2, 0.05)

# Reference Line Slider
# We allow this to go high, but we will CLAMP it mathematically below.
h_slider = Slider(0, 40, 0.5)

# h (The Actual used height)
# This forces h to never exceed the shortest column (hh).
h = Min(h_slider, hh)

# 2. Define Points for Column 1 (Left Column)
# Left edge at x=0.
P1_BotL = (0, 0)
P1_BotR = (d1, 0)
P1_TopL = (0, h1)
P1_TopR = (d2, h1)

# 3. Define Points for Column 2 (Right Column)
# Right edge at x=Bw.
P2_BotR = (Bw, 0)
P2_BotL = (Bw - d3, 0)
P2_TopR = (Bw, h2)
P2_TopL = (Bw - d4, h2)

# 4. Draw Column 1 Outline
Col1_LineLeft = Segment(P1_BotL, P1_TopL)
Col1_LineRight = Segment(P1_BotR, P1_TopR)
Col1_LineBot = Segment(P1_BotL, P1_BotR)
Col1_LineTop = Segment(P1_TopL, P1_TopR)

# 5. Draw Column 1 Flange Thickness Lines (Inner)
P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))
P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))
Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)

P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))
P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))
Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)

# 6. Draw Column 2 Outline
Col2_LineLeft = Segment(P2_BotL, P2_TopL)
Col2_LineRight = Segment(P2_BotR, P2_TopR)
Col2_LineBot = Segment(P2_BotL, P2_BotR)
Col2_LineTop = Segment(P2_TopL, P2_TopR)

# 7. Draw Column 2 Flange Thickness Lines (Inner)
P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))
P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))
Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)

P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))
P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))
Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)

# 8. Calculate Reference Line Start/End Points (Stpt, Endpt)
# We use the clamped 'h' here, so the line never flies above the columns.

# Stpt: Intersection with C1 Inner Right Flange
# Formula: StartX + (ChangeInWidth * FractionOfHeight)
Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)
Stpt = (Stpt_x, h)

# Endpt: Intersection with C2 Inner Left Flange
# Formula: StartX + (ChangeInWidth * FractionOfHeight)
# StartX (Bottom) is (Bw - d3 + tf2)
# EndX (Top) is (Bw - d4 + tf2)
Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)
Endpt = (Endpt_x, h)

# 9. Draw Reference Line
RefLine = Segment(Stpt, Endpt)
SetColor(RefLine, "Red")
SetLineThickness(RefLine, 3)

# 1. Define Sliders for Dimensions

# Syntax: Variable = Slider(Min, Max, Increment)



# Building Width (Bw)

Bw = Slider(10, 50, 0.5)



# Heights of the columns

h1 = Slider(5, 30, 0.5)

h2 = Slider(5, 30, 0.5)



# Safe Height Limit (The crucial missing variable)

hh = Min(h1, h2)



# Column 1 Widths (Left Column): d1 (Bottom), d2 (Top)

d1 = Slider(1, 10, 0.1)

d2 = Slider(1, 10, 0.1)



# Column 2 Widths (Right Column): d3 (Bottom), d4 (Top)

d3 = Slider(1, 10, 0.1)

d4 = Slider(1, 10, 0.1)



# Flange Thicknesses

tf1 = Slider(0.05, 2, 0.05)

tf2 = Slider(0.05, 2, 0.05)



# Reference Line Slider

# We allow this to go high, but we will CLAMP it mathematically below.

h_slider = Slider(0, 40, 0.5)



# h (The Actual used height)

# This forces h to never exceed the shortest column (hh).

h = Min(h_slider, hh)



# 2. Define Points for Column 1 (Left Column)

# Left edge at x=0.

P1_BotL = (0, 0)

P1_BotR = (d1, 0)

P1_TopL = (0, h1)

P1_TopR = (d2, h1)



# 3. Define Points for Column 2 (Right Column)

# Right edge at x=Bw.

P2_BotR = (Bw, 0)

P2_BotL = (Bw - d3, 0)

P2_TopR = (Bw, h2)

P2_TopL = (Bw - d4, h2)



# 4. Draw Column 1 Outline

Col1_LineLeft = Segment(P1_BotL, P1_TopL)

Col1_LineRight = Segment(P1_BotR, P1_TopR)

Col1_LineBot = Segment(P1_BotL, P1_BotR)

Col1_LineTop = Segment(P1_TopL, P1_TopR)



# 5. Draw Column 1 Flange Thickness Lines (Inner)

P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))

P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))

Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)



P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))

P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))

Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)



# 6. Draw Column 2 Outline

Col2_LineLeft = Segment(P2_BotL, P2_TopL)

Col2_LineRight = Segment(P2_BotR, P2_TopR)

Col2_LineBot = Segment(P2_BotL, P2_BotR)

Col2_LineTop = Segment(P2_TopL, P2_TopR)



# 7. Draw Column 2 Flange Thickness Lines (Inner)

P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))

P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))

Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)



P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))

P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))

Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)



# 8. Calculate Reference Line Start/End Points (Stpt, Endpt)

# We use the clamped 'h' here, so the line never flies above the columns.



# Stpt: Intersection with C1 Inner Right Flange

# Formula: StartX + (ChangeInWidth * FractionOfHeight)

Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)

Stpt = (Stpt_x, h)



# Endpt: Intersection with C2 Inner Left Flange

# Formula: StartX + (ChangeInWidth * FractionOfHeight)

# StartX (Bottom) is (Bw - d3 + tf2)

# EndX (Top) is (Bw - d4 + tf2)

Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)

Endpt = (Endpt_x, h)



# 9. Draw Reference Line

RefLine = Segment(Stpt, Endpt)

SetColor(RefLine, "Red")

SetLineThickness(RefLine, 3)

if we extend the line of stpd and endpt toeward left and right respectively then , the extended line touch3es the left flange of  left column at lstpt and touches the right flange of right column at rendpt ,from midpoint of lsdpt to stpt is ,midstpt and midpoint of endpt to rendpt is midendpt  ,the mezzanine length in staad pro is measured in India , from mid stpd to mid endpt  , now in India people break these line from midstpt to midendpt , into one to ten segments , this segments can have different web depth ,different web thickness , different flange width different flange thickness , the top flange is of these mezzanine beams are always  above the red refernce line and whatever thevarrying webdepth is the geometry goes bellow the red line so the web depth are measured vertically perpendicular to refernce red line ,the number of segments are optional ,so if user feels the data for number of segments , then the user has to feel corresponding web depth  web thickness , top flange width , top flange thickness , bottom flange width , bottom flange thickness . the first web depth is at midstpt and the right most web depth is midendpt . even if the user doesnt feed all the data we need to book the varriables for all these cases for all ten segmentsthe bottom edge of web line in the mezzanine beam can become zig zag but the tog line of all the webs for all the segments are lying on the red refernce lones . the varriables are like wd1 ,wd2 ,wd3 ,wd4, .........wd10 , tfw1 ,tfw2 ... tfw10 .. tfth1, tfth2 ...., tfth10 ,bfw1 ,bfw2 ... bfw10, bfth1 , bfth2 .....bfth10, in India if people dont feed the data for bfw or bfth we consider them same as tfw , tfth now comes the distances of segmentation from midstpd along the red line right ward  cumaltively ,even if all the segments are not used we have to book and declare all these varriables as optional needs and the distances are calculated cummutatively along the red line from left to right now extend the geogebra script accordingly


# 1. Define Sliders for Dimensions

# Syntax: Variable = Slider(Min, Max, Increment)



# Building Width (Bw)

Bw = Slider(10, 50, 0.5)



# Heights of the columns

h1 = Slider(5, 30, 0.5)

h2 = Slider(5, 30, 0.5)



# Safe Height Limit (The crucial missing variable)

hh = Min(h1, h2)



# Column 1 Widths (Left Column): d1 (Bottom), d2 (Top)

d1 = Slider(1, 10, 0.1)

d2 = Slider(1, 10, 0.1)



# Column 2 Widths (Right Column): d3 (Bottom), d4 (Top)

d3 = Slider(1, 10, 0.1)

d4 = Slider(1, 10, 0.1)



# Flange Thicknesses

tf1 = Slider(0.05, 2, 0.05)

tf2 = Slider(0.05, 2, 0.05)



# Reference Line Slider

# We allow this to go high, but we will CLAMP it mathematically below.

h_slider = Slider(0, 40, 0.5)



# h (The Actual used height)

# This forces h to never exceed the shortest column (hh).

h = Min(h_slider, hh)



# 2. Define Points for Column 1 (Left Column)

# Left edge at x=0.

P1_BotL = (0, 0)

P1_BotR = (d1, 0)

P1_TopL = (0, h1)

P1_TopR = (d2, h1)



# 3. Define Points for Column 2 (Right Column)

# Right edge at x=Bw.

P2_BotR = (Bw, 0)

P2_BotL = (Bw - d3, 0)

P2_TopR = (Bw, h2)

P2_TopL = (Bw - d4, h2)



# 4. Draw Column 1 Outline

Col1_LineLeft = Segment(P1_BotL, P1_TopL)

Col1_LineRight = Segment(P1_BotR, P1_TopR)

Col1_LineBot = Segment(P1_BotL, P1_BotR)

Col1_LineTop = Segment(P1_TopL, P1_TopR)



# 5. Draw Column 1 Flange Thickness Lines (Inner)

P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))

P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))

Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)



P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))

P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))

Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)



# 6. Draw Column 2 Outline

Col2_LineLeft = Segment(P2_BotL, P2_TopL)

Col2_LineRight = Segment(P2_BotR, P2_TopR)

Col2_LineBot = Segment(P2_BotL, P2_BotR)

Col2_LineTop = Segment(P2_TopL, P2_TopR)



# 7. Draw Column 2 Flange Thickness Lines (Inner)

P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))

P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))

Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)



P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))

P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))

Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)



# 8. Calculate Reference Line Start/End Points (Stpt, Endpt)

# We use the clamped 'h' here, so the line never flies above the columns.



# Stpt: Intersection with C1 Inner Right Flange

# Formula: StartX + (ChangeInWidth * FractionOfHeight)

Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)

Stpt = (Stpt_x, h)



# Endpt: Intersection with C2 Inner Left Flange

# Formula: StartX + (ChangeInWidth * FractionOfHeight)

# StartX (Bottom) is (Bw - d3 + tf2)

# EndX (Top) is (Bw - d4 + tf2)

Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)

Endpt = (Endpt_x, h)



# 9. Draw Reference Line

RefLine = Segment(Stpt, Endpt)

SetColor(RefLine, "Red")

SetLineThickness(RefLine, 3)

if we extend the line of stpd and endpt toeward left and right respectively then , the extended line touch3es the left flange of  left column at lstpt and touches the right flange of right column at rendpt ,from midpoint of lsdpt to stpt is ,midstpt and midpoint of endpt to rendpt is midendpt  ,the mezzanine length in staad pro is measured in India , from mid stpd to mid endpt  , now in India people break these line from midstpt to midendpt , into one to ten segments , this segments can have different web depth ,different web thickness , different flange width different flange thickness , the top flange is of these mezzanine beams are always  above the red refernce line and whatever thevarrying webdepth is the geometry goes bellow the red line so the web depth are measured vertically perpendicular to refernce red line ,the number of segments are optional ,so if user feels the data for number of segments , then the user has to feel corresponding web depth  web thickness , top flange width , top flange thickness , bottom flange width , bottom flange thickness . the first web depth is at midstpt and the right most web depth is midendpt . even if the user doesnt feed all the data we need to book the varriables for all these cases for all ten segmentsthe bottom edge of web line in the mezzanine beam can become zig zag but the tog line of all the webs for all the segments are lying on the red refernce lones . the varriables are like wd1 ,wd2 ,wd3 ,wd4, .........wd10 , tfw1 ,tfw2 ... tfw10 .. tfth1, tfth2 ...., tfth10 ,bfw1 ,bfw2 ... bfw10, bfth1 , bfth2 .....bfth10, in India if people dont feed the data for bfw or bfth we consider them same as tfw , tfth now comes the distances of segmentation from midstpd along the red line right ward  cumaltively ,even if all the segments are not used we have to book and declare all these varriables as optional needs and the distances are calculated cummutatively along the red line from left to right now extend the geogebra script accordingly


script 
# 1. BASE FRAME DEFINITIONS & SLIDERS
# -----------------------------------
# Building Width (Bw)
Bw = Slider(10, 50, 0.5)

# Heights of the columns
h1 = Slider(5, 30, 0.5)
h2 = Slider(5, 30, 0.5)

# Safe Height Limit
hh = Min(h1, h2)

# Column 1 Widths (Left): d1 (Bottom), d2 (Top)
d1 = Slider(1, 10, 0.1)
d2 = Slider(1, 10, 0.1)

# Column 2 Widths (Right): d3 (Bottom), d4 (Top)
d3 = Slider(1, 10, 0.1)
d4 = Slider(1, 10, 0.1)

# Column Flange Thicknesses
tf1 = Slider(0.05, 2, 0.05)
tf2 = Slider(0.05, 2, 0.05)

# Reference Line Slider (Clamped to hh)
h_slider = Slider(0, 40, 0.5)
h = Min(h_slider, hh)

# 2. DRAWING THE COLUMNS
# ----------------------
# Column 1 Points (Left Edge Vertical at 0)
P1_BotL = (0, 0)
P1_BotR = (d1, 0)
P1_TopL = (0, h1)
P1_TopR = (d2, h1)

# Column 2 Points (Right Edge Vertical at Bw)
P2_BotR = (Bw, 0)
P2_BotL = (Bw - d3, 0)
P2_TopR = (Bw, h2)
P2_TopL = (Bw - d4, h2)

# Draw Column 1
Col1_LineLeft = Segment(P1_BotL, P1_TopL)
Col1_LineRight = Segment(P1_BotR, P1_TopR)
Col1_LineBot = Segment(P1_BotL, P1_BotR)
Col1_LineTop = Segment(P1_TopL, P1_TopR)

# Draw Column 1 Inner Flanges
P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))
P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))
Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)
P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))
P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))
Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)

# Draw Column 2
Col2_LineLeft = Segment(P2_BotL, P2_TopL)
Col2_LineRight = Segment(P2_BotR, P2_TopR)
Col2_LineBot = Segment(P2_BotL, P2_BotR)
Col2_LineTop = Segment(P2_TopL, P2_TopR)

# Draw Column 2 Inner Flanges
P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))
P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))
Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)
P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))
P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))
Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)

# 3. REFERENCE LINE INTERSECTIONS & MIDPOINTS
# -------------------------------------------
# Stpt: Intersection with C1 Inner Right Flange
Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)
Stpt = (Stpt_x, h)

# Endpt: Intersection with C2 Inner Left Flange
Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)
Endpt = (Endpt_x, h)

# Draw Red Reference Line (Inner to Inner)
RefLine = Segment(Stpt, Endpt)
SetColor(RefLine, "Red")
SetLineThickness(RefLine, 3)

# EXTENDED POINTS (Outer Flanges)
# Left Column Outer Flange is at x=0
Lstpt = (0, h)
# Right Column Outer Flange is at x=Bw
Rendpt = (Bw, h)

# MIDPOINTS (System Line Start/End)
MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)
MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)

# Mezzanine Total Length
MezzLength = Distance(MidStpt, MidEndpt)

# 4. MEZZANINE SEGMENT VARIABLES (BOOKING 1-10)
# ---------------------------------------------
# Number of segments active (Visual limit)
NumSeg = Slider(1, 10, 1)

# Web Depths (wd) - Need 11 points for 10 segments (Start to End)
# We define sliders for the first 4, others are static for booking
wd1


# 1. BASE FRAME DEFINITIONS & SLIDERS

# -----------------------------------

# Building Width (Bw)

Bw = Slider(10, 50, 0.5)



# Heights of the columns

h1 = Slider(5, 30, 0.5)

h2 = Slider(5, 30, 0.5)



# Safe Height Limit

hh = Min(h1, h2)



# Column 1 Widths (Left): d1 (Bottom), d2 (Top)

d1 = Slider(1, 10, 0.1)

d2 = Slider(1, 10, 0.1)



# Column 2 Widths (Right): d3 (Bottom), d4 (Top)

d3 = Slider(1, 10, 0.1)

d4 = Slider(1, 10, 0.1)



# Column Flange Thicknesses

tf1 = Slider(0.05, 2, 0.05)

tf2 = Slider(0.05, 2, 0.05)



# Reference Line Slider (Clamped to hh)

h_slider = Slider(0, 40, 0.5)

h = Min(h_slider, hh)



# 2. DRAWING THE COLUMNS

# ----------------------

# Column 1 Points (Left Edge Vertical at 0)

P1_BotL = (0, 0)

P1_BotR = (d1, 0)

P1_TopL = (0, h1)

P1_TopR = (d2, h1)



# Column 2 Points (Right Edge Vertical at Bw)

P2_BotR = (Bw, 0)

P2_BotL = (Bw - d3, 0)

P2_TopR = (Bw, h2)

P2_TopL = (Bw - d4, h2)



# Draw Column 1

Col1_LineLeft = Segment(P1_BotL, P1_TopL)

Col1_LineRight = Segment(P1_BotR, P1_TopR)

Col1_LineBot = Segment(P1_BotL, P1_BotR)

Col1_LineTop = Segment(P1_TopL, P1_TopR)



# Draw Column 1 Inner Flanges

P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))

P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))

Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)

P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))

P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))

Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)



# Draw Column 2

Col2_LineLeft = Segment(P2_BotL, P2_TopL)

Col2_LineRight = Segment(P2_BotR, P2_TopR)

Col2_LineBot = Segment(P2_BotL, P2_BotR)

Col2_LineTop = Segment(P2_TopL, P2_TopR)



# Draw Column 2 Inner Flanges

P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))

P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))

Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)

P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))

P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))

Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)



# 3. REFERENCE LINE INTERSECTIONS & MIDPOINTS

# -------------------------------------------

# Stpt: Intersection with C1 Inner Right Flange

Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)

Stpt = (Stpt_x, h)



# Endpt: Intersection with C2 Inner Left Flange

Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)

Endpt = (Endpt_x, h)



# Draw Red Reference Line (Inner to Inner)

RefLine = Segment(Stpt, Endpt)

SetColor(RefLine, "Red")

SetLineThickness(RefLine, 3)



# EXTENDED POINTS (Outer Flanges)

# Left Column Outer Flange is at x=0

Lstpt = (0, h)

# Right Column Outer Flange is at x=Bw

Rendpt = (Bw, h)



# MIDPOINTS (System Line Start/End)

MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)

MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)



# Mezzanine Total Length

MezzLength = Distance(MidStpt, MidEndpt)



# 4. MEZZANINE SEGMENT VARIABLES (BOOKING 1-10)

# ---------------------------------------------

# Number of segments active (Visual limit)

NumSeg = Slider(1, 10, 1)



# Web Depths (wd) - Need 11 points for 10 segments (Start to End)

# We define sliders for the first 4, others are static for booking

wd1

all your sliders are very clumsy so link these values with geogebra spreadsheet and rewrite the entire sheet where the first coljumn of spreadsheet is varriable name as we have discussed and second column  is the value rewrite the  entire script and there shouldnt be any undefined varriable error take care of it yourself


# 1. BASE FRAME DEFINITIONS & SLIDERS

# -----------------------------------

# Building Width (Bw)

Bw = Slider(10, 50, 0.5)



# Heights of the columns

h1 = Slider(5, 30, 0.5)

h2 = Slider(5, 30, 0.5)



# Safe Height Limit

hh = Min(h1, h2)



# Column 1 Widths (Left): d1 (Bottom), d2 (Top)

d1 = Slider(1, 10, 0.1)

d2 = Slider(1, 10, 0.1)



# Column 2 Widths (Right): d3 (Bottom), d4 (Top)

d3 = Slider(1, 10, 0.1)

d4 = Slider(1, 10, 0.1)



# Column Flange Thicknesses

tf1 = Slider(0.05, 2, 0.05)

tf2 = Slider(0.05, 2, 0.05)



# Reference Line Slider (Clamped to hh)

h_slider = Slider(0, 40, 0.5)

h = Min(h_slider, hh)



# 2. DRAWING THE COLUMNS

# ----------------------

# Column 1 Points (Left Edge Vertical at 0)

P1_BotL = (0, 0)

P1_BotR = (d1, 0)

P1_TopL = (0, h1)

P1_TopR = (d2, h1)



# Column 2 Points (Right Edge Vertical at Bw)

P2_BotR = (Bw, 0)

P2_BotL = (Bw - d3, 0)

P2_TopR = (Bw, h2)

P2_TopL = (Bw - d4, h2)



# Draw Column 1

Col1_LineLeft = Segment(P1_BotL, P1_TopL)

Col1_LineRight = Segment(P1_BotR, P1_TopR)

Col1_LineBot = Segment(P1_BotL, P1_BotR)

Col1_LineTop = Segment(P1_TopL, P1_TopR)



# Draw Column 1 Inner Flanges

P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))

P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))

Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)

P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))

P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))

Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)



# Draw Column 2

Col2_LineLeft = Segment(P2_BotL, P2_TopL)

Col2_LineRight = Segment(P2_BotR, P2_TopR)

Col2_LineBot = Segment(P2_BotL, P2_BotR)

Col2_LineTop = Segment(P2_TopL, P2_TopR)



# Draw Column 2 Inner Flanges

P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))

P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))

Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)

P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))

P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))

Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)



# 3. REFERENCE LINE INTERSECTIONS & MIDPOINTS

# -------------------------------------------

# Stpt: Intersection with C1 Inner Right Flange

Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)

Stpt = (Stpt_x, h)



# Endpt: Intersection with C2 Inner Left Flange

Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)

Endpt = (Endpt_x, h)



# Draw Red Reference Line (Inner to Inner)

RefLine = Segment(Stpt, Endpt)

SetColor(RefLine, "Red")

SetLineThickness(RefLine, 3)



# EXTENDED POINTS (Outer Flanges)

# Left Column Outer Flange is at x=0

Lstpt = (0, h)

# Right Column Outer Flange is at x=Bw

Rendpt = (Bw, h)



# MIDPOINTS (System Line Start/End)

MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)

MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)



# Mezzanine Total Length

MezzLength = Distance(MidStpt, MidEndpt)



# 4. MEZZANINE SEGMENT VARIABLES (BOOKING 1-10)

# ---------------------------------------------

# Number of segments active (Visual limit)

NumSeg = Slider(1, 10, 1)



# Web Depths (wd) - Need 11 points for 10 segments (Start to End)

# We define sliders for the first 4, others are static for booking

wd1

all your sliders are very clumsy so link these values with geogebra spreadsheet and rewrite the entire sheet where the first coljumn of spreadsheet is varriable name as we have discussed and second column  is the value rewrite the  entire script and there shouldnt be any undefined varriable error take care of it yourself


# 1. BASE FRAME DEFINITIONS & SLIDERS

# -----------------------------------

# Building Width (Bw)

Bw = Slider(10, 50, 0.5)



# Heights of the columns

h1 = Slider(5, 30, 0.5)

h2 = Slider(5, 30, 0.5)



# Safe Height Limit

hh = Min(h1, h2)



# Column 1 Widths (Left): d1 (Bottom), d2 (Top)

d1 = Slider(1, 10, 0.1)

d2 = Slider(1, 10, 0.1)



# Column 2 Widths (Right): d3 (Bottom), d4 (Top)

d3 = Slider(1, 10, 0.1)

d4 = Slider(1, 10, 0.1)



# Column Flange Thicknesses

tf1 = Slider(0.05, 2, 0.05)

tf2 = Slider(0.05, 2, 0.05)



# Reference Line Slider (Clamped to hh)

h_slider = Slider(0, 40, 0.5)

h = Min(h_slider, hh)



# 2. DRAWING THE COLUMNS

# ----------------------

# Column 1 Points (Left Edge Vertical at 0)

P1_BotL = (0, 0)

P1_BotR = (d1, 0)

P1_TopL = (0, h1)

P1_TopR = (d2, h1)



# Column 2 Points (Right Edge Vertical at Bw)

P2_BotR = (Bw, 0)

P2_BotL = (Bw - d3, 0)

P2_TopR = (Bw, h2)

P2_TopL = (Bw - d4, h2)



# Draw Column 1

Col1_LineLeft = Segment(P1_BotL, P1_TopL)

Col1_LineRight = Segment(P1_BotR, P1_TopR)

Col1_LineBot = Segment(P1_BotL, P1_BotR)

Col1_LineTop = Segment(P1_TopL, P1_TopR)



# Draw Column 1 Inner Flanges

P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))

P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))

Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)

P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))

P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))

Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)



# Draw Column 2

Col2_LineLeft = Segment(P2_BotL, P2_TopL)

Col2_LineRight = Segment(P2_BotR, P2_TopR)

Col2_LineBot = Segment(P2_BotL, P2_BotR)

Col2_LineTop = Segment(P2_TopL, P2_TopR)



# Draw Column 2 Inner Flanges

P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))

P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))

Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)

P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))

P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))

Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)



# 3. REFERENCE LINE INTERSECTIONS & MIDPOINTS

# -------------------------------------------

# Stpt: Intersection with C1 Inner Right Flange

Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)

Stpt = (Stpt_x, h)



# Endpt: Intersection with C2 Inner Left Flange

Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)

Endpt = (Endpt_x, h)



# Draw Red Reference Line (Inner to Inner)

RefLine = Segment(Stpt, Endpt)

SetColor(RefLine, "Red")

SetLineThickness(RefLine, 3)



# EXTENDED POINTS (Outer Flanges)

# Left Column Outer Flange is at x=0

Lstpt = (0, h)

# Right Column Outer Flange is at x=Bw

Rendpt = (Bw, h)



# MIDPOINTS (System Line Start/End)

MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)

MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)



# Mezzanine Total Length

MezzLength = Distance(MidStpt, MidEndpt)



# 4. MEZZANINE SEGMENT VARIABLES (BOOKING 1-10)

# ---------------------------------------------

# Number of segments active (Visual limit)

NumSeg = Slider(1, 10, 1)



# Web Depths (wd) - Need 11 points for 10 segments (Start to End)

# We define sliders for the first 4, others are static for booking

wd1

all your sliders are very clumsy so link these values with geogebra spreadsheet and rewrite the entire sheet where the first coljumn of spreadsheet is varriable name as we have discussed and second column  is the value rewrite the  entire script and there shouldnt be any undefined varriable error take care of it yourself


# ------------------------------------------------------------------
# PART 1: SETUP SPREADSHEET (LABELS & DEFAULT VALUES)
# ------------------------------------------------------------------

# Row 1: Building Width (Bw)
SetValue(A1, "Bw")
SetValue(B1, 30)

# Row 2-3: Column Heights (h1, h2)
SetValue(A2, "h1")
SetValue(B2, 12)
SetValue(A3, "h2")
SetValue(B3, 10)

# Row 4-5: Left Column Widths (d1, d2)
SetValue(A4, "d1")
SetValue(B4, 4)
SetValue(A5, "d2")
SetValue(B5, 3)

# Row 6-7: Right Column Widths (d3, d4)
SetValue(A6, "d3")
SetValue(B6, 4)
SetValue(A7, "d4")
SetValue(B7, 3)

# Row 8-9: Flange Thicknesses (tf1, tf2)
SetValue(A8, "tf1")
SetValue(B8, 0.5)
SetValue(A9, "tf2")
SetValue(B9, 0.5)

# Row 10: Requested Reference Height (h_req)
SetValue(A10, "h_req")
SetValue(B10, 8)

# Row 11: Number of Segments (NumSeg)
SetValue(A11, "NumSeg")
SetValue(B11, 3)

# ------------------------------------------------------------------
# PART 2: MEZZANINE DATA (BOOKING VARIABLES IN SPREADSHEET)
# ------------------------------------------------------------------

# Rows 13-23: Web Depths (wd1 to wd11)
SetValue(A13, "wd1")
SetValue(B13, 2.0)
SetValue(A14, "wd2")
SetValue(B14, 1.5)
SetValue(A15, "wd3")
SetValue(B15, 2.0)
SetValue(A16, "wd4")
SetValue(B16, 1.5)
# Fill rest with default 1.0
Execute(Sequence("SetValue(A" + (i+16) + ", ""wd" + (i+4) + """)", i, 1, 7))
Execute(Sequence("SetValue(B" + (i+16) + ", 1.0)", i, 1, 7))

# Rows 24-33: Segment Distances (dist1 to dist10)
SetValue(A24, "dist1")
SetValue(B24, 5)
SetValue(A25, "dist2")
SetValue(B25, 5)
SetValue(A26, "dist3")
SetValue(B26, 5)
# Fill rest with default 0
Execute(Sequence("SetValue(A" + (i+26) + ", ""dist" + (i+3) + """)", i, 1, 7))
Execute(Sequence("SetValue(B" + (i+26) + ", 0)", i, 1, 7))

# Rows 35-44: Top Flange Width (tfw1 to tfw10)
Execute(Sequence("SetValue(A" + (i+34) + ", ""tfw" + i + """)", i, 1, 10))
Execute(Sequence("SetValue(B" + (i+34) + ", 0.3)", i, 1, 10))

# Rows 45-54: Top Flange Thickness (tfth1 to tfth10)
Execute(Sequence("SetValue(A" + (i+44) + ", ""tfth" + i + """)", i, 1, 10))
Execute(Sequence("SetValue(B" + (i+44) + ", 0.02)", i, 1, 10))

# Rows 55-64: Bottom Flange Width (bfw1 to bfw10)
Execute(Sequence("SetValue(A" + (i+54) + ", ""bfw" + i + """)", i, 1, 10))
Execute(Sequence("SetValue(B" + (i+54) + ", 0.3)", i, 1, 10))

# Rows 65-74: Bottom Flange Thickness (bfth1 to bfth10)
Execute(Sequence("SetValue(A" + (i+64) + ", ""bfth" + i + """)", i, 1, 10))
Execute(Sequence("SetValue(B" + (i+64) + ", 0.02)", i, 1, 10))


# ------------------------------------------------------------------
# PART 3: LINKING VARIABLES TO CELL VALUES
# ------------------------------------------------------------------

Bw = B1
h1 = B2
h2 = B3
d1 = B4
d2 = B5
d3 = B6
d4 = B7
tf1 = B8
tf2 = B9
h_req = B10
NumSeg = B11

# Linking Web Depths (wd)
wd1 = B13
wd2 = B14
wd3 = B15
wd4 = B16
wd5 = B17
wd6 = B18
wd7 = B19
wd8 = B20
wd9 = B21
wd10 = B22
wd11 = B23

# Linking Distances (dist)
dist1 = B24
dist2 = B25
dist3 = B26
dist4 = B27
dist5 = B28
dist6 = B29
dist7 = B30
dist8 = B31
dist9 = B32
dist10 = B33

# Linking Flange Specs (Just a few explicit links for logic, mass linking via index not needed for drawing yet)
tfw1 = B35
tfth1 = B45
bfw1 = B55
bfth1 = B65

# ------------------------------------------------------------------
# PART 4: GEOMETRY CALCULATION
# ------------------------------------------------------------------

# Safe Height Limit & Clamping
hh = Min(h1, h2)
h = Min(h_req, hh)

# Column 1 Points (Left Edge Vertical at 0)
P1_BotL = (0, 0)
P1_BotR = (d1, 0)
P1_TopL = (0, h1)
P1_TopR = (d2, h1)

# Column 2 Points (Right Edge Vertical at Bw)
P2_BotR = (Bw, 0)
P2_BotL = (Bw - d3, 0)
P2_TopR = (Bw, h2)
P2_TopL = (Bw - d4, h2)

# Draw Column 1
Col1_LineLeft = Segment(P1_BotL, P1_TopL)
Col1_LineRight = Segment(P1_BotR, P1_TopR)
Col1_LineBot = Segment(P1_BotL, P1_BotR)
Col1_LineTop = Segment(P1_TopL, P1_TopR)

# Draw Column 1 Inner Flanges
P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))
P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))
Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)

P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))
P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))
Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)

# Draw Column 2
Col2_LineLeft = Segment(P2_BotL, P2_TopL)
Col2_LineRight = Segment(P2_BotR, P2_TopR)
Col2_LineBot = Segment(P2_BotL, P2_BotR)
Col2_LineTop = Segment(P2_TopL, P2_TopR)

# Draw Column 2 Inner Flanges
P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))
P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))
Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)

P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))
P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))
Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)

# ------------------------------------------------------------------
# PART 5: REFERENCE LINE & MEZZANINE LOGIC
# ------------------------------------------------------------------

# Stpt: Intersection with C1 Inner Right Flange
Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)
Stpt = (Stpt_x, h)

# Endpt: Intersection with C2 Inner Left Flange
Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)
Endpt = (Endpt_x, h)

# Draw Red Reference Line
RefLine = Segment(Stpt, Endpt)
SetColor(RefLine, "Red")
SetLineThickness(RefLine, 3)

# Extended Outer Points
Lstpt = (0, h)
Rendpt = (Bw, h)

# System Midpoints
MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)
MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)

# Mezzanine Beam Drawing
# Top Line (Always Straight on Reference Line)
MezzTopLine = Segment(MidStpt, MidEndpt)
SetColor(MezzTopLine, "Blue")
SetLineThickness(MezzTopLine, 4)

# Bottom Line Zig-Zag Calculation
# Node 0 (Start)
Mz_Bot0 = (x(MidStpt), h - wd1)

# Node 1
X1 = Min(x(MidStpt) + dist1, x(MidEndpt))
Mz_Bot1 = (X1, h - wd2)

# Node 2
X2 = Min(X1 + dist2, x(MidEndpt))
Mz_Bot2 = (X2, h - wd3)

# Node 3
X3 = Min(X2 + dist3, x(MidEndpt))
Mz_Bot3 = (X3, h - wd4)

# Node 4
X4 = Min(X3 + dist4, x(MidEndpt))
Mz_Bot4 = (X4, h - wd5)

# Drawing Bottom Segments based on NumSeg
# Segment 1
WebBot_Seg1_End = If(NumSeg == 1, (x(MidEndpt), h - wd2), Mz_Bot1)
WebBot1 = Segment(Mz_Bot0, WebBot_Seg1_End)

# Segment 2
WebBot_Seg2_End = If(NumSeg == 2, (x(MidEndpt), h - wd3), Mz_Bot2)
WebBot2 = If(NumSeg >= 2, Segment(Mz_Bot1, WebBot_Seg2_End))

# Segment 3
WebBot_Seg3_End = If(NumSeg == 3, (x(MidEndpt), h - wd4), Mz_Bot3)
WebBot3 = If(NumSeg >= 3, Segment(Mz_Bot2, WebBot_Seg3_End))

# Segment 4
WebBot_Seg4_End = If(NumSeg == 4, (x(MidEndpt), h - wd5), Mz_Bot4)
WebBot4 = If(NumSeg >= 4, Segment(Mz_Bot3, WebBot_Seg4_End))

SetColor(WebBot1, "Green")
SetColor(WebBot2, "Green")
SetColor(WebBot3, "Green")
SetColor(WebBot4, "Green")

# Web Vertical Closure (Start and End)
WebStart = Segment(MidStpt, Mz_Bot0)
# Dynamic end point for web closure
WebEndNode = If(NumSeg==1, WebBot_Seg1_End, If(NumSeg==2, WebBot_Seg2_End, If(NumSeg==3, WebBot_Seg3_End, WebBot_Seg4_End)))
WebEnd = Segment(MidEndpt, WebEndNode)




# 1. BASE FRAME DEFINITIONS & SLIDERS

# -----------------------------------

# Building Width (Bw)

Bw = Slider(10, 50, 0.5)



# Heights of the columns

h1 = Slider(5, 30, 0.5)

h2 = Slider(5, 30, 0.5)



# Safe Height Limit

hh = Min(h1, h2)



# Column 1 Widths (Left): d1 (Bottom), d2 (Top)

d1 = Slider(1, 10, 0.1)

d2 = Slider(1, 10, 0.1)



# Column 2 Widths (Right): d3 (Bottom), d4 (Top)

d3 = Slider(1, 10, 0.1)

d4 = Slider(1, 10, 0.1)



# Column Flange Thicknesses

tf1 = Slider(0.05, 2, 0.05)

tf2 = Slider(0.05, 2, 0.05)



# Reference Line Slider (Clamped to hh)

h_slider = Slider(0, 40, 0.5)

h = Min(h_slider, hh)



# 2. DRAWING THE COLUMNS

# ----------------------

# Column 1 Points (Left Edge Vertical at 0)

P1_BotL = (0, 0)

P1_BotR = (d1, 0)

P1_TopL = (0, h1)

P1_TopR = (d2, h1)



# Column 2 Points (Right Edge Vertical at Bw)

P2_BotR = (Bw, 0)

P2_BotL = (Bw - d3, 0)

P2_TopR = (Bw, h2)

P2_TopL = (Bw - d4, h2)



# Draw Column 1

Col1_LineLeft = Segment(P1_BotL, P1_TopL)

Col1_LineRight = Segment(P1_BotR, P1_TopR)

Col1_LineBot = Segment(P1_BotL, P1_BotR)

Col1_LineTop = Segment(P1_TopL, P1_TopR)



# Draw Column 1 Inner Flanges

P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))

P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))

Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)

P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))

P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))

Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)



# Draw Column 2

Col2_LineLeft = Segment(P2_BotL, P2_TopL)

Col2_LineRight = Segment(P2_BotR, P2_TopR)

Col2_LineBot = Segment(P2_BotL, P2_BotR)

Col2_LineTop = Segment(P2_TopL, P2_TopR)



# Draw Column 2 Inner Flanges

P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))

P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))

Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)

P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))

P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))

Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)



# 3. REFERENCE LINE INTERSECTIONS & MIDPOINTS

# -------------------------------------------

# Stpt: Intersection with C1 Inner Right Flange

Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)

Stpt = (Stpt_x, h)



# Endpt: Intersection with C2 Inner Left Flange

Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)

Endpt = (Endpt_x, h)



# Draw Red Reference Line (Inner to Inner)

RefLine = Segment(Stpt, Endpt)

SetColor(RefLine, "Red")

SetLineThickness(RefLine, 3)



# EXTENDED POINTS (Outer Flanges)

# Left Column Outer Flange is at x=0

Lstpt = (0, h)

# Right Column Outer Flange is at x=Bw

Rendpt = (Bw, h)



# MIDPOINTS (System Line Start/End)

MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)

MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)



# Mezzanine Total Length

MezzLength = Distance(MidStpt, MidEndpt)



# 4. MEZZANINE SEGMENT VARIABLES (BOOKING 1-10)

# ---------------------------------------------

# Number of segments active (Visual limit)

NumSeg = Slider(1, 10, 1)



# Web Depths (wd) - Need 11 points for 10 segments (Start to End)

# We define sliders for the first 4, others are static for booking

wd1

all your sliders are very clumsy so link these values with geogebra spreadsheet and rewrite the entire sheet where the first coljumn of spreadsheet is varriable name as we have discussed and second column  is the value rewrite the  entire script and there shouldnt be any undefined varriable error take care of it yourself



prompt for updated geogebra model of mezzanine column connection
# ------------------------------------------------------------------
# PART 1: SAFETY CHECK (Initialize Spreadsheet)
# ------------------------------------------------------------------

# Basic Dimensions (Rows 1-11)
If(IsDefined(A1)==false, SetValue(A1, "Bw"))
If(IsDefined(B1)==false, SetValue(B1, 30))
If(IsDefined(A2)==false, SetValue(A2, "h1"))
If(IsDefined(B2)==false, SetValue(B2, 12))
If(IsDefined(A3)==false, SetValue(A3, "h2"))
If(IsDefined(B3)==false, SetValue(B3, 10))
If(IsDefined(A4)==false, SetValue(A4, "d1"))
If(IsDefined(B4)==false, SetValue(B4, 4))
If(IsDefined(A5)==false, SetValue(A5, "d2"))
If(IsDefined(B5)==false, SetValue(B5, 3))
If(IsDefined(A6)==false, SetValue(A6, "d3"))
If(IsDefined(B6)==false, SetValue(B6, 4))
If(IsDefined(A7)==false, SetValue(A7, "d4"))
If(IsDefined(B7)==false, SetValue(B7, 3))
If(IsDefined(A8)==false, SetValue(A8, "tf1"))
If(IsDefined(B8)==false, SetValue(B8, 0.5))
If(IsDefined(A9)==false, SetValue(A9, "tf2"))
If(IsDefined(B9)==false, SetValue(B9, 0.5))
If(IsDefined(A10)==false, SetValue(A10, "h_req"))
If(IsDefined(B10)==false, SetValue(B10, 8))
If(IsDefined(A11)==false, SetValue(A11, "NumSeg"))
If(IsDefined(B11)==false, SetValue(B11, 3))

# Web Depths (Rows 12-22)
Execute(Sequence("If(IsDefined(A" + (i+11) + ")==false, SetValue(A" + (i+11) + ", ""wd" + i + """))", i, 1, 11))
Execute(Sequence("If(IsDefined(B" + (i+11) + ")==false, SetValue(B" + (i+11) + ", 1.0))", i, 1, 11))

# Distances (Rows 23-32)
Execute(Sequence("If(IsDefined(A" + (i+22) + ")==false, SetValue(A" + (i+22) + ", ""dist" + i + """))", i, 1, 10))
Execute(Sequence("If(IsDefined(B" + (i+22) + ")==false, SetValue(B" + (i+22) + ", 5.0))", i, 1, 10))

# Flange Specs (Rows 33-36)
If(IsDefined(A33)==false, SetValue(A33, "tfw"))
If(IsDefined(B33)==false, SetValue(B33, 0.3))
If(IsDefined(A34)==false, SetValue(A34, "tfth"))
If(IsDefined(B34)==false, SetValue(B34, 0.02))
If(IsDefined(A35)==false, SetValue(A35, "bfw"))
If(IsDefined(B35)==false, SetValue(B35, 0.3))
If(IsDefined(A36)==false, SetValue(A36, "bfth"))
If(IsDefined(B36)==false, SetValue(B36, 0.02))

# ------------------------------------------------------------------
# PART 2: LINK VARIABLES TO SPREADSHEET CELLS
# ------------------------------------------------------------------

Bw = B1
h1 = B2
h2 = B3
d1 = B4
d2 = B5
d3 = B6
d4 = B7
tf1 = B8
tf2 = B9
h_req = B10
NumSeg = B11

wd1 = B12
wd2 = B13
wd3 = B14
wd4 = B15
wd5 = B16
wd6 = B17
wd7 = B18
wd8 = B19
wd9 = B20
wd10 = B21
wd11 = B22

dist1 = B23
dist2 = B24
dist3 = B25
dist4 = B26
dist5 = B27
dist6 = B28
dist7 = B29
dist8 = B30
dist9 = B31
dist10 = B32

tfw = B33
tfth = B34
bfw = B35
bfth = B36

# ------------------------------------------------------------------
# PART 3: DRAWING LOGIC (COLUMNS)
# ------------------------------------------------------------------

# Safe Height Limit & Clamping
hh = Min(h1, h2)
h = Min(h_req, hh)

# Column 1 Points (Left Edge Vertical at 0)
P1_BotL = (0, 0)
P1_BotR = (d1, 0)
P1_TopL = (0, h1)
P1_TopR = (d2, h1)

# Column 2 Points (Right Edge Vertical at Bw)
P2_BotR = (Bw, 0)
P2_BotL = (Bw - d3, 0)
P2_TopR = (Bw, h2)
P2_TopL = (Bw - d4, h2)

# Draw Column 1
Col1_LineLeft = Segment(P1_BotL, P1_TopL)
Col1_LineRight = Segment(P1_BotR, P1_TopR)
Col1_LineBot = Segment(P1_BotL, P1_BotR)
Col1_LineTop = Segment(P1_TopL, P1_TopR)

# Draw Column 1 Inner Flanges (Visual Only)
P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))
P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))
Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)
P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))
P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))
Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)

# Draw Column 2
Col2_LineLeft = Segment(P2_BotL, P2_TopL)
Col2_LineRight = Segment(P2_BotR, P2_TopR)
Col2_LineBot = Segment(P2_BotL, P2_BotR)
Col2_LineTop = Segment(P2_TopL, P2_TopR)

# Draw Column 2 Inner Flanges (Visual Only)
P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))
P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))
Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)
P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))
P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))
Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)

# ------------------------------------------------------------------
# PART 4: REFERENCE LINE & MEZZANINE (HARD CODED LOGIC)
# ------------------------------------------------------------------
# Logic: Depth is calculated from Outer Edge. Flange Thickness ignored.

# Stpt: Point on the Inner Web of Left Column
# X = BottomWidth + (ChangeInWidth * RatioOfHeight)
Stpt_x = d1 + (d2 - d1) * (h / h1)
Stpt = (Stpt_x, h)

# Endpt: Point on the Inner Web of Right Column
# X = Bw - (BottomWidth + (ChangeInWidth * RatioOfHeight))
RightCol_Depth_At_H = d3 + (d4 - d3) * (h / h2)
Endpt_x = Bw - RightCol_Depth_At_H
Endpt = (Endpt_x, h)

# Draw Red Reference Line
RefLine = Segment(Stpt, Endpt)
SetColor(RefLine, "Red")
SetLineThickness(RefLine, 3)

# Extended Outer Points
Lstpt = (0, h)
Rendpt = (Bw, h)

# System Midpoints
MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)
MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)

# ------------------------------------------------------------------
# PART 5: MEZZANINE BEAM (ALL 10 SEGMENTS)
# ------------------------------------------------------------------

# Top Line
MezzTopLine = Segment(MidStpt, MidEndpt)
SetColor(MezzTopLine, "Blue")
SetLineThickness(MezzTopLine, 4)

# 1. Calculate All Nodes (Bottom Points)
# Node 0 (Start)
Mz_Bot0 = (x(MidStpt), h - wd1)

# Node 1
X1 = Min(x(MidStpt) + dist1, x(MidEndpt))
Mz_Bot1 = (X1, h - wd2)

# Node 2
X2 = Min(X1 + dist2, x(MidEndpt))
Mz_Bot2 = (X2, h - wd3)

# Node 3
X3 = Min(X2 + dist3, x(MidEndpt))
Mz_Bot3 = (X3, h - wd4)

# Node 4
X4 = Min(X3 + dist4, x(MidEndpt))
Mz_Bot4 = (X4, h - wd5)

# Node 5
X5 = Min(X4 + dist5, x(MidEndpt))
Mz_Bot5 = (X5, h - wd6)

# Node 6
X6 = Min(X5 + dist6, x(MidEndpt))
Mz_Bot6 = (X6, h - wd7)

# Node 7
X7 = Min(X6 + dist7, x(MidEndpt))
Mz_Bot7 = (X7, h - wd8)

# Node 8
X8 = Min(X7 + dist8, x(MidEndpt))
Mz_Bot8 = (X8, h - wd9)

# Node 9
X9 = Min(X8 + dist9, x(MidEndpt))
Mz_Bot9 = (X9, h - wd10)

# Node 10
X10 = Min(X9 + dist10, x(MidEndpt))
Mz_Bot10 = (X10, h - wd11)

# 2. Draw Segments (Conditionally based on NumSeg)

# Segment 1
WebBot_Seg1_End = If(NumSeg == 1, (x(MidEndpt), h - wd2), Mz_Bot1)
WebBot1 = Segment(Mz_Bot0, WebBot_Seg1_End)
SetColor(WebBot1, "Green")

# Segment 2
WebBot_Seg2_End = If(NumSeg == 2, (x(MidEndpt), h - wd3), Mz_Bot2)
WebBot2 = If(NumSeg >= 2, Segment(Mz_Bot1, WebBot_Seg2_End))
SetColor(WebBot2, "Green")

# Segment 3
WebBot_Seg3_End = If(NumSeg == 3, (x(MidEndpt), h - wd4), Mz_Bot3)
WebBot3 = If(NumSeg >= 3, Segment(Mz_Bot2, WebBot_Seg3_End))
SetColor(WebBot3, "Green")

# Segment 4
WebBot_Seg4_End = If(NumSeg == 4, (x(MidEndpt), h - wd5), Mz_Bot4)
WebBot4 = If(NumSeg >= 4, Segment(Mz_Bot3, WebBot_Seg4_End))
SetColor(WebBot4, "Green")

# Segment 5
WebBot_Seg5_End = If(NumSeg == 5, (x(MidEndpt), h - wd6), Mz_Bot5)
WebBot5 = If(NumSeg >= 5, Segment(Mz_Bot4, WebBot_Seg5_End))
SetColor(WebBot5, "Green")

# Segment 6
WebBot_Seg6_End = If(NumSeg == 6, (x(MidEndpt), h - wd7), Mz_Bot6)
WebBot6 = If(NumSeg >= 6, Segment(Mz_Bot5, WebBot_Seg6_End))
SetColor(WebBot6, "Green")

# Segment 7
WebBot_Seg7_End = If(NumSeg == 7, (x(MidEndpt), h - wd8), Mz_Bot7)
WebBot7 = If(NumSeg >= 7, Segment(Mz_Bot6, WebBot_Seg7_End))
SetColor(WebBot7, "Green")

# Segment 8
WebBot_Seg8_End = If(NumSeg == 8, (x(MidEndpt), h - wd9), Mz_Bot8)
WebBot8 = If(NumSeg >= 8, Segment(Mz_Bot7, WebBot_Seg8_End))
SetColor(WebBot8, "Green")

# Segment 9
WebBot_Seg9_End = If(NumSeg == 9, (x(MidEndpt), h - wd10), Mz_Bot9)
WebBot9 = If(NumSeg >= 9, Segment(Mz_Bot8, WebBot_Seg9_End))
SetColor(WebBot9, "Green")

# Segment 10
WebBot_Seg10_End = If(NumSeg == 10, (x(MidEndpt), h - wd11), Mz_Bot10)
WebBot10 = If(NumSeg >= 10, Segment(Mz_Bot9, WebBot_Seg10_End))
SetColor(WebBot10, "Green")

# Web Vertical Closure (Start)
WebStart = Segment(MidStpt, Mz_Bot0)

# Web Vertical Closure (Dynamic End)
WebEndNode = If(NumSeg==1, WebBot_Seg1_End, If(NumSeg==2, WebBot_Seg2_End, If(NumSeg==3, WebBot_Seg3_End, If(NumSeg==4, WebBot_Seg4_End, If(NumSeg==5, WebBot_Seg5_End, If(NumSeg==6, WebBot_Seg6_End, If(NumSeg==7, WebBot_Seg7_End, If(NumSeg==8, WebBot_Seg8_End, If(NumSeg==9, WebBot_Seg9_End, WebBot_Seg10_End)))))))))
WebEnd = Segment(MidEndpt, WebEndNode)



# 1. RESET
Delete(All)

# 2. CREATE SLIDERS
# Primary member (beam) parameters
D_primary = Slider(200, 800, 10)
SetCaption(D_primary, "Primary Depth")
SetValue(D_primary, 400)

W_primary = Slider(100, 400, 10)
SetCaption(W_primary, "Primary Width")
SetValue(W_primary, 200)

# Gusset plate parameters
t_gusset = Slider(5, 30, 1)
SetCaption(t_gusset, "Gusset Thk")
SetValue(t_gusset, 15)

b_gusset = Slider(100, 500, 10)
SetCaption(b_gusset, "Gusset Width")
SetValue(b_gusset, 300)

h_gusset = Slider(200, 800, 10)
SetCaption(h_gusset, "Gusset Length")
SetValue(h_gusset, 400)

# Number of braces (1-3)
n_braces = Slider(1, 3, 1)
SetCaption(n_braces, "Num Braces")
SetValue(n_braces, 3)

# Brace angles (slope angles for each brace)
Angle1 = Slider(0, 90, 1)
SetCaption(Angle1, "Brace 1 Angle")
SetValue(Angle1, 45)

Angle2 = Slider(0, 90, 1)
SetCaption(Angle2, "Brace 2 Angle")
SetValue(Angle2, 45)

Angle3 = Slider(0, 90, 1)
SetCaption(Angle3, "Brace 3 Angle")
SetValue(Angle3, 45)

# Tee parameters (when made from plates)
tFlange = Slider(5, 30, 1)
SetCaption(tFlange, "Tee Flange t")
SetValue(tFlange, 10)

bFlange = Slider(50, 300, 10)
SetCaption(bFlange, "Tee Flange b")
SetValue(bFlange, 150)

hFlange = Slider(100, 400, 10)
SetCaption(hFlange, "Tee Flange h")
SetValue(hFlange, 200)

tWeb = Slider(5, 30, 1)
SetCaption(tWeb, "Tee Web t")
SetValue(tWeb, 10)

bWeb = Slider(50, 300, 10)
SetCaption(bWeb, "Tee Web b")
SetValue(bWeb, 150)

hWeb = Slider(100, 400, 10)
SetCaption(hWeb, "Tee Web h")
SetValue(hWeb, 200)

# Clearance parameters
ClearTee1 = Slider(10, 100, 5)
SetCaption(ClearTee1, "Clear Prim/Tee1")
SetValue(ClearTee1, 50)

ClearTee2 = Slider(10, 100, 5)
SetCaption(ClearTee2, "Clear Prim/Tee2")
SetValue(ClearTee2, 50)

ClearTee3 = Slider(10, 100, 5)
SetCaption(ClearTee3, "Clear Prim/Tee3")
SetValue(ClearTee3, 50)

ClearGusset = Slider(10, 100, 5)
SetCaption(ClearGusset, "Clear Gusset/Tee")
SetValue(ClearGusset, 30)

# Chamfered corners option (0 = No, 1 = Yes)
Chamfered = Slider(0, 1, 1)
SetCaption(Chamfered, "Chamfered (0=No,1=Yes)")
SetValue(Chamfered, 1)

MinCutAngle = Slider(0, 90, 5)
SetCaption(MinCutAngle, "Min Cut Angle")
SetValue(MinCutAngle, 10)

# Brace length for display
BraceLen = Slider(100, 500, 10)
SetCaption(BraceLen, "Brace Length")
SetValue(BraceLen, 300)

# 3. DEFINE BASE POINTS
# Primary member center (beam center line)
PrimCenter = (0, 0)
PrimTop = (0, D_primary / 2)
PrimBottom = (0, -D_primary / 2)
PrimLeft = (-W_primary / 2, 0)
PrimRight = (W_primary / 2, 0)

# Gusset plate center X coordinate
GussetCX = W_primary / 2 + t_gusset / 2

# Gusset plate corners (rectangular plate)
GussetTL = (GussetCX - b_gusset / 2, h_gusset / 2)
GussetTR = (GussetCX + b_gusset / 2, h_gusset / 2)
GussetBL = (GussetCX - b_gusset / 2, -h_gusset / 2)
GussetBR = (GussetCX + b_gusset / 2, -h_gusset / 2)

# 4. BRACE CONNECTION Y-POSITIONS ON GUSSET
# Distribute braces vertically along gusset
Brace1Y = If(n_braces == 1, 0, If(n_braces == 2, h_gusset / 4, h_gusset / 3))
Brace2Y = If(n_braces >= 2, If(n_braces == 2, -h_gusset / 4, 0), 0)
Brace3Y = If(n_braces == 3, -h_gusset / 3, 0)

# Brace connection points on gusset edge
Brace1Gusset = (GussetCX - b_gusset / 2, Brace1Y)
Brace2Gusset = (GussetCX - b_gusset / 2, Brace2Y)
Brace3Gusset = (GussetCX - b_gusset / 2, Brace3Y)

# 5. TEE CENTER POSITIONS
# Tees positioned with clearance from primary
Tee1X = ClearTee1
Tee1Y = Brace1Y
Tee1Center = (Tee1X, Tee1Y)

Tee2X = ClearTee2
Tee2Y = Brace2Y
Tee2Center = (Tee2X, Tee2Y)

Tee3X = ClearTee3
Tee3Y = Brace3Y
Tee3Center = (Tee3X, Tee3Y)

# 6. TEE FLANGE AND WEB ENDPOINTS
# Tee 1 flange (horizontal line from tee to near gusset)
Tee1FlangeStart = (Tee1X, Tee1Y)
Tee1FlangeEnd = (GussetCX - b_gusset / 2 - ClearGusset, Tee1Y)

# Tee 1 web (from tee toward primary member)
Tee1WebStart = Tee1Center
Tee1WebEnd = (0, Tee1Y)

# Tee 2 flange and web
Tee2FlangeStart = (Tee2X, Tee2Y)
Tee2FlangeEnd = (GussetCX - b_gusset / 2 - ClearGusset, Tee2Y)
Tee2WebStart = Tee2Center
Tee2WebEnd = (0, Tee2Y)

# Tee 3 flange and web
Tee3FlangeStart = (Tee3X, Tee3Y)
Tee3FlangeEnd = (GussetCX - b_gusset / 2 - ClearGusset, Tee3Y)
Tee3WebStart = Tee3Center
Tee3WebEnd = (0, Tee3Y)

# 7. BRACE CENTERLINE ENDPOINTS
# Brace 1 extends from tee at angle
Brace1Start = Tee1Center
Brace1DX = BraceLen * cos(Angle1 * pi / 180)
Brace1DY = BraceLen * sin(Angle1 * pi / 180)
Brace1End = (Tee1X - Brace1DX, Tee1Y + Brace1DY)

# Brace 2 extends from tee at angle
Brace2Start = Tee2Center
Brace2DX = BraceLen * cos(Angle2 * pi / 180)
Brace2DY = BraceLen * sin(Angle2 * pi / 180)
Brace2End = (Tee2X - Brace2DX, Tee2Y + Brace2DY)

# Brace 3 extends from tee at angle
Brace3Start = Tee3Center
Brace3DX = BraceLen * cos(Angle3 * pi / 180)
Brace3DY = BraceLen * sin(Angle3 * pi / 180)
Brace3End = (Tee3X - Brace3DX, Tee3Y + Brace3DY)

# 8. CHAMFER CALCULATIONS
# Chamfer distance for corners (only if chamfered and angle meets threshold)
ChamferDist = If(Chamfered == 1, If(abs(Angle1 - 90) >= MinCutAngle, 30, 0), 0)
ChamferDist3 = If(Chamfered == 1, If(n_braces == 3, If(abs(Angle3 - 90) >= MinCutAngle, 30, 0), 0), 0)

# Chamfered gusset corner points
GussetTLc = (x(GussetTL) + ChamferDist, y(GussetTL) - ChamferDist)
GussetBLc = (x(GussetBL) + ChamferDist, y(GussetBL) + ChamferDist)
GussetTRc = (x(GussetTR) - ChamferDist3, y(GussetTR) - ChamferDist3)
GussetBRc = (x(GussetBR) - ChamferDist3, y(GussetBR) + ChamferDist3)

# Final gusset corners to use (chamfered or original)
GussetTLf = If(Chamfered == 1, GussetTLc, GussetTL)
GussetBLf = If(Chamfered == 1, GussetBLc, GussetBL)
GussetTRf = If(Chamfered == 1, GussetTRc, GussetTR)
GussetBRf = If(Chamfered == 1, GussetBRc, GussetBR)

# 9. DRAW PRIMARY MEMBER (BEAM) - Blue
PrimFront = Segment(PrimLeft, PrimRight)
SetColor(PrimFront, "Blue")
SetLineThickness(PrimFront, 6)

PrimTopEdge = Segment((-W_primary / 2, D_primary / 2), (W_primary / 2, D_primary / 2))
SetColor(PrimTopEdge, "Blue")
SetLineThickness(PrimTopEdge, 4)

PrimBottomEdge = Segment((-W_primary / 2, -D_primary / 2), (W_primary / 2, -D_primary / 2))
SetColor(PrimBottomEdge, "Blue")
SetLineThickness(PrimBottomEdge, 4)

PrimLeftEdge = Segment((-W_primary / 2, D_primary / 2), (-W_primary / 2, -D_primary / 2))
SetColor(PrimLeftEdge, "Blue")
SetLineThickness(PrimLeftEdge, 4)

PrimRightEdge = Segment((W_primary / 2, D_primary / 2), (W_primary / 2, -D_primary / 2))
SetColor(PrimRightEdge, "Blue")
SetLineThickness(PrimRightEdge, 4)

# 10. DRAW GUSSET PLATE - Green
GussetTopEdge = Segment(GussetTLf, GussetTRf)
SetColor(GussetTopEdge, "Green")
SetLineThickness(GussetTopEdge, 5)

GussetBottomEdge = Segment(GussetBLf, GussetBRf)
SetColor(GussetBottomEdge, "Green")
SetLineThickness(GussetBottomEdge, 5)

GussetLeftEdge = Segment(GussetTLf, GussetBLf)
SetColor(GussetLeftEdge, "Green")
SetLineThickness(GussetLeftEdge, 5)

GussetRightEdge = Segment(GussetTRf, GussetBRf)
SetColor(GussetRightEdge, "Green")
SetLineThickness(GussetRightEdge, 5)

# 11. DRAW TEES - Red
# Tee 1
Tee1Flange = Segment(Tee1FlangeStart, Tee1FlangeEnd)
SetColor(Tee1Flange, "Red")
SetLineThickness(Tee1Flange, 4)

Tee1Web = Segment(Tee1WebStart, Tee1WebEnd)
SetColor(Tee1Web, "Red")
SetLineThickness(Tee1Web, 4)

# Tee 2
Tee2Flange = Segment(Tee2FlangeStart, Tee2FlangeEnd)
SetColor(Tee2Flange, "Red")
SetLineThickness(Tee2Flange, 4)

Tee2Web = Segment(Tee2WebStart, Tee2WebEnd)
SetColor(Tee2Web, "Red")
SetLineThickness(Tee2Web, 4)

# Tee 3
Tee3Flange = Segment(Tee3FlangeStart, Tee3FlangeEnd)
SetColor(Tee3Flange, "Red")
SetLineThickness(Tee3Flange, 4)

Tee3Web = Segment(Tee3WebStart, Tee3WebEnd)
SetColor(Tee3Web, "Red")
SetLineThickness(Tee3Web, 4)

# 12. DRAW BRACE CENTERLINES - Orange dashed
Brace1Line = Segment(Brace1Start, Brace1End)
SetColor(Brace1Line, "Orange")
SetLineThickness(Brace1Line, 3)
SetLineStyle(Brace1Line, 2)

Brace2Line = Segment(Brace2Start, Brace2End)
SetColor(Brace2Line, "Orange")
SetLineThickness(Brace2Line, 3)
SetLineStyle(Brace2Line, 2)

Brace3Line = Segment(Brace3Start, Brace3End)
SetColor(Brace3Line, "Orange")
SetLineThickness(Brace3Line, 3)
SetLineStyle(Brace3Line, 2)

# 13. TITLE
TitleText = Text("Portal Bracing Connection (105)", (0, 350), true, true)

# 14. LEGEND
LegendBlue = Text("Blue = Primary Member (Beam)", (-350, 300), true, true)
LegendGreen = Text("Green = Gusset Plate", (-350, 280), true, true)
LegendRed = Text("Red = Tees (Flange + Web)", (-350, 260), true, true)
LegendOrange = Text("Orange = Braces (Tubular)", (-350, 240), true, true)




# ------------------------------------------------------------------
# PART 1: SAFETY CHECK (Initialize Spreadsheet if Empty)
# This ensures no "Undefined Variable" errors if you haven't pasted data yet.
# ------------------------------------------------------------------

# Basic Dimensions (Rows 1-11)
If(IsDefined(A1)==false, SetValue(A1, "Bw"))
If(IsDefined(B1)==false, SetValue(B1, 30))
If(IsDefined(A2)==false, SetValue(A2, "h1"))
If(IsDefined(B2)==false, SetValue(B2, 12))
If(IsDefined(A3)==false, SetValue(A3, "h2"))
If(IsDefined(B3)==false, SetValue(B3, 10))
If(IsDefined(A4)==false, SetValue(A4, "d1"))
If(IsDefined(B4)==false, SetValue(B4, 4))
If(IsDefined(A5)==false, SetValue(A5, "d2"))
If(IsDefined(B5)==false, SetValue(B5, 3))
If(IsDefined(A6)==false, SetValue(A6, "d3"))
If(IsDefined(B6)==false, SetValue(B6, 4))
If(IsDefined(A7)==false, SetValue(A7, "d4"))
If(IsDefined(B7)==false, SetValue(B7, 3))
If(IsDefined(A8)==false, SetValue(A8, "tf1"))
If(IsDefined(B8)==false, SetValue(B8, 0.5))
If(IsDefined(A9)==false, SetValue(A9, "tf2"))
If(IsDefined(B9)==false, SetValue(B9, 0.5))
If(IsDefined(A10)==false, SetValue(A10, "h_req"))
If(IsDefined(B10)==false, SetValue(B10, 8))
If(IsDefined(A11)==false, SetValue(A11, "NumSeg"))
If(IsDefined(B11)==false, SetValue(B11, 3))

# Web Depths (Rows 12-22)
Execute(Sequence("If(IsDefined(A" + (i+11) + ")==false, SetValue(A" + (i+11) + ", ""wd" + i + """))", i, 1, 11))
Execute(Sequence("If(IsDefined(B" + (i+11) + ")==false, SetValue(B" + (i+11) + ", 1.0))", i, 1, 11))

# Distances (Rows 23-32)
Execute(Sequence("If(IsDefined(A" + (i+22) + ")==false, SetValue(A" + (i+22) + ", ""dist" + i + """))", i, 1, 10))
Execute(Sequence("If(IsDefined(B" + (i+22) + ")==false, SetValue(B" + (i+22) + ", 5.0))", i, 1, 10))

# Flange Specs (Rows 33-36) - Simplified to single inputs as requested by "common" practice
If(IsDefined(A33)==false, SetValue(A33, "tfw"))
If(IsDefined(B33)==false, SetValue(B33, 0.3))
If(IsDefined(A34)==false, SetValue(A34, "tfth"))
If(IsDefined(B34)==false, SetValue(B34, 0.02))
If(IsDefined(A35)==false, SetValue(A35, "bfw"))
If(IsDefined(B35)==false, SetValue(B35, 0.3))
If(IsDefined(A36)==false, SetValue(A36, "bfth"))
If(IsDefined(B36)==false, SetValue(B36, 0.02))

# ------------------------------------------------------------------
# PART 2: LINK VARIABLES TO SPREADSHEET CELLS
# ------------------------------------------------------------------

Bw = B1
h1 = B2
h2 = B3
d1 = B4
d2 = B5
d3 = B6
d4 = B7
tf1 = B8
tf2 = B9
h_req = B10
NumSeg = B11

# Link Web Depths (wd1 - wd11)
wd1 = B12
wd2 = B13
wd3 = B14
wd4 = B15
wd5 = B16
wd6 = B17
wd7 = B18
wd8 = B19
wd9 = B20
wd10 = B21
wd11 = B22

# Link Distances (dist1 - dist10)
dist1 = B23
dist2 = B24
dist3 = B25
dist4 = B26
dist5 = B27
dist6 = B28
dist7 = B29
dist8 = B30
dist9 = B31
dist10 = B32

# Link Common Flange Specs
tfw = B33
tfth = B34
bfw = B35
bfth = B36

# ------------------------------------------------------------------
# PART 3: DRAWING LOGIC
# ------------------------------------------------------------------

# Safe Height Limit & Clamping
hh = Min(h1, h2)
h = Min(h_req, hh)

# Column 1 Points (Left Edge Vertical at 0)
P1_BotL = (0, 0)
P1_BotR = (d1, 0)
P1_TopL = (0, h1)
P1_TopR = (d2, h1)

# Column 2 Points (Right Edge Vertical at Bw)
P2_BotR = (Bw, 0)
P2_BotL = (Bw - d3, 0)
P2_TopR = (Bw, h2)
P2_TopL = (Bw - d4, h2)

# Draw Column 1
Col1_LineLeft = Segment(P1_BotL, P1_TopL)
Col1_LineRight = Segment(P1_BotR, P1_TopR)
Col1_LineBot = Segment(P1_BotL, P1_BotR)
Col1_LineTop = Segment(P1_TopL, P1_TopR)

# Draw Column 1 Inner Flanges
P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))
P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))
Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)
P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))
P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))
Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)

# Draw Column 2
Col2_LineLeft = Segment(P2_BotL, P2_TopL)
Col2_LineRight = Segment(P2_BotR, P2_TopR)
Col2_LineBot = Segment(P2_BotL, P2_BotR)
Col2_LineTop = Segment(P2_TopL, P2_TopR)

# Draw Column 2 Inner Flanges
P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))
P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))
Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)
P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))
P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))
Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)

# ------------------------------------------------------------------
# PART 4: REFERENCE LINE & MEZZANINE LOGIC
# ------------------------------------------------------------------

# Stpt: Intersection with C1 Inner Right Flange
Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)
Stpt = (Stpt_x, h)

# Endpt: Intersection with C2 Inner Left Flange
Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)
Endpt = (Endpt_x, h)

# Draw Red Reference Line
RefLine = Segment(Stpt, Endpt)
SetColor(RefLine, "Red")
SetLineThickness(RefLine, 3)

# Extended Outer Points
Lstpt = (0, h)
Rendpt = (Bw, h)

# System Midpoints
MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)
MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)

# Mezzanine Beam Drawing
# Top Line (Always Straight on Reference Line)
MezzTopLine = Segment(MidStpt, MidEndpt)
SetColor(MezzTopLine, "Blue")
SetLineThickness(MezzTopLine, 4)

# Bottom Line Zig-Zag Calculation
# Node 0 (Start)
Mz_Bot0 = (x(MidStpt), h - wd1)

# Node 1
X1 = Min(x(MidStpt) + dist1, x(MidEndpt))
Mz_Bot1 = (X1, h - wd2)

# Node 2
X2 = Min(X1 + dist2, x(MidEndpt))
Mz_Bot2 = (X2, h - wd3)

# Node 3
X3 = Min(X2 + dist3, x(MidEndpt))
Mz_Bot3 = (X3, h - wd4)

# Node 4
X4 = Min(X3 + dist4, x(MidEndpt))
Mz_Bot4 = (X4, h - wd5)

# Drawing Bottom Segments based on NumSeg
# Segment 1
WebBot_Seg1_End = If(NumSeg == 1, (x(MidEndpt), h - wd2), Mz_Bot1)
WebBot1 = Segment(Mz_Bot0, WebBot_Seg1_End)

# Segment 2
WebBot_Seg2_End = If(NumSeg == 2, (x(MidEndpt), h - wd3), Mz_Bot2)
WebBot2 = If(NumSeg >= 2, Segment(Mz_Bot1, WebBot_Seg2_End))

# Segment 3
WebBot_Seg3_End = If(NumSeg == 3, (x(MidEndpt), h - wd4), Mz_Bot3)
WebBot3 = If(NumSeg >= 3, Segment(Mz_Bot2, WebBot_Seg3_End))

# Segment 4
WebBot_Seg4_End = If(NumSeg == 4, (x(MidEndpt), h - wd5), Mz_Bot4)
WebBot4 = If(NumSeg >= 4, Segment(Mz_Bot3, WebBot_Seg4_End))

SetColor(WebBot1, "Green")
SetColor(WebBot2, "Green")
SetColor(WebBot3, "Green")
SetColor(WebBot4, "Green")

# Web Vertical Closure (Start and End)
WebStart = Segment(MidStpt, Mz_Bot0)
# Dynamic end point for web closure
WebEndNode = If(NumSeg==1, WebBot_Seg1_End, If(NumSeg==2, WebBot_Seg2_End, If(NumSeg==3, WebBot_Seg3_End, WebBot_Seg4_End)))
WebEnd = Segment(MidEndpt, WebEndNode)


not working properly as d5 and others not working and some points out

Bw 30
h1 12
h2 10
d1 4
d2 3
d3 4
d4 3
tf1 0.5
tf2 0.5
h_req 8
NumSeg 3
wd1 2
wd2 1.5
wd3 2
wd4 1.5
wd5 1
wd6 1
wd7 1
wd8 1
wd9 1
wd10 1
wd11 1
dist1 5
dist2 5
dist3 5
dist4 0
dist5 0
dist6 0
dist7 0
dist8 0
dist9 0
dist10 0
tfw 0.3
tfth 0.02
bfw 0.3
bfth 0.02


# ------------------------------------------------------------------
# PART 1: SAFETY CHECK (Initialize Spreadsheet if Empty)
# This ensures no "Undefined Variable" errors if you haven't pasted data yet.
# ------------------------------------------------------------------

# Basic Dimensions (Rows 1-11)
If(IsDefined(A1)==false, SetValue(A1, "Bw"))
If(IsDefined(B1)==false, SetValue(B1, 30))
If(IsDefined(A2)==false, SetValue(A2, "h1"))
If(IsDefined(B2)==false, SetValue(B2, 12))
If(IsDefined(A3)==false, SetValue(A3, "h2"))
If(IsDefined(B3)==false, SetValue(B3, 10))
If(IsDefined(A4)==false, SetValue(A4, "d1"))
If(IsDefined(B4)==false, SetValue(B4, 4))
If(IsDefined(A5)==false, SetValue(A5, "d2"))
If(IsDefined(B5)==false, SetValue(B5, 3))
If(IsDefined(A6)==false, SetValue(A6, "d3"))
If(IsDefined(B6)==false, SetValue(B6, 4))
If(IsDefined(A7)==false, SetValue(A7, "d4"))
If(IsDefined(B7)==false, SetValue(B7, 3))
If(IsDefined(A8)==false, SetValue(A8, "tf1"))
If(IsDefined(B8)==false, SetValue(B8, 0.5))
If(IsDefined(A9)==false, SetValue(A9, "tf2"))
If(IsDefined(B9)==false, SetValue(B9, 0.5))
If(IsDefined(A10)==false, SetValue(A10, "h_req"))
If(IsDefined(B10)==false, SetValue(B10, 8))
If(IsDefined(A11)==false, SetValue(A11, "NumSeg"))
If(IsDefined(B11)==false, SetValue(B11, 3))

# Web Depths (Rows 12-22)
Execute(Sequence("If(IsDefined(A" + (i+11) + ")==false, SetValue(A" + (i+11) + ", ""wd" + i + """))", i, 1, 11))
Execute(Sequence("If(IsDefined(B" + (i+11) + ")==false, SetValue(B" + (i+11) + ", 1.0))", i, 1, 11))

# Distances (Rows 23-32)
Execute(Sequence("If(IsDefined(A" + (i+22) + ")==false, SetValue(A" + (i+22) + ", ""dist" + i + """))", i, 1, 10))
Execute(Sequence("If(IsDefined(B" + (i+22) + ")==false, SetValue(B" + (i+22) + ", 5.0))", i, 1, 10))

# Flange Specs (Rows 33-36) - Simplified to single inputs as requested by "common" practice
If(IsDefined(A33)==false, SetValue(A33, "tfw"))
If(IsDefined(B33)==false, SetValue(B33, 0.3))
If(IsDefined(A34)==false, SetValue(A34, "tfth"))
If(IsDefined(B34)==false, SetValue(B34, 0.02))
If(IsDefined(A35)==false, SetValue(A35, "bfw"))
If(IsDefined(B35)==false, SetValue(B35, 0.3))
If(IsDefined(A36)==false, SetValue(A36, "bfth"))
If(IsDefined(B36)==false, SetValue(B36, 0.02))

# ------------------------------------------------------------------
# PART 2: LINK VARIABLES TO SPREADSHEET CELLS
# ------------------------------------------------------------------

Bw = B1
h1 = B2
h2 = B3
d1 = B4
d2 = B5
d3 = B6
d4 = B7
tf1 = B8
tf2 = B9
h_req = B10
NumSeg = B11

# Link Web Depths (wd1 - wd11)
wd1 = B12
wd2 = B13
wd3 = B14
wd4 = B15
wd5 = B16
wd6 = B17
wd7 = B18
wd8 = B19
wd9 = B20
wd10 = B21
wd11 = B22

# Link Distances (dist1 - dist10)
dist1 = B23
dist2 = B24
dist3 = B25
dist4 = B26
dist5 = B27
dist6 = B28
dist7 = B29
dist8 = B30
dist9 = B31
dist10 = B32

# Link Common Flange Specs
tfw = B33
tfth = B34
bfw = B35
bfth = B36

# ------------------------------------------------------------------
# PART 3: DRAWING LOGIC
# ------------------------------------------------------------------

# Safe Height Limit & Clamping
hh = Min(h1, h2)
h = Min(h_req, hh)

# Column 1 Points (Left Edge Vertical at 0)
P1_BotL = (0, 0)
P1_BotR = (d1, 0)
P1_TopL = (0, h1)
P1_TopR = (d2, h1)

# Column 2 Points (Right Edge Vertical at Bw)
P2_BotR = (Bw, 0)
P2_BotL = (Bw - d3, 0)
P2_TopR = (Bw, h2)
P2_TopL = (Bw - d4, h2)

# Draw Column 1
Col1_LineLeft = Segment(P1_BotL, P1_TopL)
Col1_LineRight = Segment(P1_BotR, P1_TopR)
Col1_LineBot = Segment(P1_BotL, P1_BotR)
Col1_LineTop = Segment(P1_TopL, P1_TopR)

# Draw Column 1 Inner Flanges
P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))
P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))
Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)
P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))
P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))
Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)

# Draw Column 2
Col2_LineLeft = Segment(P2_BotL, P2_TopL)
Col2_LineRight = Segment(P2_BotR, P2_TopR)
Col2_LineBot = Segment(P2_BotL, P2_BotR)
Col2_LineTop = Segment(P2_TopL, P2_TopR)

# Draw Column 2 Inner Flanges
P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))
P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))
Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)
P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))
P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))
Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)

# ------------------------------------------------------------------
# PART 4: REFERENCE LINE & MEZZANINE LOGIC
# ------------------------------------------------------------------

# Stpt: Intersection with C1 Inner Right Flange
Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)
Stpt = (Stpt_x, h)

# Endpt: Intersection with C2 Inner Left Flange
Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)
Endpt = (Endpt_x, h)

# Draw Red Reference Line
RefLine = Segment(Stpt, Endpt)
SetColor(RefLine, "Red")
SetLineThickness(RefLine, 3)

# Extended Outer Points
Lstpt = (0, h)
Rendpt = (Bw, h)

# System Midpoints
MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)
MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)

# Mezzanine Beam Drawing
# Top Line (Always Straight on Reference Line)
MezzTopLine = Segment(MidStpt, MidEndpt)
SetColor(MezzTopLine, "Blue")
SetLineThickness(MezzTopLine, 4)

# Bottom Line Zig-Zag Calculation
# Node 0 (Start)
Mz_Bot0 = (x(MidStpt), h - wd1)

# Node 1
X1 = Min(x(MidStpt) + dist1, x(MidEndpt))
Mz_Bot1 = (X1, h - wd2)

# Node 2
X2 = Min(X1 + dist2, x(MidEndpt))
Mz_Bot2 = (X2, h - wd3)

# Node 3
X3 = Min(X2 + dist3, x(MidEndpt))
Mz_Bot3 = (X3, h - wd4)

# Node 4
X4 = Min(X3 + dist4, x(MidEndpt))
Mz_Bot4 = (X4, h - wd5)

# Drawing Bottom Segments based on NumSeg
# Segment 1
WebBot_Seg1_End = If(NumSeg == 1, (x(MidEndpt), h - wd2), Mz_Bot1)
WebBot1 = Segment(Mz_Bot0, WebBot_Seg1_End)

# Segment 2
WebBot_Seg2_End = If(NumSeg == 2, (x(MidEndpt), h - wd3), Mz_Bot2)
WebBot2 = If(NumSeg >= 2, Segment(Mz_Bot1, WebBot_Seg2_End))

# Segment 3
WebBot_Seg3_End = If(NumSeg == 3, (x(MidEndpt), h - wd4), Mz_Bot3)
WebBot3 = If(NumSeg >= 3, Segment(Mz_Bot2, WebBot_Seg3_End))

# Segment 4
WebBot_Seg4_End = If(NumSeg == 4, (x(MidEndpt), h - wd5), Mz_Bot4)
WebBot4 = If(NumSeg >= 4, Segment(Mz_Bot3, WebBot_Seg4_End))

SetColor(WebBot1, "Green")
SetColor(WebBot2, "Green")
SetColor(WebBot3, "Green")
SetColor(WebBot4, "Green")

# Web Vertical Closure (Start and End)
WebStart = Segment(MidStpt, Mz_Bot0)
# Dynamic end point for web closure
WebEndNode = If(NumSeg==1, WebBot_Seg1_End, If(NumSeg==2, WebBot_Seg2_End, If(NumSeg==3, WebBot_Seg3_End, WebBot_Seg4_End)))
WebEnd = Segment(MidEndpt, WebEndNode)



# ------------------------------------------------------------------
# PART 1: SAFETY CHECK (Initialize Spreadsheet if Empty)
# This ensures no "Undefined Variable" errors if you haven't pasted data yet.
# ------------------------------------------------------------------

# Basic Dimensions (Rows 1-11)
If(IsDefined(A1)==false, SetValue(A1, "Bw"))
If(IsDefined(B1)==false, SetValue(B1, 30))
If(IsDefined(A2)==false, SetValue(A2, "h1"))
If(IsDefined(B2)==false, SetValue(B2, 12))
If(IsDefined(A3)==false, SetValue(A3, "h2"))
If(IsDefined(B3)==false, SetValue(B3, 10))
If(IsDefined(A4)==false, SetValue(A4, "d1"))
If(IsDefined(B4)==false, SetValue(B4, 4))
If(IsDefined(A5)==false, SetValue(A5, "d2"))
If(IsDefined(B5)==false, SetValue(B5, 3))
If(IsDefined(A6)==false, SetValue(A6, "d3"))
If(IsDefined(B6)==false, SetValue(B6, 4))
If(IsDefined(A7)==false, SetValue(A7, "d4"))
If(IsDefined(B7)==false, SetValue(B7, 3))
If(IsDefined(A8)==false, SetValue(A8, "tf1"))
If(IsDefined(B8)==false, SetValue(B8, 0.5))
If(IsDefined(A9)==false, SetValue(A9, "tf2"))
If(IsDefined(B9)==false, SetValue(B9, 0.5))
If(IsDefined(A10)==false, SetValue(A10, "h_req"))
If(IsDefined(B10)==false, SetValue(B10, 8))
If(IsDefined(A11)==false, SetValue(A11, "NumSeg"))
If(IsDefined(B11)==false, SetValue(B11, 3))

# Web Depths (Rows 12-22)
Execute(Sequence("If(IsDefined(A" + (i+11) + ")==false, SetValue(A" + (i+11) + ", ""wd" + i + """))", i, 1, 11))
Execute(Sequence("If(IsDefined(B" + (i+11) + ")==false, SetValue(B" + (i+11) + ", 1.0))", i, 1, 11))

# Distances (Rows 23-32)
Execute(Sequence("If(IsDefined(A" + (i+22) + ")==false, SetValue(A" + (i+22) + ", ""dist" + i + """))", i, 1, 10))
Execute(Sequence("If(IsDefined(B" + (i+22) + ")==false, SetValue(B" + (i+22) + ", 5.0))", i, 1, 10))

# Flange Specs (Rows 33-36) - Simplified to single inputs as requested by "common" practice
If(IsDefined(A33)==false, SetValue(A33, "tfw"))
If(IsDefined(B33)==false, SetValue(B33, 0.3))
If(IsDefined(A34)==false, SetValue(A34, "tfth"))
If(IsDefined(B34)==false, SetValue(B34, 0.02))
If(IsDefined(A35)==false, SetValue(A35, "bfw"))
If(IsDefined(B35)==false, SetValue(B35, 0.3))
If(IsDefined(A36)==false, SetValue(A36, "bfth"))
If(IsDefined(B36)==false, SetValue(B36, 0.02))

# ------------------------------------------------------------------
# PART 2: LINK VARIABLES TO SPREADSHEET CELLS
# ------------------------------------------------------------------

Bw = B1
h1 = B2
h2 = B3
d1 = B4
d2 = B5
d3 = B6
d4 = B7
tf1 = B8
tf2 = B9
h_req = B10
NumSeg = B11

# Link Web Depths (wd1 - wd11)
wd1 = B12
wd2 = B13
wd3 = B14
wd4 = B15
wd5 = B16
wd6 = B17
wd7 = B18
wd8 = B19
wd9 = B20
wd10 = B21
wd11 = B22

# Link Distances (dist1 - dist10)
dist1 = B23
dist2 = B24
dist3 = B25
dist4 = B26
dist5 = B27
dist6 = B28
dist7 = B29
dist8 = B30
dist9 = B31
dist10 = B32

# Link Common Flange Specs
tfw = B33
tfth = B34
bfw = B35
bfth = B36

# ------------------------------------------------------------------
# PART 3: DRAWING LOGIC
# ------------------------------------------------------------------

# Safe Height Limit & Clamping
hh = Min(h1, h2)
h = Min(h_req, hh)

# Column 1 Points (Left Edge Vertical at 0)
P1_BotL = (0, 0)
P1_BotR = (d1, 0)
P1_TopL = (0, h1)
P1_TopR = (d2, h1)

# Column 2 Points (Right Edge Vertical at Bw)
P2_BotR = (Bw, 0)
P2_BotL = (Bw - d3, 0)
P2_TopR = (Bw, h2)
P2_TopL = (Bw - d4, h2)

# Draw Column 1
Col1_LineLeft = Segment(P1_BotL, P1_TopL)
Col1_LineRight = Segment(P1_BotR, P1_TopR)
Col1_LineBot = Segment(P1_BotL, P1_BotR)
Col1_LineTop = Segment(P1_TopL, P1_TopR)

# Draw Column 1 Inner Flanges
P1_FlangeL_Bot = (x(P1_BotL) + tf1, y(P1_BotL))
P1_FlangeL_Top = (x(P1_TopL) + tf1, y(P1_TopL))
Col1_FlangeLeft = Segment(P1_FlangeL_Bot, P1_FlangeL_Top)
P1_FlangeR_Bot = (x(P1_BotR) - tf1, y(P1_BotR))
P1_FlangeR_Top = (x(P1_TopR) - tf1, y(P1_TopR))
Col1_FlangeRight = Segment(P1_FlangeR_Bot, P1_FlangeR_Top)

# Draw Column 2
Col2_LineLeft = Segment(P2_BotL, P2_TopL)
Col2_LineRight = Segment(P2_BotR, P2_TopR)
Col2_LineBot = Segment(P2_BotL, P2_BotR)
Col2_LineTop = Segment(P2_TopL, P2_TopR)

# Draw Column 2 Inner Flanges
P2_FlangeL_Bot = (x(P2_BotL) + tf2, y(P2_BotL))
P2_FlangeL_Top = (x(P2_TopL) + tf2, y(P2_TopL))
Col2_FlangeLeft = Segment(P2_FlangeL_Bot, P2_FlangeL_Top)
P2_FlangeR_Bot = (x(P2_BotR) - tf2, y(P2_BotR))
P2_FlangeR_Top = (x(P2_TopR) - tf2, y(P2_TopR))
Col2_FlangeRight = Segment(P2_FlangeR_Bot, P2_FlangeR_Top)

# ------------------------------------------------------------------
# PART 4: REFERENCE LINE & MEZZANINE LOGIC
# ------------------------------------------------------------------

# Stpt: Intersection with C1 Inner Right Flange
Stpt_x = (d1 - tf1) + ((d2 - tf1) - (d1 - tf1)) * (h / h1)
Stpt = (Stpt_x, h)

# Endpt: Intersection with C2 Inner Left Flange
Endpt_x = (Bw - d3 + tf2) + ((Bw - d4 + tf2) - (Bw - d3 + tf2)) * (h / h2)
Endpt = (Endpt_x, h)

# Draw Red Reference Line
RefLine = Segment(Stpt, Endpt)
SetColor(RefLine, "Red")
SetLineThickness(RefLine, 3)

# Extended Outer Points
Lstpt = (0, h)
Rendpt = (Bw, h)

# System Midpoints
MidStpt = ((x(Lstpt) + x(Stpt)) / 2, h)
MidEndpt = ((x(Endpt) + x(Rendpt)) / 2, h)

# Mezzanine Beam Drawing
# Top Line (Always Straight on Reference Line)
MezzTopLine = Segment(MidStpt, MidEndpt)
SetColor(MezzTopLine, "Blue")
SetLineThickness(MezzTopLine, 4)

# Bottom Line Zig-Zag Calculation
# Node 0 (Start)
Mz_Bot0 = (x(MidStpt), h - wd1)

# Node 1
X1 = Min(x(MidStpt) + dist1, x(MidEndpt))
Mz_Bot1 = (X1, h - wd2)

# Node 2
X2 = Min(X1 + dist2, x(MidEndpt))
Mz_Bot2 = (X2, h - wd3)

# Node 3
X3 = Min(X2 + dist3, x(MidEndpt))
Mz_Bot3 = (X3, h - wd4)

# Node 4
X4 = Min(X3 + dist4, x(MidEndpt))
Mz_Bot4 = (X4, h - wd5)

# Drawing Bottom Segments based on NumSeg
# Segment 1
WebBot_Seg1_End = If(NumSeg == 1, (x(MidEndpt), h - wd2), Mz_Bot1)
WebBot1 = Segment(Mz_Bot0, WebBot_Seg1_End)

# Segment 2
WebBot_Seg2_End = If(NumSeg == 2, (x(MidEndpt), h - wd3), Mz_Bot2)
WebBot2 = If(NumSeg >= 2, Segment(Mz_Bot1, WebBot_Seg2_End))

# Segment 3
WebBot_Seg3_End = If(NumSeg == 3, (x(MidEndpt), h - wd4), Mz_Bot3)
WebBot3 = If(NumSeg >= 3, Segment(Mz_Bot2, WebBot_Seg3_End))

# Segment 4
WebBot_Seg4_End = If(NumSeg == 4, (x(MidEndpt), h - wd5), Mz_Bot4)
WebBot4 = If(NumSeg >= 4, Segment(Mz_Bot3, WebBot_Seg4_End))

SetColor(WebBot1, "Green")
SetColor(WebBot2, "Green")
SetColor(WebBot3, "Green")
SetColor(WebBot4, "Green")

# Web Vertical Closure (Start and End)
WebStart = Segment(MidStpt, Mz_Bot0)
# Dynamic end point for web closure
WebEndNode = If(NumSeg==1, WebBot_Seg1_End, If(NumSeg==2, WebBot_Seg2_End, If(NumSeg==3, WebBot_Seg3_End, WebBot_Seg4_End)))
WebEnd = Segment(MidEndpt, WebEndNode)






Comments

Popular posts from this blog

actions events in itext 7

midi_sequence_playing_real_time

GTTERMS_FORMALIZATION_GEOMETRIFYING_TRIGONOMETRY