From 671f66f4d4eb42d96bacce084fece1a5f27ef55f Mon Sep 17 00:00:00 2001 From: t123yh Date: Sat, 17 Feb 2024 20:04:06 +0800 Subject: [PATCH 1/3] Add step importer --- easyeda2kicad/__main__.py | 10 ++++++---- easyeda2kicad/easyeda/easyeda_api.py | 13 ++++++++++++- easyeda2kicad/easyeda/easyeda_importer.py | 1 + easyeda2kicad/easyeda/parameters_easyeda.py | 1 + easyeda2kicad/kicad/export_kicad_3d_model.py | 7 +++++++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/easyeda2kicad/__main__.py b/easyeda2kicad/__main__.py index a4bec62..8e595d8 100644 --- a/easyeda2kicad/__main__.py +++ b/easyeda2kicad/__main__.py @@ -342,14 +342,16 @@ def main(argv: List[str] = sys.argv[1:]) -> int: ).output ) exporter.export(lib_path=arguments["output"]) - if exporter.output: - filename = f"{exporter.output.name}.wrl" + if exporter.output or exporter.output_step: + filename_wrl = f"{exporter.output.name}.wrl" + filename_step = f"{exporter.output.name}.step" lib_path = f"{arguments['output']}.3dshapes" logging.info( f"Created 3D model for ID: {component_id}\n" - f" 3D model name: {exporter.output.name}\n" - f" 3D model path: {os.path.join(lib_path, filename)}" + f" 3D model name: {exporter.output.name}\n" + + (f" 3D model path (wrl): {os.path.join(lib_path, filename_wrl)}\n" if filename_wrl else "") + + (f" 3D model path (step): {os.path.join(lib_path, filename_step)}\n" if filename_step else "") ) # logging.info(f"3D model: {os.path.join(lib_path, filename)}") diff --git a/easyeda2kicad/easyeda/easyeda_api.py b/easyeda2kicad/easyeda/easyeda_api.py index 341ab45..da7aea6 100644 --- a/easyeda2kicad/easyeda/easyeda_api.py +++ b/easyeda2kicad/easyeda/easyeda_api.py @@ -7,6 +7,7 @@ API_ENDPOINT = "https://easyeda.com/api/products/{lcsc_id}/components?version=6.4.19.5" ENDPOINT_3D_MODEL = "https://easyeda.com/analyzer/api/3dmodel/{uuid}" +ENDPOINT_3D_MODEL_STEP = "https://modules.easyeda.com/qAxj6KHrDKw4blvCG8QJPs7Y/{uuid}" # ------------------------------------------------------------ @@ -43,6 +44,16 @@ def get_raw_3d_model_obj(self, uuid: str) -> str: headers={"User-Agent": self.headers["User-Agent"]}, ) if r.status_code != requests.codes.ok: - logging.error(f"No 3D model data found for uuid:{uuid} on easyeda") + logging.error(f"No raw 3D model data found for uuid:{uuid} on easyeda") return None return r.content.decode() + + def get_step_3d_model(self, uuid: str) -> bytes: + r = requests.get( + url=ENDPOINT_3D_MODEL_STEP.format(uuid=uuid), + headers={"User-Agent": self.headers["User-Agent"]}, + ) + if r.status_code != requests.codes.ok: + logging.error(f"No step 3D model data found for uuid:{uuid} on easyeda") + return None + return r.content diff --git a/easyeda2kicad/easyeda/easyeda_importer.py b/easyeda2kicad/easyeda/easyeda_importer.py index ee6744b..1ca58ed 100644 --- a/easyeda2kicad/easyeda/easyeda_importer.py +++ b/easyeda2kicad/easyeda/easyeda_importer.py @@ -249,6 +249,7 @@ def create_3d_model(self) -> Union[Ee3dModel, None]: model_3d: Ee3dModel = self.parse_3d_model_info(info=model_3d_info) if self.download_raw_3d_model: model_3d.raw_obj = EasyedaApi().get_raw_3d_model_obj(uuid=model_3d.uuid) + model_3d.step = EasyedaApi().get_step_3d_model(uuid=model_3d.uuid) return model_3d logging.warning("No 3D model available for this component") diff --git a/easyeda2kicad/easyeda/parameters_easyeda.py b/easyeda2kicad/easyeda/parameters_easyeda.py index a1bcae6..cfc5d20 100644 --- a/easyeda2kicad/easyeda/parameters_easyeda.py +++ b/easyeda2kicad/easyeda/parameters_easyeda.py @@ -543,6 +543,7 @@ class Ee3dModel: translation: Ee3dModelBase rotation: Ee3dModelBase raw_obj: str = None + step: bytes = None def convert_to_mm(self) -> None: self.translation.convert_to_mm() diff --git a/easyeda2kicad/kicad/export_kicad_3d_model.py b/easyeda2kicad/kicad/export_kicad_3d_model.py index 29d9241..36c5ffd 100644 --- a/easyeda2kicad/kicad/export_kicad_3d_model.py +++ b/easyeda2kicad/kicad/export_kicad_3d_model.py @@ -123,6 +123,7 @@ def __init__(self, model_3d: Ee3dModel): if model_3d and model_3d.raw_obj else None ) + self.output_step = model_3d.step def export(self, lib_path: str) -> None: if self.output: @@ -132,3 +133,9 @@ def export(self, lib_path: str) -> None: encoding="utf-8", ) as my_lib: my_lib.write(self.output.raw_wrl) + if self.output_step: + with open( + file=f"{lib_path}.3dshapes/{self.output.name}.step", + mode="wb", + ) as my_lib: + my_lib.write(self.output_step) From 77c82eb217b547d54f6f1a36beef9c47de9466a5 Mon Sep 17 00:00:00 2001 From: uPesy-computer Date: Mon, 19 Feb 2024 08:44:26 +0100 Subject: [PATCH 2/3] add comments + format code --- easyeda2kicad/__main__.py | 16 +++++++++++++--- easyeda2kicad/easyeda/easyeda_api.py | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/easyeda2kicad/__main__.py b/easyeda2kicad/__main__.py index 8e595d8..fc45aea 100644 --- a/easyeda2kicad/__main__.py +++ b/easyeda2kicad/__main__.py @@ -349,9 +349,19 @@ def main(argv: List[str] = sys.argv[1:]) -> int: logging.info( f"Created 3D model for ID: {component_id}\n" - f" 3D model name: {exporter.output.name}\n" + - (f" 3D model path (wrl): {os.path.join(lib_path, filename_wrl)}\n" if filename_wrl else "") + - (f" 3D model path (step): {os.path.join(lib_path, filename_step)}\n" if filename_step else "") + f" 3D model name: {exporter.output.name}\n" + + ( + " 3D model path (wrl):" + f" {os.path.join(lib_path, filename_wrl)}\n" + if filename_wrl + else "" + ) + + ( + " 3D model path (step):" + f" {os.path.join(lib_path, filename_step)}\n" + if filename_step + else "" + ) ) # logging.info(f"3D model: {os.path.join(lib_path, filename)}") diff --git a/easyeda2kicad/easyeda/easyeda_api.py b/easyeda2kicad/easyeda/easyeda_api.py index da7aea6..9c908a0 100644 --- a/easyeda2kicad/easyeda/easyeda_api.py +++ b/easyeda2kicad/easyeda/easyeda_api.py @@ -8,6 +8,8 @@ API_ENDPOINT = "https://easyeda.com/api/products/{lcsc_id}/components?version=6.4.19.5" ENDPOINT_3D_MODEL = "https://easyeda.com/analyzer/api/3dmodel/{uuid}" ENDPOINT_3D_MODEL_STEP = "https://modules.easyeda.com/qAxj6KHrDKw4blvCG8QJPs7Y/{uuid}" +# ENDPOINT_3D_MODEL_STEP found in https://modules.lceda.cn/smt-gl-engine/0.8.22.6032922c/smt-gl-engine.js : points to the bucket containing the step files. + # ------------------------------------------------------------ From d3520428dc728fc5e5c9acc977b34bf0a1cb3e00 Mon Sep 17 00:00:00 2001 From: uPesy-computer Date: Mon, 19 Feb 2024 09:05:37 +0100 Subject: [PATCH 3/3] [FEATURE] Add STEP export support --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 79efaad..90b2082 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ By default, all librairies are saved in `C:/Users/your_name/Documents/Kicad/easy - `easyeda2kicad.kicad_sym` file for Kicad v6.x symbol library - `easyeda2kicad.lib` file for Kicad v5.x legacy symbol library - `easyeda2kicad.pretty/` folder for footprint libraries -- `easyeda2kicad.3dshapes/` folder for 3d models +- `easyeda2kicad.3dshapes/` folder for 3d models (in .WRL and .STEP format ) If you want to save components symbol/footprint in your own libs, you can specify the output lib path by using `--output` option. @@ -72,7 +72,7 @@ easyeda2kicad --full --lcsc_id=C2040 --output ~/libs/my_lib This command will save: - the symbol in `~/libs/my_lib.kicad_sym` file for symbol library. The file will be created if it doesn't exist. - the footprint in `~/libs/my_lib.pretty/` folder for footprint libraries. The folder will be created if it doesn't exist. -- the 3d models in `~/libs/my_lib.3dshapes/` folder for 3d models. The folder will be created if it doesn't exist. +- the 3d models in `~/libs/my_lib.3dshapes/` folder for 3d models. The folder will be created if it doesn't exist. The 3D models will be saved both in .WRL and .STEP format. You can use the option `--overwrite` to update a component symbol/footprint that is already in a Kicad library (generated by easyeda2kicad)