Skip to content

Commit cffb03f

Browse files
committed
made all legacy examples work again :D
1 parent 44f052d commit cffb03f

14 files changed

+137
-50
lines changed

solid/examples/legacy/animation_example.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#! /usr/bin/env python3
2+
#
3+
# THIS IS NOT WORKING because it's obsolete.
4+
# See examples/12-animation.py
5+
# See examples/13-animated-bouncing-ball.py
6+
#
7+
28
import sys
39
from math import cos, sin
410
from typing import Optional

solid/examples/legacy/append_solidpython_code.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
#! /usr/bin/env python3
2+
3+
# ======================================================
4+
# = add relative path to the solid package to sys.path =
5+
# ======================================================
6+
import sys
7+
from pathlib import Path
8+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
9+
sys.path.append(solidPath)
10+
#==================================================
11+
212
import sys
313

414
from solid import scad_render_to_file
5-
from solid.objects import cylinder
6-
from solid.utils import up
15+
from solid import cylinder
16+
from solid import up
717

818
SEGMENTS = 48
919

solid/examples/legacy/basic_builtins.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
# ======================================================
2+
# = add relative path to the solid package to sys.path =
3+
# ======================================================
14
import sys
25
from pathlib import Path
3-
4-
solidPath = Path(__file__).absolute().parent.parent.parent.as_posix()
6+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
57
sys.path.append(solidPath)
8+
#==================================================
69

7-
from solid.builtins import *
10+
from solid import *
811
from solid import scad_render_to_file
912

1013
def second_func():

solid/examples/legacy/basic_geometry.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
#! /usr/bin/env python3
2+
3+
# ======================================================
4+
# = add relative path to the solid package to sys.path =
5+
# ======================================================
6+
import sys
7+
from pathlib import Path
8+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
9+
sys.path.append(solidPath)
10+
#==================================================
11+
212
import sys
313

414
from solid import scad_render_to_file
5-
from solid.builtins import cube, cylinder, difference, translate, union
6-
from solid.utils import right
15+
from solid import cube, cylinder, difference, translate, union
16+
from solid import right
717

818
SEGMENTS = 48
919

solid/examples/legacy/basic_scad_include.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#! /usr/bin/env python3
2+
# ======================================================
3+
# = add relative path to the solid package to sys.path =
4+
# ======================================================
25
import sys
36
from pathlib import Path
7+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
8+
sys.path.append(solidPath)
9+
#==================================================
410

511
from solid import scad_render_to_file, import_scad, use
612

solid/examples/legacy/bom_scad.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
#
1818
# -ETJ 08 Mar 2011
1919

20+
# ======================================================
21+
# = add relative path to the solid package to sys.path =
22+
# ======================================================
2023
import sys
2124
from pathlib import Path
22-
23-
solidPath = Path(__file__).absolute().parent.parent.parent.as_posix()
25+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
2426
sys.path.append(solidPath)
27+
#==================================================
2528

2629
from solid import scad_render_to_file
27-
from solid.builtins import cube, color, cylinder, difference, translate, union
28-
from solid.utils import EPSILON
29-
from solid.utils import bill_of_materials, bom_part, set_bom_headers
30+
from solid import cube, color, cylinder, difference, translate, union
31+
from solid.extensions.legacy.utils import EPSILON
32+
from solid.extensions.legacy.bill_of_materials import bill_of_materials, bom_part, set_bom_headers
3033

3134
head_rad = 2.65
3235
head_height = 2.8

solid/examples/legacy/convenience_example.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# ======================================================
2+
# = add relative path to the solid package to sys.path =
3+
# ======================================================
14
import sys
25
from pathlib import Path
3-
4-
solidPath = Path(__file__).absolute().parent.parent.parent.as_posix()
6+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
57
sys.path.append(solidPath)
8+
#==================================================
69

710
from solid import *
811
from solid import scad_render_to_file

solid/examples/legacy/koch.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
#! /usr/bin/env python3
2+
3+
# ======================================================
4+
# = add relative path to the solid package to sys.path =
5+
# ======================================================
6+
import sys
7+
from pathlib import Path
8+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
9+
sys.path.append(solidPath)
10+
#==================================================
11+
212
import sys
313
from pathlib import Path
414

515
from euclid3 import LineSegment2, LineSegment3, Point2, Point3
616

7-
from solid import scad_render_to_file
8-
from solid.objects import polygon, polyhedron, union
9-
from solid.utils import forward, up
17+
from solid import scad_render_to_file, polygon, polyhedron, union
18+
from solid.extensions.legacy.utils import forward, up
1019

1120
ONE_THIRD = 1 / 3
1221

@@ -85,7 +94,7 @@ def kochify(seg, height_ratio=0.33, left_loc=0.33, midpoint_loc=0.5, right_loc=0
8594
LineSegment2(r, b)]
8695

8796

88-
def main_3d(out_dir):
97+
def main_3d():
8998
gens = 4
9099

91100
# Parameters
@@ -143,12 +152,11 @@ def main_3d(out_dir):
143152
)
144153
)
145154

146-
file_out = Path(out_dir) / 'koch_3d.scad'
147-
file_out = scad_render_to_file(all_polys, file_out, include_orig_code=True)
155+
file_out = scad_render_to_file(all_polys, include_orig_code=True)
148156
print(f"{__file__}: SCAD file written to: {file_out}")
149157

150158

151-
def main(out_dir):
159+
def main():
152160
# Parameters
153161
height_ratio = 0.25
154162
left_loc = ONE_THIRD
@@ -189,11 +197,11 @@ def main(out_dir):
189197
edges = [list(range(len(points)))]
190198
all_polys.add(forward(h)(polygon(points=points, paths=edges)))
191199

192-
file_out = scad_render_to_file(all_polys, out_dir=out_dir, include_orig_code=True)
200+
filename = Path(__file__).with_suffix(".2.scad")
201+
file_out = scad_render_to_file(all_polys, filename=filename, include_orig_code=True)
193202
print(f"{__file__}: SCAD file written to: {file_out}")
194203

195204

196205
if __name__ == '__main__':
197-
out_dir = sys.argv[1] if len(sys.argv) > 1 else None
198-
main_3d(out_dir)
199-
main(out_dir)
206+
main_3d()
207+
main()

solid/examples/legacy/libs_example.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
1+
# ======================================================
2+
# = add relative path to the solid package to sys.path =
3+
# ======================================================
24
import sys
35
from pathlib import Path
4-
5-
solidPath = Path(__file__).absolute().parent.parent.parent.as_posix()
6+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
67
sys.path.append(solidPath)
8+
#==================================================
79

810
from solid import import_scad, scad_render_to_file
911

solid/examples/legacy/path_extrude_example.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
#! /usr/bin/env python3
2-
from solid.objects import linear_extrude
3-
from solid.solidpython import OpenSCADObject
2+
3+
# ======================================================
4+
# = add relative path to the solid package to sys.path =
5+
# ======================================================
46
import sys
5-
from math import cos, radians, sin, pi, tau
67
from pathlib import Path
8+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
9+
sys.path.append(solidPath)
10+
#==================================================
711

12+
import sys
13+
from math import cos, radians, sin, pi, tau
14+
from pathlib import Path
815
from euclid3 import Point2, Point3, Vector3
16+
from typing import Set, Sequence, List, Callable, Optional, Union, Iterable, Tuple
917

18+
from solid import linear_extrude
19+
from solid.core.object_base import OpenSCADObject
1020
from solid import scad_render_to_file, text, translate, cube, color, rotate
11-
from solid.utils import UP_VEC, Vector23, distribute_in_grid, extrude_along_path
12-
from solid.utils import down, right, frange, lerp
13-
14-
15-
from typing import Set, Sequence, List, Callable, Optional, Union, Iterable, Tuple
21+
from solid.extensions.legacy.utils import UP_VEC, Vector23, distribute_in_grid, extrude_along_path
22+
from solid.extensions.legacy.utils import down, right, frange, lerp
1623

1724
SEGMENTS = 48
1825
PATH_RAD = 50

solid/examples/legacy/screw_thread_example.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
#! /usr/bin/env python3
2+
3+
# ======================================================
4+
# = add relative path to the solid package to sys.path =
5+
# ======================================================
6+
import sys
7+
from pathlib import Path
8+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
9+
sys.path.append(solidPath)
10+
#==================================================
11+
212
import sys
313

4-
from solid import scad_render_to_file
5-
from solid import screw_thread
6-
from solid.objects import cylinder
14+
from solid import scad_render_to_file, cylinder
15+
from solid.extensions.legacy import screw_thread
716

817
SEGMENTS = 48
918

solid/examples/legacy/sierpinski.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
#! /usr/bin/env python3
2+
3+
# ======================================================
4+
# = add relative path to the solid package to sys.path =
5+
# ======================================================
6+
import sys
7+
from pathlib import Path
8+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
9+
sys.path.append(solidPath)
10+
#==================================================
11+
212
import math
313
import random
414
import sys
515
from pathlib import Path
616

717
from solid import scad_render_to_file
8-
from solid.objects import cube, polyhedron, translate, union
18+
from solid import cube, polyhedron, translate, union
919

1020

1121
# =========================================================
@@ -100,6 +110,5 @@ def sierpinski_3d(generation, scale=1, midpoint_weight=0.5, jitter_range_vec=Non
100110
for p in tet.points:
101111
t.add(translate(p).add(cube(5, center=True)))
102112

103-
file_out = out_dir / f'gasket_{generations}_gen.scad'
104-
file_out = scad_render_to_file(t, file_out)
113+
file_out = scad_render_to_file(t)
105114
print(f"{__file__}: SCAD file written to: \n{file_out}")

solid/examples/legacy/solidpython_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /usr/bin/env python3
22
from solid import scad_render_to_file
3-
from solid.objects import union
3+
from solid import union
44

55
SEGMENTS = 48
66

solid/examples/legacy/splines_example.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
#! /usr/bin/env python
2-
import os
1+
#! /usr/bin/env python3
2+
3+
# ======================================================
4+
# = add relative path to the solid package to sys.path =
5+
# ======================================================
36
import sys
4-
from solid import *
5-
from solid.utils import Red, right, forward, back
7+
from pathlib import Path
8+
solidPath = Path(__file__).absolute().parent.parent.parent.parent.as_posix()
9+
sys.path.append(solidPath)
10+
#==================================================
611

7-
from solid.splines import catmull_rom_points, catmull_rom_polygon, control_points
8-
from solid.splines import bezier_polygon, bezier_points
12+
import os
13+
import sys
914
from euclid3 import Vector2, Vector3, Point2, Point3
1015

16+
from solid import *
17+
from solid.extensions.legacy.utils import Red, right, forward, back
18+
from solid.extensions.legacy.splines import catmull_rom_points, catmull_rom_polygon,\
19+
control_points, bezier_polygon,\
20+
bezier_points
21+
1122
def assembly():
1223
# Catmull-Rom Splines
1324
a = basic_catmull_rom() # Top row in OpenSCAD output
@@ -123,7 +134,7 @@ def bottle_shape(width: float, height: float, neck_width:float=None, neck_height
123134

124135
# Make OpenSCAD polygons out of the shapes once all points are calculated
125136
a = polygon(cr_points)
126-
a += mirror(v=(1,0))(a)
137+
a += mirror((1,0))(a)
127138

128139
# Show control points. These aren't required for anything, but seeing them
129140
# makes refining a curve much easier

0 commit comments

Comments
 (0)