Loading step fails if there are duplicate names in step
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 541
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 5
Description
# Description
When a step file contains multiple sub-assemblies which are re-used e.g. multiple capacitors where the sub-assemblies are re-used, or a car with multiple wheels. Cadquery fails with a value error when loading up the step file. To be clear, I'm not entirely sure what the "correct" behaviour should be here. But either there is a bug in KiCAD or there is a bug in Cadquery. I did open this step file up in Freecad and it appears to handle the duplicated sub-assemblies gracefully, and looks like it appends a number to the end of the name e.g.
Perhaps that is the correct strategy here?
## To Reproduce
Load up a KiCAD generated step file. These contain many objects that are "Duplicated" e.g. many capacitors will all use the same model/sub-assembly. To reproduce this;
1. Download the mobo step file from the [opulo project outputs](https://github.com/opulo-inc/lumenpnp/releases/download/v4.0.1/LumenPnP-PCBs-v4.0.1.zip). The step file I'm using was in `LumenPnP-PCBs-v4.0.1/mobo/mobo-3D.step`.
2. Load up that step file using cadquery using the following code.
3. It raises an exception.
```python
import cadquery as cq
def main():
assy = cq.Assembly.load("mobo-3D.step")
if __name__ == "__main__":
main()
```
## Backtrace
```
$ uv run main.py
Traceback (most recent call last):
File "/home/nathaniel/projects/electric_gauntlet/mechanical/main.py", line 9, in
main()
File "/home/nathaniel/projects/electric_gauntlet/mechanical/main.py", line 5, in main
assy = cq.Assembly.load("mobo-3D.step")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nathaniel/projects/electric_gauntlet/mechanical/.venv/lib/python3.12/site-packages/cadquery/assembly.py", line 647, in load
_importStep(assy, path)
File "/home/nathaniel/projects/electric_gauntlet/mechanical/.venv/lib/python3.12/site-packages/cadquery/occ_impl/importers/assembly.py", line 129, in importStep
_importDoc(doc, assy)
File "/home/nathaniel/projects/electric_gauntlet/mechanical/.venv/lib/python3.12/site-packages/cadquery/occ_impl/importers/assembly.py", line 347, in _importDoc
_process_label(top_level_label, imported_assy)
File "/home/nathaniel/projects/electric_gauntlet/mechanical/.venv/lib/python3.12/site-packages/cadquery/occ_impl/importers/assembly.py", line 225, in _process_label
parent.add(sub_assy, name=ref_name, loc=cq_loc, color=color)
File "/home/nathaniel/projects/electric_gauntlet/mechanical/.venv/lib/python3.12/site-packages/cadquery/assembly.py", line 247, in add
raise ValueError(
ValueError: Unique name is required. C_0805_2012Metric1 is already in the assembly
```
## Environment
OS: Windows under Ubuntu WSL
I did not use conda and I am instead using astral/uv for the python environment.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.