|
22 | 22 | ScadSize = Union[int, Sequence[float]] |
23 | 23 | OpenSCADObjectPlus = Union[OpenSCADObject, Sequence[OpenSCADObject]] |
24 | 24 |
|
| 25 | +IMPORTED_SCAD_MODULES: Dict[Path, SimpleNamespace] = {} |
| 26 | + |
25 | 27 | class polygon(OpenSCADObject): |
26 | 28 | """ |
27 | 29 | Create a polygon with the specified points and paths. |
@@ -761,15 +763,23 @@ def import_scad(scad_file_or_dir: PathStr) -> SimpleNamespace: |
761 | 763 | OpenSCAD files. Create Python mappings for all OpenSCAD modules & functions |
762 | 764 | Return a namespace or raise ValueError if no scad files found |
763 | 765 | ''' |
| 766 | + global IMPORTED_SCAD_MODULES |
| 767 | + |
764 | 768 | scad = Path(scad_file_or_dir) |
765 | 769 | candidates: List[Path] = [scad] |
766 | | - if not scad.is_absolute(): |
767 | | - candidates = [d/scad for d in _openscad_library_paths()] |
768 | 770 |
|
769 | | - for candidate_path in candidates: |
770 | | - namespace = _import_scad(candidate_path) |
771 | | - if namespace is not None: |
772 | | - return namespace |
| 771 | + ns = IMPORTED_SCAD_MODULES.get(scad) |
| 772 | + if ns: |
| 773 | + return ns |
| 774 | + else: |
| 775 | + if not scad.is_absolute(): |
| 776 | + candidates = [d/scad for d in _openscad_library_paths()] |
| 777 | + |
| 778 | + for candidate_path in candidates: |
| 779 | + namespace = _import_scad(candidate_path) |
| 780 | + if namespace is not None: |
| 781 | + IMPORTED_SCAD_MODULES[scad] = namespace |
| 782 | + return namespace |
773 | 783 | raise ValueError(f'Could not find .scad files at or under {scad}. \nLocations searched were: {candidates}') |
774 | 784 |
|
775 | 785 | def _import_scad(scad: Path) -> Optional[SimpleNamespace]: |
|
0 commit comments