Last active
April 12, 2026 02:19
-
-
Save ali1234/5d8f3a9f1954c1dc37cc82bced0afdff to your computer and use it in GitHub Desktop.
OpenSCAD parts system...
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
| import subprocess | |
| import sys | |
| f = sys.argv[1] | |
| openscad = 'openscad-nightly' | |
| result = subprocess.check_output([openscad, '--export-format', 'echo', '-o', '-', f]) | |
| exported = set() | |
| for line in result.decode().split('\n'): | |
| if line.startswith("ECHO: ") and "PART:" in line: | |
| part = line[13:-1] | |
| if part not in exported: | |
| subprocess.check_call([openscad, '-D', f'$part="{part}"', '-o', f'{part}.stl', f]) | |
| exported.add(part) |
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
| use <part.scad> | |
| # Wrap each separate part in the "part" module like this: | |
| part("a") cube(10); | |
| part("b") sphere(5); | |
| # Running the export.py on this file will export a.stl and b.stl | |
| # If you define $part at the top of this file, only that part will be previewed. | |
| # If $part is undefined or doesn't match anything, everything will be previewed. |
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
| # The part module eachoes the name of the part so that the exporter | |
| # script can parse a list of all parts. Then it applies ! to children | |
| # iff $part = this part. | |
| module part(name) { | |
| echo(str("PART: ", name)); | |
| if($part == name) { | |
| !children(); | |
| } else { | |
| children(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment