Skip to content

Commit

Permalink
Merge pull request #118 from t123yh/master
Browse files Browse the repository at this point in the history
Add STEP 3D export support
  • Loading branch information
uPesy authored Feb 19, 2024
2 parents 5644beb + d352042 commit a9e3bd2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)

Expand Down
18 changes: 15 additions & 3 deletions easyeda2kicad/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,26 @@ 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)}"
+ (
" 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)}")
Expand Down
15 changes: 14 additions & 1 deletion easyeda2kicad/easyeda/easyeda_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

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.

# ------------------------------------------------------------


Expand Down Expand Up @@ -43,6 +46,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
1 change: 1 addition & 0 deletions easyeda2kicad/easyeda/easyeda_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions easyeda2kicad/easyeda/parameters_easyeda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions easyeda2kicad/kicad/export_kicad_3d_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

0 comments on commit a9e3bd2

Please sign in to comment.