/Boxes/Clip.foocad

A clip to keep a hinged box closed.
Glue the two orange piece to a hinged box, so that it can be closed
Notes
I've not tried this (yet).
My original hinged box had the orange piece built-in, which don't work very well. Alas, I never got around to trying this solution.
import static uk.co.nickthecoder.foocad.chamferedextrude.v1.ChamferedExtrude.*
class Clip : AbstractModel() {
@Custom( about="Size of the pegs (length and height" )
var size = Vector2( 40, 20 )
@Custom( about="Gap between the two pegs" )
var gap = 2.0
@Custom( about="How much smaller are the pegs compared to the slots the go inside" )
var slack = 0.3
@Custom( about="Thickess of the peg's back plate, which will be stuck to the box")
var backT = 1.0
@Custom(about="Radius of the slider")
var radius = 2.0
@Piece
fun slide() : Shape3d {
val pegs : Shape3d = pegs()
val pegT = size.y / 7
val pegsP = pegsProfile(false)
val insideP = pegsP.offset(slack)
val outsideP = Square( pegsP.size.x - backT + pegT - slack, pegsP.size.y + pegT *2 )
.roundCorner(2,radius)
.roundCorner(1,radius)
.centerY().leftTo(backT+slack)
val end = outsideP.chamferedExtrude(pegT, radius/2, 0)
val mid = (outsideP-insideP).extrude(size.x).bottomTo(end.top)
val exit = Cube( pegs.size.x+slack, mid.size.y, pegs.size.z + slack * 2 )
.bottomTo( mid.bottom ).frontTo(gap/2)
return end + mid - exit + end.mirrorZ().bottomTo(mid.top)
}
fun pegsProfile( forPegs : bool ) : Shape2d {
val pegT = size.y / 7
val roundR = if (forPegs) pegT*0.7 else 0
return (
Square( backT, pegT*3 ) +
Square( backT +pegT, pegT).translateY(gap/2) +
Square( pegT, pegT*2 ).translateX( backT + pegT ).translateY(gap/2)
.roundCorner(2,roundR)
.roundCorner(1,roundR)
).mirrorY().also()
}
@Piece
fun pegs() : Shape3d {
val pegLength = size.x*0.4
val profile = pegsProfile(true)
return profile.extrude( pegLength ).color("Orange")
}
override fun build() : Shape3d {
val slide : Shape3d = slide()
val pegs : Shape3d = pegs().translateZ(1.7)
return slide + pegs
}
}

