Skip to content

Commit 30270c7

Browse files
authored
Merge pull request #11 from pks5/examples
Connectors, Examples
2 parents cfaaae1 + 514d0ac commit 30270c7

File tree

944 files changed

+41953
-2518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

944 files changed

+41953
-2518
lines changed

bin/create-examples.py

+31-12
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33
import re
44
import argparse
55

6+
67
parser = argparse.ArgumentParser("create-examples")
78
parser.add_argument("example_file", help="A JSON file with examples to create.", type=str)
89
args = parser.parse_args()
910

10-
dir_path = os.path.dirname(os.path.realpath(__file__))
11+
#dir_path = os.path.dirname(os.path.realpath(__file__))
12+
#example_file_path = os.path.abspath(os.path.join(dir_path, args.example_file))
13+
14+
example_file_path = os.path.abspath(os.path.relpath(args.example_file, start=os.curdir))
15+
16+
if(not os.path.exists(example_file_path)):
17+
print("Cannot open file: " + example_file_path)
18+
exit(0)
1119

12-
with open(dir_path + '/' + args.example_file) as f:
20+
with open(example_file_path, "r", encoding="utf-8") as f:
1321
d = json.load(f)
1422

1523
for example in d['examples']:
16-
target_dir = example['targetDirectory']
24+
target_dir = os.path.abspath(os.path.join(example_file_path, '..', example['targetDirectory']))
1725
url = example['url']
18-
file = open(dir_path + '/' + example['template'], "r")
26+
27+
template_file_path = os.path.abspath(os.path.join(example_file_path, '..', example['template']))
28+
29+
file = open(template_file_path, "r")
1930
brick_template = file.read()
2031
file.close()
2132

@@ -26,16 +37,24 @@
2637
for param in brick['parameters']:
2738
val = brick['parameters'][param]
2839
if(isinstance(val, str)):
29-
print('Replaced string param ' + param + ' with value ' + str(val).lower())
30-
scad = re.sub(param + r'\s*=\s*\"[a-zA-Z0-9\.\-_\s]+\"\s*;', param + ' = "' + str(val).lower() + '";', scad)
40+
try:
41+
print('Replaced string param ' + param + ' with value: ' + val)
42+
except(UnicodeEncodeError):
43+
print('Replaced string param ' + param + ' with unicode value')
44+
45+
scad = re.sub(param + r'\s*=\s*\"[a-zA-Z0-9\.\-_\s]+\"\s*;', param + ' = "' + val + '";', scad)
3146
elif(isinstance(val, bool)):
32-
print('Replaced bool param ' + param + ' with value ' + str(val).lower())
47+
print('Replaced bool param ' + param + ' with value: ' + str(val).lower())
3348
scad = re.sub(param + r'\s*=\s*((true)|(false))\s*;', param + ' = ' + str(val).lower() + ';', scad)
34-
elif(isinstance(val, int)):
35-
print('Replaced integer param ' + param + ' with value ' + str(val).lower())
36-
scad = re.sub(param + r'\s*=\s*[0-9\.]+\s*;', param + ' = ' + str(val) + ';', scad)
37-
38-
f = open(target_dir + "/" + file_name, "w")
49+
elif(isinstance(val, (int, float))):
50+
print('Replaced integer param ' + param + ' with value: ' + str(val))
51+
scad = re.sub(param + r'\s*=\s*[0-9\.\-]+\s*;', param + ' = ' + str(val) + ';', scad)
52+
elif(isinstance(val, list)):
53+
print('Replaced list param ' + param + ' with value: ' + json.dumps(val))
54+
scad = re.sub(param + r'\s*=\s*((\[[\[\]0-9\.\,]*\])|(\"[a-zA-Z0-9\.\-_\s]+\")|([0-9\.\-]+)|((true)|(false)))\s*;', param + ' = ' + json.dumps(val) + ';', scad)
55+
else:
56+
print('Did not replace param ' + param + ': unknown type!')
57+
f = open(target_dir + "/" + file_name, "w", encoding="utf-8")
3958
f.write(scad)
4059
f.close()
4160
print("Wrote " + file_name)

bin/create-previews.sh

+16-22
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,43 @@
11
#!/bin/bash
22

3-
PATH_TO_OPENSCAD="C:/Program Files/OpenSCAD/openscad.exe"
4-
#PATH_TO_OPENSCAD="/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD"
3+
# TODO Support Linux
4+
if [[ "$OSTYPE" == "darwin"* ]]; then
5+
PATH_TO_OPENSCAD="/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD"
6+
else
7+
PATH_TO_OPENSCAD="C:/Program Files/OpenSCAD/openscad.exe"
8+
fi
59

610
PATH_TO_MAGICK="magick"
711

8-
DIR_DOCS="../docs"
9-
DIR_SETS="../sets"
10-
DIR_EXAMPLES="../examples"
11-
DIR_CLASSIC="../examples/classic"
12-
DIR_TECHNIC="../examples/technic"
13-
DIR_BOXES="../examples/boxes"
14-
DIR_TEXT="../examples/text"
15-
DIR_CUSTOM="../examples/custom"
16-
DIR_CORNER="../examples/corner"
17-
DIR_SLANTED="../examples/slanted"
18-
1912
IMAGE_WIDTH=2400
2013
IMAGE_HEIGHT=1800
2114
IMAGE_BORDER=60
2215
IMAGE_WIDTH_FULL=$((IMAGE_WIDTH + 2 * IMAGE_BORDER))
2316
IMAGE_HEIGHT_FULL=$((IMAGE_HEIGHT + 2 * IMAGE_BORDER))
2417
IMAGE_WIDTH_HALF=$((IMAGE_WIDTH_FULL / 2))
2518

26-
#declare -a arr=("$DIR_SETS" "$DIR_EXAMPLES")
27-
declare -a arr=("$DIR_TECHNIC")
28-
#declare -a arr=("$DIR_CORNER")
29-
30-
echo
31-
echo Creating preview images ...
32-
echo
19+
if [ "$#" -lt 1 ]; then
20+
echo "Usage: bash create-previews.sh [diretory1] [directory2] ..."
21+
exit 1
22+
fi
3323

3424
curDir=$(pwd)
3525

3626
cd "$(dirname "$0")"
3727

38-
for i in "${arr[@]}"
28+
for i in "$@"
3929
do
30+
echo
31+
echo "Creating preview images for folder '$i' ..."
32+
echo
33+
4034
find "$i" -name "*.scad" -print0 | while read -d $'\0' file
4135
do
4236
echo "Creating preview for ${file} ..."
4337
label="$(basename ${file})"
4438
label=${label//-/ }
4539
label=${label/.scad/}
46-
label=`python -c "print('${label}'.title())"`
40+
label=`python -c "print('${label}'[:28].title())"`
4741
image_file="${file/scad/png}"
4842

4943
"$PATH_TO_OPENSCAD" --o "$image_file" --p "preview-parameters.json" --P BestQuality --csglimit 3000000 --imgsize ${IMAGE_WIDTH},${IMAGE_HEIGHT} --autocenter "$file"

bin/preview-parameters.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
{
44
"BestQuality": {
55
"previewQuality": "1",
6-
"roundingResolution": "128"
6+
"roundingResolution": "128",
7+
"viewMode": "cover"
78
}
89
},
910
"fileFormatVersion": "1"

dev/slanted-brick-s2-4x2.scad

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* MachineBlocks
3+
* https://machineblocks.com/examples/slanted
4+
*
5+
* Slanted Brick S2 4x2
6+
* Copyright (c) 2022 - 2025 Jan Philipp Knoeller <pk@pksoftware.de>
7+
*
8+
* Published under license:
9+
* Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
10+
* https://creativecommons.org/licenses/by-nc-sa/4.0/
11+
*
12+
*/
13+
14+
// Include the library
15+
use <../lib/block.scad>;
16+
17+
/* [Size] */
18+
19+
// Brick size in X-direction specified as multiple of an 1x1 brick.
20+
brickSizeX = 4; // [1:32]
21+
// Brick size in Y-direction specified as multiple of an 1x1 brick.
22+
brickSizeY = 2; // [1:32]
23+
// Height of brick specified as number of layers. Each layer has the height of one plate.
24+
baseLayers = 12; // [1:24]
25+
26+
/* [Appearance] */
27+
28+
// Type of cut-out on the underside.
29+
baseCutoutType = "classic"; // [none, classic]
30+
// Whether to draw knobs.
31+
knobs = true;
32+
// Whether knobs should be centered.
33+
knobCentered = false;
34+
// Type of the knobs
35+
knobType = "classic"; // [classic, technic]
36+
37+
// Whether to draw pillars.
38+
pillars = true;
39+
40+
// Whether brick should have Technic holes along X-axis.
41+
holesX = false;
42+
// Whether brick should have Technic holes along Y-axis.
43+
holesY = false;
44+
// Whether brick should have Technic holes along Z-axis.
45+
holesZ = false;
46+
47+
// Whether brick should have a pit
48+
pit = false;
49+
// Whether knobs should be drawn inside pit
50+
pitKnobs = false;
51+
// Pit wall thickness as multiple of one brick side length
52+
pitWallThickness = 0.333;
53+
54+
// Slanting size on X0 side specified as multiple of an 1x1 brick.
55+
slantingX0 = 2;
56+
// Slanting size on X1 side specified as multiple of an 1x1 brick.
57+
slantingX1 = -2;
58+
// Slanting size on Y0 side specified as multiple of an 1x1 brick.
59+
slantingY0 = 0;
60+
// Slanting size on Y1 side specified as multiple of an 1x1 brick.
61+
slantingY1 = 0;
62+
63+
/* [Quality] */
64+
65+
// Quality of the preview in relation to the final rendering.
66+
previewQuality = 0.5; // [0.1:0.1:1]
67+
// Number of drawn fragments for roundings in the final rendering.
68+
roundingResolution = 64; // [16:8:128]
69+
70+
/* [Calibration] */
71+
72+
// Adjustment of the height (mm)
73+
baseHeightAdjustment = 0.0;
74+
// Adjustment of each side (mm)
75+
baseSideAdjustment = -0.1;
76+
// Diameter of the knobs (mm)
77+
knobSize = 5.0;
78+
// Thickness of the walls (mm)
79+
wallThickness = 1.5;
80+
// Diameter of the Z-Tubes (mm)
81+
tubeZSize = 6.4;
82+
83+
// Generate the block
84+
block(
85+
grid = [brickSizeX, brickSizeY],
86+
baseLayers = baseLayers,
87+
baseCutoutType = baseCutoutType,
88+
89+
knobs = knobs,
90+
knobCentered = knobCentered,
91+
knobType = knobType,
92+
93+
pillars = pillars,
94+
95+
holesX = holesX,
96+
holesY = holesY,
97+
holesZ = holesZ,
98+
99+
pit = pit,
100+
pitKnobs = pitKnobs,
101+
pitWallThickness = pitWallThickness,
102+
103+
slanting = ((slantingX0 != 0) || (slantingX1 != 0) || (slantingY0 != 0) || (slantingY1 != 0)) ? [slantingX0, slantingX1, slantingY0, slantingY1] : false,
104+
105+
previewQuality = previewQuality,
106+
baseRoundingResolution = roundingResolution,
107+
holeRoundingResolution = roundingResolution,
108+
knobRoundingResolution = roundingResolution,
109+
pillarRoundingResolution = roundingResolution,
110+
111+
baseHeightAdjustment = baseHeightAdjustment,
112+
baseSideAdjustment = baseSideAdjustment,
113+
knobSize = knobSize,
114+
wallThickness = wallThickness,
115+
tubeZSize = tubeZSize
116+
);

examples/angle/angle-1x1x1.scad

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* MachineBlocks
3+
* https://machineblocks.com/examples/angle
4+
*
5+
* Angle 1x1x1
6+
* Copyright (c) 2022 - 2025 Jan Philipp Knoeller <pk@pksoftware.de>
7+
*
8+
* Published under license:
9+
* Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
10+
* https://creativecommons.org/licenses/by-nc-sa/4.0/
11+
*
12+
*/
13+
14+
// Include the library
15+
use <../../lib/block.scad>;
16+
use <../../lib/connectors.scad>;
17+
18+
/* [View] */
19+
// How to view the brick in the editor
20+
viewMode = "print"; // [print, assembled, cover]
21+
22+
/* [Size] */
23+
24+
// Both bricks' size in X-direction specified as multiple of an 1x1 brick.
25+
brickSizeX = 1; // [1:32]
26+
// First brick's size in Y-direction specified as multiple of an 1x1 brick.
27+
brick1SizeY = 1; // [1:32]
28+
// Second brick's size in Y-direction specified as multiple of an 1x1 brick.
29+
brick2SizeY = 1; // [1:32]
30+
// First brick's height specified as number of layers. Each layer has the height of one plate.
31+
brick1BaseLayers = 1; // [1:24]
32+
// Second brick's base height in mm
33+
brick2BaseHeight = 1.8;
34+
35+
/* [Appearance] */
36+
37+
// Type of cut-out on the underside.
38+
brick1BaseCutoutType = "classic"; // [none, classic]
39+
// Whether first brick should have knobs.
40+
brick1Knobs = true;
41+
// Type of first brick's knobs
42+
brick1KnobType = "classic"; // [classic, technic]
43+
// Whether second brick should have knobs.
44+
brick2Knobs = true;
45+
// Type of second brick's knobs
46+
brick2KnobType = "technic"; // [classic, technic]
47+
48+
/* [Quality] */
49+
50+
// Quality of the preview in relation to the final rendering.
51+
previewQuality = 0.5; // [0.1:0.1:1]
52+
// Number of drawn fragments for roundings in the final rendering.
53+
roundingResolution = 64; // [16:8:128]
54+
55+
/* [Calibration] */
56+
57+
// Adjustment of the height (mm)
58+
baseHeightAdjustment = 0.0;
59+
// Adjustment of each side (mm)
60+
baseSideAdjustment = -0.1;
61+
// Diameter of the knobs (mm)
62+
knobSize = 5.0;
63+
// Thickness of the walls (mm)
64+
wallThickness = 1.5;
65+
// Diameter of the Z-Tubes (mm)
66+
tubeZSize = 6.4;
67+
68+
/* [Hidden] */
69+
70+
// Grid Size XY
71+
gridSizeXY = 8.0;
72+
// Grid Size Z
73+
gridSizeZ = 3.2;
74+
75+
// Generate the block
76+
union()
77+
{
78+
block(grid = [ brickSizeX, brick1SizeY ],
79+
baseLayers = brick1BaseLayers,
80+
baseCutoutType = brick1BaseCutoutType,
81+
connectors = [[ 2, 0 ] ],
82+
knobs = brick1Knobs,
83+
knobType = brick1KnobType,
84+
85+
previewQuality = previewQuality,
86+
baseRoundingResolution = roundingResolution,
87+
holeRoundingResolution = roundingResolution,
88+
knobRoundingResolution = roundingResolution,
89+
pillarRoundingResolution = roundingResolution,
90+
91+
baseHeightAdjustment = baseHeightAdjustment,
92+
baseSideAdjustment = baseSideAdjustment,
93+
knobSize = knobSize,
94+
wallThickness = wallThickness,
95+
tubeZSize = tubeZSize);
96+
}
97+
98+
translate(viewMode != "print" ? [0, -0.5 * brick1SizeY * gridSizeXY, 0.5 * brick2SizeY * gridSizeXY + (viewMode == "cover" ? (brick1BaseLayers + 2) * gridSizeZ : 0)] : [(brickSizeX + 0.5) * gridSizeXY, 0, 0])
99+
rotate(viewMode != "print" ? [ 90, 0, 0 ] : [ 0, 0, 0 ])
100+
{
101+
102+
block(grid = [ brickSizeX, brick2SizeY ],
103+
baseHeight = brick2BaseHeight,
104+
baseCutoutType = "none",
105+
knobs = brick2Knobs,
106+
knobType = brick2KnobType,
107+
connectors = [ [ 2, 2 ] ],
108+
connectorHeight = brick1BaseLayers * gridSizeZ,
109+
110+
previewQuality = previewQuality,
111+
baseRoundingResolution = roundingResolution,
112+
holeRoundingResolution = roundingResolution,
113+
knobRoundingResolution = roundingResolution,
114+
pillarRoundingResolution = roundingResolution,
115+
116+
baseHeightAdjustment = baseHeightAdjustment,
117+
baseSideAdjustment =
118+
[ baseSideAdjustment, baseSideAdjustment, 0, baseSideAdjustment ],
119+
knobSize = knobSize,
120+
wallThickness = wallThickness,
121+
tubeZSize = tubeZSize);
122+
}

examples/angle/angle-1x1x1.webp

23.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)