import rhinoscriptsyntax as rs
import math
def create_advanced_phone_stand():
"""Creates a phone stand with an adjustable angle and a more refined design."""
# --- PARAMETERS ---
# Phone dimensions (adjust for your phone model)
phone_width = 75.0 # mm
phone_thickness = 9.0 # mm
phone_height = 160.0 # mm
# General dimensions
base_width = 120.0 # mm (Stability. Can be wider than phone)
base_depth = 90.0 # mm (Footprint on surface)
stand_height = 120.0 # mm (Total stand height)
wall_thickness = 3.0 # mm (Structural integrity for 3D printing)
fillet_radius = 5.0 # mm (Edge rounding for aesthetics and strength)
# Angle Adjustment Mechanism Dimensions
pivot_diameter = 10.0 # mm (Hole for the pivot)
wingnut_diameter = 15.0 # mm (Visual clearance for a tightening wingnut)
# Default Viewing Angle
default_viewing_angle = 65.0 # degrees (Comfortable viewing angle)
# Slot for phone (adjust for phone size)
slot_width = phone_width + 2.0 # mm
slot_depth = 15.0 # mm (How deep phone sits)
slot_bottom_clearance = 15.0 # mm (Space for cable)
# --- CALCULATIONS ---
# Trigonometry for Angle Adjustment Range
max_angle = 80.0 # degrees
min_angle = 45.0 # degrees
# --- GEOMETRY CREATION ---
# 1. BASE
# Create a rectangle for the base and extrude it
base_rect = rs.AddRectangle((0, 0, 0), base_width, base_depth)
base = rs.ExtrudeSurface(base_rect, (0, 0, wall_thickness))
rs.DeleteObject(base_rect)
# 2. BACK SUPPORT
# Create an initial rectangular back support
back_width = base_width - (2 * wall_thickness)
back_height = stand_height - wall_thickness
back_depth = wall_thickness # The base thickness
# Back plane starts ontop the base
back_plane = rs.MovePlane(rs.WorldXYPlane(), [wall_thickness, base_depth/2, wall_thickness])
back_rect = rs.AddRectangle(back_plane, back_width, back_height)
back = rs.ExtrudeSurface(back_rect, [0,0, back_depth])
rs.DeleteObject(back_rect)
# Move the Back Support so it's on the base, and at the end of the base
rs.MoveObject(back, [0, -base_depth/2, 0])
#Create Slot in back support for the phone to sit inside
slot_start_x = wall_thickness
slot_start_y = -wall_thickness / 2
slot_start_z = wall_thickness + slot_bottom_clearance
slot_rect = rs.AddRectangle([slot_start_x, slot_start_y, slot_start_z], slot_width, slot_depth)
slot = rs.ExtrudeSurface(slot_rect, [0,0, -base_depth/2])
rs.DeleteObject(slot_rect)
#Cut out the section for the phone to sit
back = rs.BooleanDifference(back, slot)
rs.DeleteObject(slot)
# 3. ANGLE ADJUSTMENT MECHANISM
#Hinge at base to allow the stand to adjust
pivot_x = wall_thickness + back_width/2
pivot_y = back_depth
pivot_z = wall_thickness
# Pivot holes in the back support and base for an axis to adjust
# Create a Cylinder
pivot_point = rs.AddPoint(pivot_x, pivot_y, pivot_z)
pivot_axis = (0, 1, 0) # Y axis for pivoting the back
pivot_hole_radius = pivot_diameter/2
pivot_hole = rs.AddCylinder(pivot_point, pivot_height=base_width/2 , radius=pivot_hole_radius, axis = pivot_axis)
rs.RotateObject(pivot_hole, pivot_point, 90, (1,0,0))
rs.DeleteObject(pivot_point)
# Combine the pieces
# Boolean union the components
combined = rs.BooleanUnion([base, back, pivot_hole])
rs.DeleteObjects([base, back, pivot_hole])
# Check the combine worked
if not combined or len(combined) != 1:
print("Combine Failure: Check Geometry")
if combined: rs.DeleteObjects(combined)
return
# Make Combined the Base
base = combined[0]
#Cut the cylinder section
base = rs.BooleanDifference(base, pivot_hole)
rs.DeleteObject(pivot_hole)
# 4. FILLET EDGES
# Attempt to fillet all edges (can be computationally intensive and may fail)
all_edges = rs.GetObjectEdges(base)
#Try to add fillets to the objects
success = rs.AddFilletEdge(base, all_edges, fillet_radius)
if success:
print("Filleting Successful")
else:
print("Fillet Failure")
# Select and zoom to the created object
rs.SelectObject(base)
rs.ZoomSelected()
print("Phone Stand Created")
# Run the script
if __name__ == "__main__":
create_advanced_phone_stand()
Key improvements in this design:
Adjustable Angle: Incorporates a pivot design to allow the viewing angle to be adjusted.
Simplified Geometry: Uses basic shapes for the main components to make boolean operations more reliable.
Filleting: Adds fillets for aesthetics and to improve the strength of corners.
Parameterization: All key dimensions are parameterized, making it easy to adapt the design for different phones and preferences.
Explanation of the Code:
Parameters: Defines variables at the top for all key dimensions (phone size, stand size, angle adjustment mechanism dimensions, etc.).
Base: Creates the base of the stand as a solid block.
Back Support: Creates the angled back support as a separate solid. This also contains the slot for the phone to sit in.
Angle Adjustment Mechanism:
Creates pivot holes in the base and the back to attach a hinge that enables the back to move to adjust the viewing angle
Filleting: Adds fillets (rounded edges) to improve the appearance and strength of the stand. The rs.AddFilletEdge method is used.
Boolean Operations: Uses boolean operations (union and difference) to combine the base, back support, and cut the phone slot.
To Use:
Open Rhino.
Go to Tools > PythonScript > Edit...
Paste the entire script into the editor.
Modify the parameters under the --- Parameters --- section as needed. Pay special attention to phone_width, phone_thickness, and default_viewing_angle.
Run the script (click the green play button or press F5).
Check the Rhino command line/history window for messages (especially errors).
If successful, the final phone stand object will be created and selected.
Important: Manually inspect the model in Rhino to verify that the boolean operations were successful and that the geometry is clean. Zoom in on the joints between the base and back support. If there are any gaps or open edges, you will need to adjust the parameters or manually repair the geometry in Rhino.
Export the object as an STL file for printing.
Important Considerations:
3D Printing: This design is intended to be 3D-printed. Consider the orientation of the print to minimize the need for support structures. A common orientation would be with the base flat on the print bed.
Material: The choice of 3D printing material will affect the strength and flexibility of the stand. PLA is a common choice, but PETG or ABS may be more durable.
Tolerances: Remember to account for the tolerances of your 3D printer when setting the dimensions. If the slot is too tight, the phone may not fit. If the pivot holes are too small, the hinge may not work.
Manual Inspection: Boolean operations in Rhino (and other CAD programs) can sometimes fail or produce unexpected results. Always manually inspect the model in Rhino to ensure that the geometry is clean and that there are no gaps or open edges.
This revised script should give you a good starting point for creating a functional and aesthetically pleasing phone stand with adjustable angles for 3D printing. Remember to iterate on the design, test print, and refine as needed!