python glue + replay: follow the one-solid Part (pickle through Body, refuse a recorded multi-solid make_part_rpart)

DECISION: the Python value layer and the model-JSON replay follow the rule of 654a6d3e (a Part holds
exactly one solid). No behaviour is added; two places that knew about several bodies are narrowed.

WHY (the discussion in short; the full account is in 654a6d3e): the several-solids-in-one-Part design
existed so that the editor could hold a tool and its target side by side with no assembly constraint
(pattern a tool, then cut). The owner judged that a wrong design for an editor's convenience, because it
makes assembly hard; the conclusion reached with the assistant is that those solids are intermediate
values of a notebook, not product items, so a Part is one solid again. Everything below only removes what
assumed the opposite.

- _glue/values.py (pickle / deepcopy of a Part): a Part used to be rebuilt from either `body` or
  `bodies`. Now `body` is always the argument: the Solid when the body is plain, and the `Body` when it
  carries a name, colour or opacity, so an appearance still survives the notebook cell cache
  (Part(body=Body) is accepted by the binding for exactly this).
- _glue/session.py: a Part's children for lineage are its one body solid, its connectors and material.
- recording/serializer.py (replay of make_part_rpart): the multi-body branch is gone. A model JSON
  recorded by a development build that held several solids in one Part (params["bodies"] with more than
  one row; only SDK 2.2.8 development builds ever recorded it, 2.2.7 never did) now fails with a message
  that says what to do instead of being replayed into something the SDK no longer has. The unused Body
  import is removed.

Why refuse instead of converting such a model to one Part per solid: the part ids and the assembly that
would hold them are the author's decision, not something replay can invent.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Ni Jingzhe
2026-11-10 03:48:51 +08:00
parent 654a6d3e33
commit 2c998266b6
3 changed files with 12 additions and 27 deletions
+1 -2
View File
@@ -54,8 +54,7 @@ _PRODUCT_KINDS = frozenset({"Part", "Assembly", "Component", "Connector"})
def _children(item: Any) -> Iterable[Any]:
kind = type(item).__name__
if kind == "Part":
for body in item.bodies: # one Solid, or every body of a multi-body part
yield body.solid
yield item.body
yield from item.connectors
if item.material is not None:
yield item.material
+5 -8
View File
@@ -95,21 +95,18 @@ def _token_for(key: str, item: Any) -> str:
def _plain_body(part: Any) -> bool:
"""A one-body Part whose body is just its Solid: no name, colour or opacity, and the default id."""
"""A Part whose body is just its Solid: no name, colour or opacity, and the default id."""
if part.multi_body:
return False
body = part.bodies[0]
return body.body_id == "body" and body.name is None and body.color is None and body.opacity is None
# Constructor arguments that are not read back by the attribute of the same name. A Part holds one ``body`` or
# several ``bodies``, and is rebuilt from exactly one of them (``Part.body`` raises for a multi-body Part). A one-body
# Part whose body carries a name or an appearance is rebuilt from its ``Body`` so they survive.
# Constructor arguments that are not read back by the attribute of the same name. A Part holds exactly one ``body``
# (a Solid); a body that carries a name or an appearance is rebuilt from its ``Body`` (which ``Part(body=...)`` also
# takes) so they survive.
_ARGUMENTS: Dict[str, Dict[str, Any]] = {
"Part": {
"body": lambda value: value.body if _plain_body(value) else None,
"bodies": lambda value: None if _plain_body(value) else value.bodies,
"body": lambda value: value.body if _plain_body(value) else value.bodies[0],
},
}
+6 -17
View File
@@ -31,7 +31,6 @@ from ..errors import raise_harness_error
from simplecadapi._cpp import (
AnyShape,
Assembly,
Body,
Compound,
Connector,
ConnectorRef,
@@ -3449,23 +3448,13 @@ def _execute_graph(
ctx.require_params(node.node_id, op_name, params, ("part_id",))
body_outputs = _feature_input_shapes(ctx, graph, outputs, node, params)
rows = params.get("bodies")
if body_outputs and isinstance(rows, list) and len(rows) > 1:
# a multi-body part: one recorded input per body, in the order of the rows
if len(body_outputs) != len(rows):
raise ValueError(
f"make_part_rpart node {node.node_id}: {len(rows)} bodies recorded, "
f"{len(body_outputs)} inputs resolved"
)
result = ops.make_part_rpart(
str(params["part_id"]),
name=cast(Optional[str], params.get("name")),
bodies=[
Body(str(row["body_id"]), cast(Solid, shape), row.get("name"))
for row, shape in zip(rows, body_outputs)
],
if isinstance(rows, list) and len(rows) > 1:
# a model recorded while a Part could hold several solids (SDK 2.2.8 development builds)
raise ValueError(
f"make_part_rpart node {node.node_id}: it recorded {len(rows)} solids for one Part; "
"a Part holds exactly one solid. Make one Part per solid and put them in an Assembly"
)
_store_outputs(node, result)
elif body_outputs:
if body_outputs:
result = ops.make_part_rpart(
str(params["part_id"]),
cast(Solid, body_outputs[0]),