-
Notifications
You must be signed in to change notification settings - Fork 59
Description
Dave @rosenhauer
You have done incredibly beautiful work expanding and improving this library.
However, when generating simple project boxes I regularly run into problems.
There really need to be examples for generating “Shapes”.
Preferably both for the pre-defined shapes and examples showing how to create a custom shape.
The issue I am currently running into occurs in this program:
//-----------------------------------------------------------------------
// Yet Another Parameterized Projectbox generator
//
// This is a box for a handheldAerosolSensor
//
// Version 0.1.0 (2026-03-10)
//
// This design is parameterized based on the size of a PCB.
//
// For many/complex cutoutGrills, you might need to adjust
// the max number of elements in OpenSCAD:
//
// Preferences->Advanced->Turn off rendering at 250000 elements
// ^^^^^^
//
//-----------------------------------------------------------------------
include <./YAPPgenerator_v3.3.8.scad>
$fn=20;
myPcb = "handheldAerosolSensor.stl";
if (true)
{
translate([56.8, 39.5 , 24])
{
rotate([0,0,180]) color("gray") import(myPcb);
}
}
//---------------------------------------------------------
// This design is parameterized based on the size of a PCB.
//---------------------------------------------------------
// Note: length/lengte refers to X axis,
// width/breedte refers to Y axis,
// height/hoogte refers to Z axis
/*
padding-back|<------pcb length --->|<padding-front
RIGHT
0 X-axis --->
+----------------------------------------+ ---
| | ^
| | padding-right
Y | | v
| | -5,y +----------------------+ | ---
B a | | 0,y x,y | | ^ F
A x | | | | | R
C i | | | | | pcb width O
K s | | | | | N
| | 0,0 x,0 | | v T
^ | -5,0 +----------------------+ | ---
| | | padding-left
0 +----------------------------------------+ ---
0 X-as --->
LEFT
*/
//-- which part(s) do you want to print?
printBaseShell = true;
printLidShell = true;
printSwitchExtenders = true;
printDisplayClips = false;
// ********************************************************************
// The Following will be used as the first element in the pbc array
//Defined here so you can define the "Main" PCB using these if wanted
pcbLength = 100; // front to back (X axis)
pcbWidth = 65; // side to side (Y axis)
pcbThickness = 1.7;
standoffHeight = 22; // 10.1; //-- How much the PCB needs to be raised from the base to leave room for solderings and whatnot
standoffDiameter = 4;
standoffPinDiameter = 2.0;
standoffHoleSlack = 0.4;
//===================================================================
// *** PCBs ***
// Printed Circuit Boards
//-------------------------------------------------------------------
// Default origin = yappCoordPCB : yappCoordBoxInside[0,0,0]
//
// Parameters:
// Required:
// p(0) = name
// p(1) = length
// p(2) = width
// p(3) = posx
// p(4) = posy
// p(5) = Thickness
// p(6) = standoff_Height = Height to bottom of PCB from the inside of the base
// negative measures from inside of the lid to the top of the PCB
// p(7) = standoff_Diameter
// p(8) = standoff_PinDiameter
// Optional:
// p(9) = standoff_HoleSlack (default to 0.4)
//The following can be used to get PCB values elsewhere in the script - not in pcb definition.
//If "PCB Name" is omitted then "Main" is used
// pcbLength --> pcbLength("PCB Name")
// pcbWidth --> pcbWidth("PCB Name")
// pcbThickness --> pcbThickness("PCB Name")
// standoffHeight --> standoffHeight("PCB Name")
// standoffDiameter --> standoffDiameter("PCB Name")
// standoffPinDiameter --> standoffPinDiameter("PCB Name")
// standoffHoleSlack --> standoffHoleSlack("PCB Name")
pcb =
[
// Default Main PCB - DO NOT REMOVE the "Main" line.
["Main", pcbLength, pcbWidth, 0, 0, pcbThickness, standoffHeight, standoffDiameter, standoffPinDiameter, standoffHoleSlack]
];
//-------------------------------------------------------------------
//-- padding between pcb and inside wall
paddingFront = 50;
paddingBack = 5;
paddingRight = 5;
paddingLeft = 5;
//-- Edit these parameters for your own box dimensions
wallThickness = 2.0;
basePlaneThickness = 2.0;
lidPlaneThickness = 2.0;
//-- Total height of box = lidPlaneThickness
// + lidWallHeight
//-- + baseWallHeight
// + basePlaneThickness
//-- space between pcb and lidPlane :=
//-- (bottonWallHeight+lidWallHeight) - (standoffHeight+pcbThickness)
baseWallHeight = 20;
lidWallHeight = 20;
//-- ridge where base and lid off box can overlap
//-- Make sure this isn't less than lidWallHeight
ridgeHeight = 5.0;
ridgeSlack = 0.2; // Gap between the inside of the lid and the outside of the base
//New in v3.3.7
ridgeGap = 0.5; // Gap between the bottom of the base ridge and the bottom of the lid when assembled.
roundRadius = 10.0;
// Box Types are 0-4 with 0 as the default
// 0 = All edges rounded with radius (roundRadius) above
// 1 = All edges sqrtuare
// 2 = All edges chamfered by (roundRadius) above
// 3 = Square top and bottom edges (the ones that touch the build plate) and rounded vertical edges
// 4 = Square top and bottom edges (the ones that touch the build plate) and chamfered vertical edges
// 5 = Chanfered top and bottom edges (the ones that touch the build plate) and rounded vertical edges
boxType = 0; // Default type 0
// Set the layer height of your printer
printerLayerHeight = 0.2;
//---------------------------
//-- C O N T R O L --
//---------------------------
// -- Render --
renderQuality = 8; //-> from 1 to 32, Default = 8
// --Preview --
previewQuality = 5; //-> from 1 to 32, Default = 5
showSideBySide = true; //-> Default = true
onLidGap = 0; // tip don't override to animate the lid opening
colorLid = "YellowGreen";
alphaLid = 1;
colorBase = "BurlyWood";
alphaBase = 1;
hideLidWalls = false; //-> Remove the walls from the lid : only if preview and showSideBySide=true
hideBaseWalls = false; //-> Remove the walls from the base : only if preview and showSideBySide=true
showOrientation = true; //-> Show the Front/Back/Left/Right labels : only in preview
showPCB = false; //-> Show the PCB in red : only in preview
showSwitches = false; //-> Show the switches (for pushbuttons) : only in preview
showButtonsDepressed = false; //-> Should the buttons in the Lid On view be in the pressed position
showOriginCoordBox = false; //-> Shows red bars representing the origin for yappCoordBox : only in preview
showOriginCoordBoxInside = false; //-> Shows blue bars representing the origin for yappCoordBoxInside : only in preview
showOriginCoordPCB = false; //-> Shows blue bars representing the origin for yappCoordBoxInside : only in preview
showMarkersPCB = false; //-> Shows black bars corners of the PCB : only in preview
showMarkersCenter = false; //-> Shows magenta bars along the centers of all faces
inspectX = 70; //-> 0=none (>0 from Back)
inspectY = 0; //-> 0=none (>0 from Right)
inspectZ = 0; //-> 0=none (>0 from Bottom)
inspectXfromBack = true; //-> View from the inspection cut foreward
inspectYfromLeft = true; //-> View from the inspection cut to the right
inspectZfromBottom = true; //-> View from the inspection cut up
//---------------------------
//-- C O N T R O L --
//---------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Start of Debugging config (used if not overridden in template)
// ------------------------------------------------------------------
// ------------------------------------------------------------------
//==================================================================
// *** Shapes ***
//------------------------------------------------------------------
// There are a view pre defines shapes and masks
// shapes:
// shapeIsoTriangle, shapeHexagon, shape6ptStar
//
// masks:
// maskHoneycomb, maskHexCircles, maskBars, maskOffsetBars
//
//------------------------------------------------------------------
// Shapes should be defined to fit into a 1x1 box (+/-0.5 in X and Y) - they will
// be scaled as needed.
// defined as a vector of [x,y] vertices pairs.(min 3 vertices)
// for example a triangle could be [yappPolygonDef,[[-0.5,-0.5],[0,0.5],[0.5,-0.5]]];
// To see how to add your own shapes and mask see the YAPPgenerator program
//------------------------------------------------------------------
//===================================================================
// *** Connectors ***
// Standoffs with hole through base and socket in lid for screw type connections.
//-------------------------------------------------------------------
// Default origin = yappCoordPCB : pcb[0,0,0]
//
// Parameters:
// Required:
// p(0) = posx
// p(1) = posy
// p(2) = StandHeight : From specified origin
// p(3) = screwDiameter
// p(4) = screwHeadDiameter (don't forget to add extra for the fillet or specify yappNoInternalFillet)
// p(5) = insertDiameter
// p(6) = outsideDiameter
// Optional:
// p(7) = insert Depth : default to entire connector
// p(8) = PCB Gap : Default if yappCoordPCB then pcbThickness else 0
// p(9) = filletRadius : Default = 0/Auto(0 = auto size)
// n(a) = { yappAllCorners, yappFrontLeft | <yappBackLeft> | yappFrontRight | yappBackRight }
// n(b) = { <yappCoordPCB> | yappCoordBox | yappCoordBoxInside }
// n(c) = { yappNoFillet } : Don't add fillets
// n(d) = { yappCountersink }
// n(e) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
// n(f) = { yappThroughLid = changes the screwhole to the lid and the socket to the base}
// n(g) = {yappSelfThreading} : Make the insert self threading specify the Screw Diameter in the insertDiameter
// n(h) = { yappNoInternalFillet } : Don't add internal fillets (external fillets can still be added)
//-------------------------------------------------------------------
connectors =
[
//- 0, 1, 2, 3, 4, 5, 6, 7, -rest-
[3.5, 3.5, standoffHeight, 2.5, 4.5, 3.5, 7, default, yappAllCorners, yappCoordPCB, "Main"]
];
//===================================================================
// *** Cutouts ***
// There are 6 cutouts one for each surface:
// cutoutsBase (Bottom), cutoutsLid (Top), cutoutsFront, cutoutsBack, cutoutsLeft, cutoutsRight
//-------------------------------------------------------------------
// Default origin = yappCoordBox: box[0,0,0]
//
// Required Not Used Note
//----------------------+-----------------------+---------------+------------------------------------
// yappRectangle | width, length | radius |
// yappCircle | radius | width, length |
// yappRoundedRect | width, length, radius | |
// yappCircleWithFlats | width, radius | length | length=distance between flats
// yappCircleWithKey | width, length, radius | | width = key width length=key depth
// | | | (negative indicates outside of circle)
// yappPolygon | width, length | radius | yappPolygonDef object must be
// | | | provided
// yappRing | width, length, radius | | radius = outer radius,
// | | | length = inner radius
// | | | width = connection between rings
// | | | 0 = No connectors
// | | | positive = 2 connectors
// | | | negative = 4 connectors
// yappSphere | width, radius | | Width = Sphere center distance from
// | | | center of depth. negative = below
// | | | radius = sphere radius
//----------------------+-----------------------+---------------+------------------------------------
//
// Parameters:
// Required:
// p(0) = from Back
// p(1) = from Left
// p(2) = width
// p(3) = length
// p(4) = radius
// p(5) = shape : { yappRectangle | yappCircle | yappPolygon | yappRoundedRect
// | yappCircleWithFlats | yappCircleWithKey | yappSphere }
// Optional:
// p(6) = depth : Default = 0/Auto : 0 = Auto (plane thickness)
// p(7) = angle : Default = 0
// n(a) = { yappPolygonDef } : Required if shape = yappPolygon specified -
// n(b) = { yappMaskDef } : If a yappMaskDef object is added it will be used as a mask
// for the cutout.
// n(c) = { [yappMaskDef, hOffset, vOffset, rotation] } : If a list for a mask is added
// it will be used as a mask for the cutout. With the Rotation
// and offsets applied. This can be used to fine tune the mask
// placement within the opening.
// n(d) = { <yappCoordPCB> | yappCoordBox | yappCoordBoxInside }
// n(e) = { <yappOrigin>, yappCenter }
// n(f) = { <yappGlobalOrigin>, yappAltOrigin } // Only affects Top(lid), Back and Right Faces
// n(g) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
// n(h) = { yappFromInside } Make the cut from the inside towards the outside
//-------------------------------------------------------------------
cutoutsLid =
[
// 0, 1, 2, 3, 4, 5, --rest--
[pcbLength+21, 31, 31, 31, 1, yappRoundedRect, 3, yappCenter, yappCoordPCB] //-- ePaper Display
// 0, 1, 2, 3, 4, 5, --rest--
,[pcbLength+8, 12, 4, 4, 2, yappCircle, 3, yappCenter, yappCoordPCB] //-- ePaper Mounting Hole
,[pcbLength+8, 50, 4, 4, 2, yappCircle, 3, yappCenter, yappCoordPCB] //-- ePaper Mounting Hole
,[pcbLength+34, 12, 4, 4, 2, yappCircle, 3, yappCenter, yappCoordPCB] //-- ePaper Mounting Hole
,[pcbLength+34, 50, 4, 4, 2, yappCircle, 3, yappCenter, yappCoordPCB] //-- ePaper Mounting Hole
];
cutoutsFront =
[
// 0, 1, 2, 3, 4, 5, 6, --rest--
[39, 7, 41, 12, 1, yappRoundedRect, 20, yappCenter, yappCoordBox] //-- SPS30 Air Quality Sensor
];
cutoutsLeft =
[
// 0 1 2 3 4 5 6
[60, -10, 14.5, 8, 1, yappRoundedRect, yappCenter, yappCoordPCB] //-- USB.
];
//===================================================================
// *** Snap Joins ***
//-------------------------------------------------------------------
// Default origin = yappCoordBox: box[0,0,0]
//
// Parameters:
// Required:
// p(0) = posx | posy
// p(1) = width
// p(2) = { yappLeft | yappRight | yappFront | yappBack } : one or more
// Optional:
// n(a) = { <yappOrigin>, yappCenter }
// n(b) = { yappSymmetric }
// n(c) = { yappRectangle } == Make a diamond shape snap
//-------------------------------------------------------------------
snapJoins =
[
[20, 5, yappBack, yappFront, yappCenter, yappSymmetric]
,[20, 5, yappLeft, yappRight, yappCenter, yappSymmetric]
];
//===================================================================
// *** Push Buttons ***
//-------------------------------------------------------------------
// Default origin = yappCoordPCB: PCB[0,0,0]
//
// Parameters:
// Required:
// p(0) = posx
// p(1) = posy
// p(2) = capLength
// p(3) = capWidth
// p(4) = capRadius
// p(5) = capAboveLid
// p(6) = switchHeight
// p(7) = switchTravel
// p(8) = poleDiameter
// Optional:
// p(9) = Height to top of PCB : Default = standoffHeight + pcbThickness
// p(10) = { yappRectangle | yappCircle | yappPolygon | yappRoundedRect
// | yappCircleWithFlats | yappCircleWithKey } : Shape, Default = yappRectangle
// p(11) = angle : Default = 0
// p(12) = filletRadius : Default = 0/Auto
// p(13) = buttonWall : Default = 2.0;
// p(14) = buttonPlateThickness : Default= 2.5;
// p(15) = buttonSlack : Default= 0.25;
// n(a) = { <yappCoordPCB> | yappCoordBox | yappCoordBoxInside }
// n(b) = { <yappGlobalOrigin>, yappAltOrigin }
// n(c) = { yappNoFillet }
// n(d) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
//-------------------------------------------------------------------
pushButtons =
[
// 0, 1, 2, 3, 4, 5, 6, 7, 8, --rest--
[64, 31, 15, 15, 7, 2.5, 4, 2, 5, default, yappCircle, 0, default, default, default, default, yappCoordPCB]
];
// **********************************************************
// **********************************************************
// **********************************************************
// *************** END OF TEMPLATE SECTION ******************
// **********************************************************
// **********************************************************
// **********************************************************
//---- This is where the magic happens ----
YAPPgenerate();
//------
translate([103,4,2]) color("black") rotate([0,0,0]) cube ([1,2,22]);
The PCB should be positioned (approximately) 22 mm above the inside of the base.
Intuitively, standoffHeight should therefore also be 22. But when I do that, I get this:
The black bar is exactly 22 mm high and starts exactly at the top of basePlaneThickness.
Only when I set:
standoffHeight = 10.1;
do the standoffs appear to have the right height:
The pushbutton column is also much to long:
Only when I change p(9) of pushButtons from default to 22 does the height appear to be correct.