Created
May 10, 2026 12:43
-
-
Save apla/cf4c8ab6c24d29da998aa32b9b3ae43c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { booleans, primitives, transforms } = require('@jscad/modeling'); | |
| const { subtract, union } = booleans; | |
| const { cuboid, cylinder } = primitives; | |
| const { translate, rotateX, rotateZ } = transforms; | |
| // Parameters | |
| function groundingBarShell ({innerWidth, innerDepth, wallThickness, holeDiameter, holeSpacing, holeCount, holeWallThickness, holeWallHeight, innerLength, mode}) { | |
| const outerW = innerWidth + wallThickness * 2; | |
| const outerD = innerDepth + wallThickness * 2; | |
| const outer = cuboid({ size: [innerLength + wallThickness * 2, outerW, outerD] }); | |
| const inner = cuboid({ size: [innerLength + wallThickness, innerWidth, innerDepth] }); | |
| let shell = subtract(outer, translate([wallThickness, 0, 0], inner)); | |
| const holeDepth = mode === "passThrough" ? outerD + 2 : wallThickness + 2; | |
| const holeHeight = wallThickness + holeWallHeight; | |
| const holeRadius = holeDiameter / 2; | |
| // const holeCount = Math.max(1, Math.floor((length - holeSpacing) / holeSpacing)); | |
| const totalSpan = (holeCount - 1) * holeSpacing; | |
| const startX = -totalSpan / 2; | |
| for (let i = 0; i < holeCount; i++) { | |
| const x = startX + i * holeSpacing; | |
| const zOffset = mode === "passThrough" ? 0 : (outerD / 2 - holeDepth / 2 + 1); | |
| const yOffset = mode === "passThrough" ? 0 : (outerW / 2 - holeDepth / 2 + 1); | |
| const offset = [x, 0, zOffset - mode === "passThrough" ? holeWallHeight * 2 : holeWallHeight]; | |
| const screwHole = translate( | |
| [x, 0, zOffset - mode === "passThrough" ? holeWallHeight * 2 : holeWallHeight], | |
| subtract( | |
| cylinder({ radius: holeRadius, height: holeDepth + 2 + holeWallHeight, segments: 32 }) | |
| ) | |
| ); | |
| const screwHoleWall = translate( | |
| [x, 0, innerDepth / 2 + holeWallHeight/2], | |
| subtract( | |
| cylinder({ radius: holeRadius + holeWallThickness * 2, height: holeHeight, segments: 32 }) | |
| ) | |
| ); | |
| const wireHole = translate( | |
| [x, yOffset, 0], | |
| rotateX( | |
| Math.PI/2, | |
| cylinder({ radius: holeRadius, height: holeDepth + 2 + holeHeight, segments: 32 }) | |
| ) | |
| ); | |
| shell = union(shell, screwHoleWall) | |
| shell = subtract(shell, screwHole); | |
| shell = subtract(shell, wireHole); | |
| } | |
| return shell; | |
| }; | |
| function getParameterDefinitions () { | |
| return [ | |
| {name: 'bar_brass_group', type: 'group', caption: 'Bar brass'}, | |
| {name: 'innerWidth', caption: 'Brass bar width:', type: 'float', step: 0.1, initial: 10}, | |
| {name: 'outerDepth', caption: 'Brass bar depth:', type: 'float', step: 0.1, initial: 10}, | |
| {name: 'wallThickness', caption: 'Wall Thickness:', type: 'float', step: 0.1, initial: 2}, | |
| {name: 'holes_group', type: 'group', caption: 'Holes'}, | |
| {name: 'holeDiameter', caption: 'Hole diameter:', type: 'float', step: 0.1, initial: 6}, | |
| {name: 'holeSpacing', caption: 'Hole spacing:', type: 'float', step: 0.1, initial: 9}, | |
| {name: 'holeCount', caption: 'Hole count:', type: 'float', step: 0.1, initial: 4}, | |
| {name: 'holeWallThickness', caption: 'Hole protection wall thickness:', type: 'float', step: 0.1, initial: 1}, | |
| {name: 'holeWallHeight', caption: 'Hole protection wall H:', type: 'float', step: 0.1, initial: 5}, | |
| ]; | |
| } | |
| function mainX (params) { | |
| const innerWidth = 10; // mm | |
| const innerDepth = 10; // mm | |
| const wallThickness = 2; // mm | |
| const holeDiameter = 6; // mm | |
| const holeSpacing = 9; // mm | |
| const holeCount = 5; | |
| const holeWallThickness = 1; // mm | |
| const holeWallHeight = 5; // mm | |
| const innerLength = holeSpacing * holeCount; | |
| const mode = "passThrough"; | |
| return groundingBarShell({ | |
| innerWidth, innerDepth, wallThickness, innerLength, | |
| holeDiameter, holeSpacing, holeCount, holeWallThickness, holeWallHeight, | |
| mode, | |
| ...params | |
| }); | |
| } | |
| function main (params) { | |
| const {holeCount, holeSpacing, holeDiameter} = params; | |
| const holderLength = holeCount * holeSpacing; | |
| const barWidth = holeDiameter; | |
| let shell = cuboid({ size: [holderLength, barWidth, barWidth * 1.25] }); | |
| const totalSpan = (holeCount - 1) * holeSpacing; | |
| const startX = -totalSpan / 2; | |
| for (let i = 0; i < holeCount; i++) { | |
| const x = startX + i * holeSpacing; | |
| const wireHole = translate( | |
| [x, 0, barWidth/4], | |
| rotateX( | |
| Math.PI/2, | |
| cylinder({ radius: holeDiameter/2, height: barWidth, segments: 32 }) | |
| ) | |
| ); | |
| const wireEnterReduce = 0.2; | |
| const wireEnter = translate( | |
| [x, 0, barWidth/6*5], | |
| cuboid({ size: [holeDiameter - wireEnterReduce, holeDiameter, holeDiameter] }) | |
| ); | |
| shell = subtract(shell, wireHole); | |
| shell = subtract(shell, wireEnter); | |
| } | |
| return shell; | |
| } | |
| module.exports = { main, getParameterDefinitions }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment