Esempio n. 1
0
    def test_import_scad(self):
        include_file = self.expand_scad_path("examples/scad_to_include.scad")
        mod = import_scad(include_file)
        a = mod.steps(3)
        actual = scad_render(a)

        abs_path = a._get_include_path(include_file)
        expected = f"use <{abs_path}>\n\n\nsteps(howmany = 3);"
        self.assertEqual(expected, actual)

        # Make sure this plays nicely with `scad_render()`'s `file_header` arg
        header = '$fn = 24;'
        actual = scad_render(a, file_header=header)
        expected = f"{header}\nuse <{abs_path}>\n\n\nsteps(howmany = 3);"
        self.assertEqual(expected, actual)

        # Confirm that we can leave out even non-default arguments in OpenSCAD
        a = mod.optional_nondefault_arg();
        actual = scad_render(a)
        expected = f'use <{abs_path}>\n\n\noptional_nondefault_arg();'
        self.assertEqual(expected, actual);

        # Make sure we throw ValueError on nonexistent imports
        self.assertRaises(ValueError, import_scad, 'path/doesnt/exist.scad')

        # Test that we recursively import directories correctly
        examples = import_scad(include_file.parent)
        self.assertTrue(hasattr(examples, 'scad_to_include'))
        self.assertTrue(hasattr(examples.scad_to_include, 'steps'))
Esempio n. 2
0
    def test_extra_args_to_included_scad(self):
        include_file = self.expand_scad_path("examples/scad_to_include.scad")
        mod = import_scad(include_file)
        a = mod.steps(3, external_var=True)
        actual = scad_render(a)

        abs_path = a._get_include_path(include_file)
        expected = f"use <{abs_path}>\n\n\nsteps(external_var = true, howmany = 3);"
        self.assertEqual(expected, actual)
Esempio n. 3
0
 def test_imported_scad_arguments(self):
     include_file = self.expand_scad_path("examples/scad_to_include.scad")
     mod = import_scad(include_file)
     points = mod.scad_points();
     poly = polygon(points);
     actual = scad_render(poly);
     abs_path = points._get_include_path(include_file)
     expected = f'use <{abs_path}>\n\n\npolygon(points = scad_points());'
     self.assertEqual(expected, actual)
Esempio n. 4
0
    def test_import_scad(self):
        include_file = self.expand_scad_path("examples/scad_to_include.scad")
        mod = import_scad(include_file)
        a = mod.steps(3)
        actual = scad_render(a)

        abs_path = a._get_include_path(include_file)
        expected = f"use <{abs_path}>\n\n\nsteps(howmany = 3);"
        self.assertEqual(expected, actual)

        # Make sure this plays nicely with `scad_render()`'s `file_header` arg
        header = '$fn = 24;'
        actual = scad_render(a, file_header=header)
        expected = f"{header}\nuse <{abs_path}>\n\n\nsteps(howmany = 3);"
        self.assertEqual(expected, actual)
Esempio n. 5
0
# echo tumbler.py |entr ./tumbler.py


import solid as s
import solid.objects as so
import os
import solid.utils as su
from math import pi, sqrt, atan2, asin, tan, cos, sin

depth = 200
thickness = 20
height = 75
width = 240
m3_support_depth = 6

gears = so.import_scad('gears.scad')

screw_clearance = {
        'm4': 4.5,
        'm3': 3.4,
}
screw_head_sink = {
        'm4': {'h': 4, 'diameter': 7.3},
        'm3': {'h': 2.5, 'diameter': 6.2}
}
screw_nut = {
        'm4': {'width': 7.0, 'depth': 3.6},
        'm3': {'width': 5.7, 'depth': 2.9}
}

def hex(width, h, fillet_radius = 0.1):
Esempio n. 6
0
def demo_import_scad():
    scad_path = Path(__file__).parent / 'scad_to_include.scad'
    scad_mod = import_scad(scad_path)
    return scad_mod.steps(5)