Advertisement
Guest User

Untitled

a guest
Mar 30th, 2025
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. from openscad import *
  2. from collections import namedtuple
  3. from collections import OrderedDict
  4. Button=namedtuple('Button', ['body', 'label'])
  5.  
  6. width = 10.8;
  7. height = 6.9;
  8. depth = 4.8;
  9. stopper_extra_width = -1.9;
  10. stopper_extra_height = 1;
  11. stopper_depth = 2.4;
  12.  
  13. text_size = 2.8;
  14. text_depth = 0.4;
  15.  
  16. distance = 5;
  17.  
  18. def button(caption):
  19.     label=text(
  20.         caption, halign="center", valign="center",
  21.         size=text_size, font="Arial:style=Black"
  22.     ).linear_extrude(text_depth)
  23.    
  24.     stopper=union(
  25.         square(
  26.             [width+stopper_extra_width,
  27.              height+stopper_extra_height],
  28.             center=True
  29.         ),
  30.         square([width,height], center=True)
  31.     ).linear_extrude(stopper_depth)
  32.  
  33.     body=square([width, height], center=True)\
  34.         .linear_extrude(height)
  35.  
  36.     all = union(stopper, body.up(stopper_depth))
  37.     all = all - label.up(stopper_depth+height-text_depth)
  38.        
  39.     return Button(
  40.         body=all,
  41.         label=label.up(stopper_depth+height-text_depth),
  42.     )
  43.  
  44.  
  45. all = [
  46.     ["D", "MNU"],
  47.     ["FPL", "PRC"],
  48.     ["CLR", "ENT"],
  49.     ["AP", "FD"],
  50.     ["HDG", "ALT"],
  51.     ["NAV", "VNV"],
  52.     ["APR", "BC"],
  53.     ["VS", "UP"],
  54.     ["FLC", "DN"]
  55. ]
  56.  
  57. bodies=[]
  58. labels=[]
  59. for i, row in enumerate(all):
  60.     for j, col in enumerate(row):
  61.         b=button(col)
  62.         def displace(o):
  63.             return o.front(i*(width+distance))\
  64.                     .right(j*(width+distance))
  65.  
  66.         bodies.append(displace(b.body.color("black")))
  67.         labels.append(displace(b.label.color("white")))
  68.  
  69. exports={}
  70. for i, body in enumerate(bodies):
  71.     exports["body_%s" % i]=body
  72. for i, label in enumerate(labels):
  73.     exports["label_%s" % i]=label
  74.  
  75. show(union(*exports.values()))
  76. export(exports,"buttons.3mf")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement