import sand3d as s3d
def barrel_vise():
base = s3d.at(pedestal_body(), x=39, y=-37)
clamp = s3d.at(sliding_clamp(), x=39, y=-109.5, z=144)
s3d.joint(&class="tok-comment">#39;joint_clamp_01_joint_00class="tok-string">39;, clamp, on=s3d.local(base, x=0, y=-20, z=268), kind=39;prismaticclass="tok-string">39;, axis=39;+Y39;, range=(0,281.6))
return s3d.assembly(&class="tok-comment">#39;barrel_vise39;, base, clamp)
def pedestal_body(base_d=368, base_h=44, step_d=282, step_h=28, neck_w=151, neck_d=157, neck_h=45, sleeve_d=187, bore=115, sleeve_l=850, sleeve_y=-609, axis_h=268, saddle_w=238, saddle_d=216, saddle_y=-86, saddle_bottom=116, saddle_top=422, crown_w=183, jaw_y=168, jaw_d=146, jaw_bottom=359, jaw_top=551, rail_w=46, rail_t=10, ear_pitch=314, ear_w=24, bed_d=442, bed_y=20, rear_d=160, rear_l=631):
base=s3d.revolve(&class="tok-comment">#39;base39;,s3d.poly([(0,0),(base_d/2,0),(base_d/2,base_h/2),(base_d/2-base_h/2,base_h),(step_d/2+rail_t,base_h),(step_d/2,base_h+step_h),(0,base_h+step_h)]))
neck=s3d.at(s3d.box(&class="tok-comment">#39;neck39;,w=sleeve_d,d=neck_d,h=neck_h+1),z=base_h+step_h-1)
ears=s3d.at(s3d.extrude(&class="tok-comment">#39;ear39;,s3d.slot(l=ear_w*4,d=ear_w),h=base_h/2),on=s3d.ring(n=4,r=ear_pitch/2*2**0.5-ear_w,start=45))
sleeve=s3d.at(s3d.tube(&class="tok-comment">#39;barrel_sleeve39;,d=rear_d,d_in=bore,h=rear_l),y=sleeve_y,z=axis_h,rx=-90)
forward=s3d.at(s3d.tube(&class="tok-comment">#39;forward_sleeve39;,d=sleeve_d,d_in=bore,h=sleeve_l-rear_l+1),y=sleeve_y+rear_l-1,z=axis_h,rx=-90)
rail=s3d.at(s3d.box(&class="tok-comment">#39;top_rail39;,w=rail_w,d=rear_l,h=rail_t),y=sleeve_y+rear_l/2,z=axis_h+rear_d/2-rail_t/5)
lower=s3d.at(s3d.extrude(&class="tok-comment">#39;lower_rail39;,s3d.poly([(-rear_d/2+rail_t,axis_h-rear_d/2-step_h),(-sleeve_d/2,axis_h-rear_d/2),(-sleeve_d/2,axis_h-rear_d/3),(-rear_d/2,axis_h-step_h),(rear_d/2,axis_h-step_h),(sleeve_d/2,axis_h-rear_d/3),(sleeve_d/2,axis_h-rear_d/2),(rear_d/2-rail_t,axis_h-rear_d/2-step_h)]),h=sleeve_l),y=sleeve_y+sleeve_l,rx=90)
bed=s3d.at(s3d.extrude(&class="tok-comment">#39;support_bed39;,s3d.poly([(-bed_d/2,axis_h-sleeve_d/2),(-bed_d/2,axis_h+rail_w+rail_t),(bed_d/2,axis_h+rail_w+rail_t),(bed_d/2,saddle_bottom+step_h),(bed_d/2-step_h*2,saddle_bottom),(-neck_d/2,saddle_bottom)]),h=sleeve_d),x=-sleeve_d/2,y=bed_y,rx=90,rz=90)
recess=s3d.extrude(&class="tok-comment">#39;triangular_recess39;,s3d.poly([(-bed_d/6+rail_t,0),(bed_d/6-rail_t,0),(bed_d/6-rail_t,rail_w*2)]),h=rail_t)
recess=s3d.at(recess,on=s3d.grid(nx=1,ny=3,py=bed_d/3),x=sleeve_d/2-rail_t/2,y=bed_y,z=axis_h-rear_d/2,rx=90,rz=90)
reflected=[s3d.transform(s3d.copy(tool),mirror=&class="tok-comment">#39;x39;) for tool in recess]
bed=s3d.cut(bed,recess,reflected)
saddle=s3d.at(s3d.extrude(&class="tok-comment">#39;saddle39;,s3d.poly([(-saddle_w/2,axis_h+sleeve_d/2-rail_t),(-saddle_w/2,saddle_top-step_h),(-saddle_w/2+step_h,saddle_top),(saddle_w/2-step_h,saddle_top),(saddle_w/2,saddle_top-step_h),(saddle_w/2,axis_h+sleeve_d/2-rail_t)]),h=saddle_d),y=saddle_y+saddle_d/2,rx=90)
jaw=s3d.at(s3d.extrude(&class="tok-comment">#39;fixed_jaw39;,s3d.poly([(-jaw_d/2,jaw_bottom),(-jaw_d/2,jaw_top-jaw_d/2),(-jaw_d/2+rail_w,jaw_top-step_h),(-jaw_d/2+rail_w*2,jaw_top),(jaw_d/2,jaw_top),(jaw_d/2,jaw_bottom)]),h=crown_w),x=-crown_w/2,y=jaw_y,rx=90,rz=90)
crown=s3d.at(s3d.box(&class="tok-comment">#39;fixed_crown39;,w=crown_w,d=jaw_d/2,h=step_h),y=jaw_y+jaw_d/2-rail_t,z=jaw_top-step_h)
jaw=s3d.join(jaw,crown)
notch=s3d.at(s3d.box(&class="tok-comment">#39;jaw_cheek_recess39;,w=rail_w,d=jaw_d+rail_t,h=rail_w),x=crown_w/2,y=jaw_y,z=jaw_bottom-1)
jaw=s3d.cut(jaw,notch,s3d.transform(s3d.copy(notch),mirror=&class="tok-comment">#39;x39;))
result=s3d.group(&class="tok-comment">#39;pedestal_body39;,base,neck,ears,sleeve,forward,rail,lower,bed,saddle,jaw)
s3d.material(result,kind=&class="tok-comment">#39;painted_metalclass="tok-string">39;,color=39;#646b6939;)
return result
def sliding_clamp(rod_d=115, rod_l=1070, rod_y=-556.5, axis_h=124, end_d=187, end_l=145, end_y=366.5, end_bottom=0, jaw_w=183, jaw_d=146, jaw_y=438.5, jaw_bottom=206, jaw_top=407, collar_d=145, collar_l=46, opening_w=123, opening_h=64, foot_w=145, crown_step=31, panel_t=7, panel_h=45, hole_d=50):
rod=s3d.cylinder(&class="tok-comment">#39;sliding_rod39;,d=rod_d,h=rod_l)
s3d.hole(rod,d=rod_d/2,on=rod.face(&class="tok-comment">#39;bottom39;),depth=crown_step)
rod=s3d.at(rod,y=rod_y,z=axis_h,rx=-90)
housing=s3d.at(s3d.cylinder(&class="tok-comment">#39;end_housing39;,d=end_d,h=end_l),y=end_y,z=axis_h,rx=-90)
foot=s3d.at(s3d.extrude(&class="tok-comment">#39;housing_foot39;,s3d.poly([(-foot_w/2,end_bottom),(-end_d/2,26),(-end_d/2,axis_h),(end_d/2,axis_h),(end_d/2,26),(foot_w/2,end_bottom)]),h=end_l),y=end_y+end_l,rx=90)
panel=s3d.at(s3d.extrude(&class="tok-comment">#39;foot_panel39;,s3d.poly([(-end_l/2+panel_t,0),(end_l/2-panel_t,0),(-end_l/2+panel_t,panel_h)]),h=panel_t),x=end_d/2-panel_t/2,y=end_y+end_l/2,z=crown_step,rx=90,rz=90)
foot=s3d.cut(foot,panel,s3d.transform(s3d.copy(panel),mirror=&class="tok-comment">#39;x39;))
collar=s3d.at(s3d.cylinder(&class="tok-comment">#39;end_collar39;,d=collar_d,h=collar_l),y=end_y+end_l-1,z=axis_h,rx=-90)
jaw=s3d.at(s3d.extrude(&class="tok-comment">#39;moving_jaw39;,s3d.poly([(-jaw_d/2,jaw_bottom),(-jaw_d/2,jaw_top),(-jaw_d/2+collar_l,jaw_top),(-jaw_d/2+collar_l,jaw_top-crown_step),(jaw_d/2-collar_l,jaw_top-crown_step),(jaw_d/2,326),(jaw_d/2,jaw_bottom)]),h=jaw_w),x=-jaw_w/2,y=jaw_y,rx=90,rz=90)
contour=s3d.at(s3d.extrude(&class="tok-comment">#39;lower_jaw_contour39;,s3d.poly([(-jaw_w/2,jaw_top+1),(jaw_w/2,jaw_top+1),(jaw_w/2,jaw_bottom+opening_h),(opening_w/2,jaw_bottom+opening_h),(opening_w/2,jaw_bottom+crown_step),(crown_step,jaw_bottom),(-crown_step,jaw_bottom),(-opening_w/2,jaw_bottom+crown_step),(-opening_w/2,jaw_bottom+opening_h),(-jaw_w/2,jaw_bottom+opening_h)]),h=jaw_d+2),y=jaw_y+jaw_d/2+1,rx=90)
jaw=s3d.intersect(jaw,contour)
s3d.hole(jaw,d=hole_d,on=(0,jaw_y),depth=collar_l*2)
body=s3d.group(&class="tok-comment">#39;clamp_casting39;,rod,housing,foot,collar,jaw)
s3d.material(body,kind=&class="tok-comment">#39;painted_metalclass="tok-string">39;,color=39;#646b6939;)
hub=s3d.at(handle_hub(),y=572,z=91)
s3d.joint(&class="tok-comment">#39;joint_head_01_joint_00class="tok-string">39;,hub,on=s3d.local(body,x=0,y=571.5,z=124),kind=39;continuousclass="tok-string">39;,axis=39;+Y39;)
return s3d.group(&class="tok-comment">#39;sliding_clamp39;,body,hub)
def handle_hub(d=66,l=119,edge_r=4):
solid=s3d.cylinder(&class="tok-comment">#39;hub39;,d=d,h=l)
solid=s3d.fillet(solid,r=edge_r,edges=&class="tok-comment">#39;top bottom39;)
solid=s3d.at(solid,y=-l/2,z=d/2,rx=-90)
s3d.material(solid,kind=&class="tok-comment">#39;steelclass="tok-string">39;,color=39;#777c7e39;)
shaft=s3d.at(ball_crossbar(),y=17.5,z=-214)
s3d.joint(&class="tok-comment">#39;joint_shaft_01_joint_00class="tok-string">39;,shaft,on=s3d.local(solid,x=0,y=18,z=34),kind=39;prismaticclass="tok-string">39;,axis=39;+Z39;,range=(-157.6,155.5))
return s3d.group(&class="tok-comment">#39;handle_hub39;,solid,shaft)
def ball_crossbar(d=27,ball_d=54,h=493):
shaft = s3d.at(s3d.cylinder(&class="tok-comment">#39;crossbar39;,d=d,h=h-ball_d),z=ball_d/2)
bottom = s3d.sphere(&class="tok-comment">#39;bottom_ball39;,d=ball_d)
top = s3d.at(s3d.sphere(&class="tok-comment">#39;top_ball39;,d=ball_d),z=h-ball_d)
result=s3d.group(&class="tok-comment">#39;ball_crossbar39;,shaft,bottom,top)
s3d.material(result,kind=&class="tok-comment">#39;steelclass="tok-string">39;,color=39;#81868839;)
return result