From 2e433fcd0d1afadd8ab786dd30d7d4546bdee43d Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 11 Nov 2026 10:08:41 +0100 Subject: hw-toolchain: placer, routers and KiCad helpers for agent-driven hardware work Rust placer (simulated annealing) and negotiated-congestion router for 2-layer KiCad boards, pnr.sh to place, route, DRC-check and install candidates, Python KiCad helpers, repo conventions (AGENTS.md) and the tool documentation under knowledge/. Konnect (KiCad MCP, AGPL) as a submodule. Co-Authored-By: Claude Opus 5.5 --- tools/threemf_group.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tools/threemf_group.py (limited to 'tools/threemf_group.py') diff --git a/tools/threemf_group.py b/tools/threemf_group.py new file mode 100644 index 0000000..1f92df3 --- /dev/null +++ b/tools/threemf_group.py @@ -0,0 +1,48 @@ +"""Group the objects of a 3MF into one object with parts, for multi-colour printing. + + python3 tools/threemf_group.py in.3mf out.3mf [name] + +SolidCraft exports one 3MF object per body (its `objects: component` mode only groups bodies of +placed sub-components). A slicer loads those as separate objects, so a shell and its label inlays +could not get one colour each on one object. This writes a parent object (default name: the +first object's) whose components are all build items, and builds only the parent; the slicer +then loads one object with each body as a part. Build-item transforms are moved onto the +components. +""" +import sys +import zipfile +import xml.etree.ElementTree as ET + +NS = "http://schemas.microsoft.com/3dmanufacturing/core/2015/02" +MODEL = "3D/3dmodel.model" + + +def main(): + src, dst = sys.argv[1], sys.argv[2] + ET.register_namespace("", NS) + with zipfile.ZipFile(src) as z: + files = {n: z.read(n) for n in z.namelist()} + root = ET.fromstring(files[MODEL]) + q = lambda tag: "{%s}%s" % (NS, tag) # noqa: E731 + resources, build = root.find(q("resources")), root.find(q("build")) + objects = resources.findall(q("object")) + name = sys.argv[3] if len(sys.argv) > 3 else objects[0].get("name") + parent = ET.SubElement(resources, q("object"), { + "id": str(max(int(o.get("id")) for o in objects) + 1), "type": "model", "name": name}) + comps = ET.SubElement(parent, q("components")) + for item in build.findall(q("item")): + attrs = {"objectid": item.get("objectid")} + if item.get("transform"): + attrs["transform"] = item.get("transform") + ET.SubElement(comps, q("component"), attrs) + build.remove(item) + ET.SubElement(build, q("item"), {"objectid": parent.get("id")}) + files[MODEL] = ET.tostring(root, encoding="UTF-8", xml_declaration=True) + with zipfile.ZipFile(dst, "w", zipfile.ZIP_DEFLATED) as z: + for n, data in files.items(): + z.writestr(n, data) + print("%s: %d parts in object '%s'" % (dst, len(comps), name)) + + +if __name__ == "__main__": + main() -- cgit v1.3