Created
March 11, 2024 21:46
-
-
Save hughc/60bd251dc47857ff49163c6530db5506 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 { exec } = require("child_process"); | |
const scadSetting = {}; | |
//this should be the same as the spacing of LEDS on your strip | |
scadSetting.Width_and_depth_of_a_single_cell = 532 / 32; | |
// grid height | |
scadSetting.Height_of_grid = 10.2; | |
//best as an even multiple of your nozzle size | |
scadSetting.Cell_wall_thickness = 0.8; | |
scadSetting.Number_of_rows = 8; | |
scadSetting.Number_of_columns = 8; | |
/* [Strip Notches] */ | |
//notch to allow strip to sit under grid | |
scadSetting.Include_notch_for_strip = "yes"; // [no, yes] | |
//width of notch | |
scadSetting.LED_strip_width = 10; | |
//notch height to allow strip to sit under grid | |
scadSetting.Notch_height_regular = 2; | |
//notch height on edges - optional extra space for soldering | |
scadSetting.Notch_height_edge = 4; | |
/* [Multiple unit settings] */ | |
// removes clips from left edge | |
scadSetting.Is_first_column_unit = "no"; // [no, yes] | |
// removes clips from bottom edge | |
scadSetting.Is_first_row_unit = "no"; // [no, yes] | |
// hides or shows top edge | |
scadSetting.Is_last_row_unit = "no"; // [no, yes] | |
// hides or shows right edge | |
scadSetting.Is_last_column_unit = "no"; // [no, yes] | |
/* [Attachment points] */ | |
// an attachment point for a screw from behind the grid | |
scadSetting.Centre_screw_fitting = "no"; // [no, yes] | |
// only appear if 'is first' / 'is last' are selected | |
scadSetting.Edge_screw_fittings = "yes"; // [no, yes] | |
scadSetting.includeNotchForStrip = scadSetting.Include_notch_for_strip == "yes"; //comment | |
scadSetting.isFirstColumn = scadSetting.Is_first_column_unit == "yes"; //comment | |
scadSetting.isFirstRow = scadSetting.Is_first_row_unit == "yes"; | |
scadSetting.includeEdgeScrews = scadSetting.Edge_screw_fittings == "yes"; //comment | |
scadSetting.isLastRow = scadSetting.Is_last_row_unit == "yes"; //comment | |
scadSetting.isLastColumn = scadSetting.Is_last_column_unit == "yes"; | |
scadSetting.includeCentreScrew = scadSetting.Centre_screw_fitting == "yes"; //comment | |
// vary to suit your hardware | |
scadSetting.Screw_hole_sizes = 3.2; //[2:0.2:5] | |
scadSetting.Edge_attachment_hole_offset = 3.6; | |
const generateScadFile = (outputDir, column, row) => { | |
const modelParams = Object.keys(scadSetting).reduce(function (previous, key) { | |
const value = scadSetting[key]; | |
if (isNaN(value)) return previous + ` -D '${key}="${value}"'`; | |
return previous + ` -D '${key}=${value}'`; | |
}, ""); | |
const rowTitle = scadSetting.isFirstRow ? "bottom" : scadSetting.isLastRow ? "top" : "middle"; | |
const colTitle = scadSetting.isFirstColumn ? "left" : scadSetting.isLastColumn ? "right" : "middle"; | |
var yourscript = exec(`openscad customisable_grid.scad -o ${outputDir}/grid_${rowTitle}_${colTitle}.stl ${modelParams}`, (error, stdout, stderr) => { | |
console.log(stdout); | |
console.log(stderr); | |
if (error !== null) { | |
console.log(`exec error: ${error}`); | |
} | |
}); | |
}; | |
const totalWidth = 32; | |
const totalHeight = 32; | |
const maxCellCount = 8; | |
let numRows = Math.floor(totalWidth / maxCellCount); | |
let numColumns = Math.floor(totalHeight / maxCellCount); | |
const lastRowCellCount = totalWidth % maxCellCount || maxCellCount; | |
const lastColumnCellCount = totalHeight % maxCellCount || maxCellCount; | |
const extraRow = lastRowCellCount > 0 && lastRowCellCount != maxCellCount; | |
const extraCol = lastColumnCellCount > 0 && lastColumnCellCount != maxCellCount; | |
if (extraRow) numRows++; | |
if (extraCol) numColumns++; | |
const outputDir = 'batch_simple' | |
for (let column = 0; column < numColumns; column++) { | |
for (let row = 0; row < numRows; row++) { | |
scadSetting.Number_of_rows = column == numRows - 1 ? lastRowCellCount : maxCellCount; | |
scadSetting.Number_of_columns = row == numColumns - 1 ? lastColumnCellCount : maxCellCount; | |
scadSetting.isFirstColumn = column == 0; | |
scadSetting.isFirstRow = row == 0; | |
scadSetting.isLastColumn = column == numRows - 1; | |
scadSetting.isLastRow = row == numColumns - 1; | |
scadSetting.includeCentreScrew = row > 0 && row < numRows - 1 && column > 0 && column < numColumns - 1; | |
generateScadFile(outputDir, column, row); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allows you to crank out a full set of stl files based on the openscad model found here:
https://www.thingiverse.com/thing:4973163
Would be easy enough to turn into a cli app with commander.js to take input / output params, store configs in json etc.
Assumes you are on a linux-based system and that openscad is installed / on your path.