From 179b6df910c1c1a890b0090679cd11e9b3956b44 Mon Sep 17 00:00:00 2001 From: Brendan Haines Date: Sat, 29 Oct 2022 15:35:39 -0600 Subject: [PATCH] update fp generators to use relative 3d model paths --- fp_generator.py | 8 +++++--- generate_jst.py | 4 ++-- generate_molex.py | 6 ++++-- generate_samtec.py | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/fp_generator.py b/fp_generator.py index d6620a6..ee38b2a 100644 --- a/fp_generator.py +++ b/fp_generator.py @@ -22,10 +22,12 @@ class Footprint: def __init__( self, name: str, + lib: Union[Path, str], description: Optional[str] = None, keywords: Optional[List[str]] = None, ): self.name = name + self.lib = Path(lib) self.description = "" if description is None else description self._pads = [] self._models = [] @@ -80,7 +82,7 @@ class Footprint: scale: Tuple[float] = (1, 1, 1), ): self._contents += ( - f' (model "{str(Path(path).resolve())}" ' + f' (model "{str(Path(path).relative_to(self.lib))}" ' f"(offset (xyz {offset[0]} {offset[1]} {offset[2]})) " f"(scale (xyz {scale[0]} {scale[1]} {scale[2]})) " f"(rotate (xyz {rotate[0]} {rotate[1]} {rotate[2]})) " @@ -155,6 +157,6 @@ class Footprint: ")\n" ) - def write(self, lib: Union[Path, str]): - with open(Path(lib) / f"{self.name}.kicad_mod", "w") as f: + def write(self): + with open(self.lib / f"{self.name}.kicad_mod", "w") as f: f.write(self._contents + ")") diff --git a/generate_jst.py b/generate_jst.py index f10531e..178451a 100644 --- a/generate_jst.py +++ b/generate_jst.py @@ -83,7 +83,7 @@ def footprint(part: str, lib: Optional[Union[Path, str]] = None): match = re.match(r"SM(\d\d)B-SRSS-TB", part) pins = int(match[1]) - fp = Footprint(part, description=f"connector, JST-SH, 1x{pins:02f}, RA") + fp = Footprint(part, lib=lib, description=f"connector, JST-SH, 1x{pins:02f}, RA") fp.add_text("reference", "REF**", (5.55 + (0.025 + 0.005) * INCH), 0, rotation=90, layer="F.SilkS") fp.add_text("value", "VAL**", 4 * 0.025 * INCH, 0, rotation=90, layer="F.Fab") fp.add_text("user", r"${REFERENCE}**", 2 * 0.025 * INCH, 0, rotation=90, layer="F.Fab") @@ -133,7 +133,7 @@ def footprint(part: str, lib: Optional[Union[Path, str]] = None): (round2grid(1.8 + 0.010 * INCH), s * round2grid(b / 2 + 0.010 * INCH, "up")), layer="F.SilkS", ) - fp.write(lib) + fp.write() else: raise NotImplementedError diff --git a/generate_molex.py b/generate_molex.py index 1b5e22d..349b259 100644 --- a/generate_molex.py +++ b/generate_molex.py @@ -74,7 +74,9 @@ def footprint(part: str, lib: Optional[Union[Path, str]] = None): flavor = int(match[2]) if flavor == 10: - fp = Footprint(part, description=f"connector, Micro-Fit 3.0, 1x{pins:02f}, RA, press-fit retention clip") + fp = Footprint( + part, lib=lib, description=f"connector, Micro-Fit 3.0, 1x{pins:02f}, RA, press-fit retention clip" + ) fp.add_text("reference", "REF**", -(6.93 + (0.025 + 0.005) * INCH), 0, rotation=90, layer="F.SilkS") fp.add_text("value", "VAL**", -0.025 * INCH, 0, rotation=90, layer="F.Fab") fp.add_text("user", r"${REFERENCE}**", 0.025 * INCH, 0, rotation=90, layer="F.Fab") @@ -118,7 +120,7 @@ def footprint(part: str, lib: Optional[Union[Path, str]] = None): rotate=(0, 0, -90), ) fp.add_rect((4.6 - 9.9, -a / 2), (4.6, a / 2), layer="F.Fab") - fp.write(lib) + fp.write() else: raise NotImplementedError else: diff --git a/generate_samtec.py b/generate_samtec.py index 522c258..fe9e9b3 100644 --- a/generate_samtec.py +++ b/generate_samtec.py @@ -129,7 +129,7 @@ def footprint(part: str, lib: Optional[Union[Path, str]] = None) -> str: center = [strobe[0] * (cols - 1) / 2, strobe[1] * (rows - 1) / 2] - fp = Footprint(fp_name, description=description, keywords=keywords) + fp = Footprint(fp_name, lib=lib, description=description, keywords=keywords) fp.add_text("reference", "REF**", center[0], -2.032, layer="F.SilkS") fp.add_text("value", "VAL**", center[0] - 0.025 * INCH, center[1], rotation=90, layer="F.Fab") fp.add_text("user", r"${REFERENCE}**", center[0] + 0.025 * INCH, center[1], rotation=90, layer="F.Fab") @@ -154,7 +154,7 @@ def footprint(part: str, lib: Optional[Union[Path, str]] = None) -> str: (center[0], center[1], 0), rotate=(-90, 0, 90), ) - fp.write(lib) + fp.write() elif any([part.startswith(s) for s in ["SSW-"]]): # socket