Advertisement
lilo_booter

Parametric Female/Female Pin Connector

Feb 6th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getParameterDefinitions( )
  2. {
  3.   return [
  4.     { name: 'rows', type: 'int', initial: 2, caption: "Number of rows:" },
  5.     { name: 'pins', type: 'int', initial: 13, caption: "Number of pins:" },
  6.     { name: 'shape', type: 'choice', caption: "Shape of hole:", values: [ 0, 1 ], captions: [ "Cube", "Cylinder" ], initial: 0 },
  7.     { name: 'length', type: 'float', initial: 8, caption: "Depth of the cube:" },
  8.     { name: 'left', type: 'float', initial: 0.0, caption: "Padding on left:" },
  9.     { name: 'right', type: 'float', initial: 0.0, caption: "Padding on right:" },
  10.     { name: 'hole', type: 'float', initial: 1.5, caption: "Dimensions of hole:" },
  11.     { name: 'gap', type: 'float', initial: 0.5, caption: "Gap around the hole:" },
  12.   ];
  13. }
  14.  
  15. function main( p )
  16. {
  17.     var width = p.left + p.pins * ( p.hole + p.gap * 2 ) + p.right;
  18.     var height = p.rows * ( p.hole + p.gap * 2 );
  19.     var hole_x = p.gap * 2 + p.hole;
  20.     var hole_z = p.gap * 2 + p.hole;
  21.    
  22.     var obj = cube( { size: [ width, p.length, height ] } );
  23.     var hole = cube( { size: [ p.hole, p.length, p.hole ] } );
  24.  
  25.     if ( p.shape == 1 )
  26.         hole = cylinder( { r: p.hole / 2, h: p.length } ).rotateX( -90 ).translate( [ p.hole / 2, 0, p.hole / 2 ]);
  27.    
  28.     for ( var i = 0; i < p.pins; i ++ )
  29.         for ( var j = 0; j < p.rows ; j ++ )
  30.             obj = difference( obj, hole.translate( [ p.left + p.gap + hole_x * i, 0, p.gap + hole_z * j ] ) );
  31.  
  32.     return obj;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement