split molex and samtec footprint generators

This commit is contained in:
Brendan Haines 2022-09-23 01:24:47 -06:00
parent 59db22ac7c
commit 78e9b81850
3 changed files with 90 additions and 72 deletions

View File

@ -10,9 +10,13 @@ class Footprint:
# layer: (size_x, size_y, stroke) # layer: (size_x, size_y, stroke)
"F.SilkS": (0.030 * INCH, 0.030 * INCH, 0.007 * INCH), "F.SilkS": (0.030 * INCH, 0.030 * INCH, 0.007 * INCH),
"B.SilkS": (0.030 * INCH, 0.030 * INCH, 0.007 * INCH), "B.SilkS": (0.030 * INCH, 0.030 * INCH, 0.007 * INCH),
"F.Fab": (0.030 * INCH, 0.030 * INCH, 0.005 * INCH), None: (0.025 * INCH, 0.025 * INCH, 0.005 * INCH),
"B.Fab": (0.030 * INCH, 0.030 * INCH, 0.005 * INCH), }
None: (0.030 * INCH, 0.030 * INCH, 0.005 * INCH),
line_size = {
"F_SilkS": 0.007,
"B_SilkS": 0.007,
None: 0.005,
} }
def __init__( def __init__(

View File

@ -1,13 +1,11 @@
import time import time
import zipfile import zipfile
from datetime import datetime
from pathlib import Path from pathlib import Path
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from typing import Optional, Union from typing import Optional, Union
import numpy as np import numpy as np
import regex as re import regex as re
import requests
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import By from selenium.webdriver.support.select import By
@ -18,11 +16,10 @@ from fp_generator import INCH, Footprint
dir_ = Path(__file__).parent dir_ = Path(__file__).parent
rng = np.random.default_rng() rng = np.random.default_rng()
SILK_WIDTH = 0.007 * INCH
PARTS_SAMTEC = [ PARTS = [
# Pin Headers # Pin Headers
*[f"TSW-1{i:02d}-07-L-S" for i in range(1, 5)], *[f"TSW-1{i:02d}-07-L-S" for i in range(1, 5)], # quick for testing
# *[f"TSW-1{i:02d}-07-L-S" for i in range(1, 51)], # *[f"TSW-1{i:02d}-07-L-S" for i in range(1, 51)],
# *[f"TSW-1{i:02d}-07-L-D" for i in range(1, 51)], # *[f"TSW-1{i:02d}-07-L-D" for i in range(1, 51)],
# # *[f"TSW-1{i:02d}-07-L-T" for i in range(1, 51)], # # *[f"TSW-1{i:02d}-07-L-T" for i in range(1, 51)],
@ -43,25 +40,8 @@ PARTS_SAMTEC = [
# ), # ),
] ]
PARTS_MOLEX = [
# Micro-Fit 3.0 Single Row Headers
*[f"43650-{i:02d}10" for i in range(2, 13)], # 1 row, RA, press-fit retention clip
*[f"43650-{i:02d}13" for i in range(2, 13)], # 1 row, RA, solder tab
*[f"43650-{i:02d}22" for i in range(2, 13)], # 1 row, Vertical, press-fit retention clip
*[f"43650-{i:02d}25" for i in range(2, 13)], # 1 row, RA, solder tab
# Micro-Fit 3.0 Dual Row Headers
*[f"43045-{i:02d}07" for i in range(2, 25, 2)], # 2 row, RA, press-fit retention clip
*[f"43045-{i:02d}10" for i in range(2, 25, 2)], # 2 row, RA, solder tab
*[f"43045-{i:02d}16" for i in range(2, 25, 2)], # 2 row, Vertical, press-fit retention clip
*[f"43045-{i:02d}19" for i in range(2, 25, 2)], # 2 row, RA, solder tab
# Eurostyle 5.08mm Headers
# "39531-0002",
# Eurostyle 5.08mm Plugs
# "39530-0002",
]
def download_step(part: str, headless: bool = True) -> None:
def download_step_samtec(part: str) -> None:
print(part) print(part)
with TemporaryDirectory(prefix=str(dir_ / "tmp") + "/") as tmp: with TemporaryDirectory(prefix=str(dir_ / "tmp") + "/") as tmp:
tmp = Path(tmp) tmp = Path(tmp)
@ -71,7 +51,8 @@ def download_step_samtec(part: str) -> None:
"prefs", "prefs",
{"download.default_directory": str(tmp)}, {"download.default_directory": str(tmp)},
) )
# chrome_options.add_argument("--headless") if headless:
chrome_options.add_argument("--headless")
with webdriver.Chrome( with webdriver.Chrome(
options=chrome_options, options=chrome_options,
@ -108,39 +89,7 @@ def download_step_samtec(part: str) -> None:
(Path(tmp) / filename).rename(dir_ / "samtec.pretty" / "3dshapes" / filename) (Path(tmp) / filename).rename(dir_ / "samtec.pretty" / "3dshapes" / filename)
def download_step_molex(part: Union[str, int]) -> None: def footprint(part: str, lib: Optional[Union[Path, str]] = None) -> str:
# remove dash
part = f'{int(str(part).replace("-", "")):09d}'
print(part)
with TemporaryDirectory(prefix=str(dir_ / "tmp") + "/") as tmp:
tmp = Path(tmp)
for p in [part, part[:5] + "-" + part[5:]]:
try:
zipname = f"{part}_stp.zip"
# download
with open(tmp / zipname, "wb") as f:
f.write(requests.get(f"https://www.molex.com/pdm_docs/stp/{p}_stp.zip").content)
# unzip
with zipfile.ZipFile(tmp / zipname) as zip:
zip.extractall(path=str(tmp))
# move
filename = f"{part}.stp"
(Path(tmp) / filename).rename(dir_ / "molex.pretty" / "3dshapes" / filename)
return
except zipfile.BadZipFile:
print(f"zip does not exist for part {p}")
raise ValueError(f"Could not download .stp for part {part}")
def footprint_samtec(part: str, lib: Optional[Union[Path, str]] = None) -> str:
if any([part.startswith(s) for s in ["TSW-", "HTSW-"]]): if any([part.startswith(s) for s in ["TSW-", "HTSW-"]]):
# pinheader # pinheader
match = re.match( match = re.match(
@ -182,8 +131,8 @@ def footprint_samtec(part: str, lib: Optional[Union[Path, str]] = None) -> str:
fp = Footprint(fp_name, description=description, keywords=keywords) fp = Footprint(fp_name, description=description, keywords=keywords)
fp.add_text("reference", "REF**", center[0], -2.032, layer="F.SilkS") fp.add_text("reference", "REF**", center[0], -2.032, layer="F.SilkS")
fp.add_text("value", "VAL**", center[0], center[1], rotation=90, layer="F.Fab", hidden=True) 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], 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")
fp.add_rect( fp.add_rect(
[-0.05 * INCH] * 2, [-0.05 * INCH] * 2,
(0.05 * INCH + strobe[0] * (cols - 1), 0.05 * INCH + strobe[1] * (rows - 1)), (0.05 * INCH + strobe[0] * (cols - 1), 0.05 * INCH + strobe[1] * (rows - 1)),
@ -219,15 +168,11 @@ if __name__ == "__main__":
pool = Pool(10) pool = Pool(10)
for part in PARTS_SAMTEC: # for part in PARTS:
# time.sleep(rng.random() * 3) # # time.sleep(rng.random() * 3)
# download_step_samtec(part) # # download_step(part)
footprint_samtec(part) # footprint(part)
# pool.map(download_step_samtec, PARTS_SAMTEC) # pool.map(download_step, PARTS)
# pool.map(footprint_samtec, PARTS_SAMTEC) pool.map(footprint, PARTS)
# for part in PARTS_MOLEX:
# download_step_molex(part)
# pool.map(download_step_molex, PARTS_MOLEX)
pool.close() pool.close()

69
generate_molex.py Normal file
View File

@ -0,0 +1,69 @@
import zipfile
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Union
import requests
from fp_generator import INCH, Footprint
dir_ = Path(__file__).parent
PARTS = [
# # Micro-Fit 3.0 Single Row Headers
# *[f"43650-{i:02d}10" for i in range(2, 13)], # 1 row, RA, press-fit retention clip
# *[f"43650-{i:02d}13" for i in range(2, 13)], # 1 row, RA, solder tab
# *[f"43650-{i:02d}22" for i in range(2, 13)], # 1 row, Vertical, press-fit retention clip
# *[f"43650-{i:02d}25" for i in range(2, 13)], # 1 row, RA, solder tab
# # Micro-Fit 3.0 Dual Row Headers
# *[f"43045-{i:02d}07" for i in range(2, 25, 2)], # 2 row, RA, press-fit retention clip
# *[f"43045-{i:02d}10" for i in range(2, 25, 2)], # 2 row, RA, solder tab
# *[f"43045-{i:02d}16" for i in range(2, 25, 2)], # 2 row, Vertical, press-fit retention clip
# *[f"43045-{i:02d}19" for i in range(2, 25, 2)], # 2 row, RA, solder tab
# # Eurostyle 5.08mm Headers
"39531-0002",
# Eurostyle 5.08mm Plugs
# "39530-0002",
]
def download_step_molex(part: Union[str, int]) -> None:
# remove dash
part = f'{int(str(part).replace("-", "")):09d}'
print(part)
with TemporaryDirectory(prefix=str(dir_ / "tmp") + "/") as tmp:
tmp = Path(tmp)
for p in [part, part[:5] + "-" + part[5:]]:
try:
zipname = f"{part}_stp.zip"
# download
with open(tmp / zipname, "wb") as f:
f.write(requests.get(f"https://www.molex.com/pdm_docs/stp/{p}_stp.zip").content)
# unzip
with zipfile.ZipFile(tmp / zipname) as zip:
zip.extractall(path=str(tmp))
# move
filename = f"{part}.stp"
(Path(tmp) / filename).rename(dir_ / "molex.pretty" / "3dshapes" / filename)
return
except zipfile.BadZipFile:
print(f"zip does not exist for part {p}")
raise ValueError(f"Could not download .stp for part {part}")
if __name__ == "__main__":
from multiprocessing import Pool
pool = Pool(10)
pool.map(download_step_molex, PARTS)
# for part in PARTS:
# download_step_molex(part)
pool.close()