Skip to main content

Module rename

Module rename 

Source
Expand description

Rename a feature everywhere it is named (owner 2026-11-27: a TRUE rename).

A feature’s id is also the name of the solid it makes and the head of every face, edge, frame and sketch child it publishes (E4:S3:PROFILE_START, CU1_PZ, D1:XY, S3:G20, E4:S3:PROFILE_START|E4:S3:L1_SW). Those names are what every other part of the document stores: feature params (reference fields, boolean targets), sketch external references, assembly constraints, PMI annotations, sheet views and dimension anchors, ports, wires, CAM, simulation and instruction blocks. rename_feature_in_document rewrites the id and every such name in one pass over the document, so the caller can adopt the result as ONE history edit (one undo step).

A name is rewritten per TOKEN, never as a substring:

  • a string is split into segments at | (an edge between two faces) and # (a sheet anchor’s edge), and each segment into tokens at :;
  • a token is the old id, or the old id followed by _, @, [, . or # (CU1_PZ, S1@0,0,0, Ext_top[0]), which keeps E40 and xE4 untouched;
  • after a component token (ACOMP2:), the rest of the segment names the component’s own part and is never touched.

Only the blocks that hold model entity names are walked (NAMED_BLOCKS; in ports, only the keys points are placed by). Free text (labels, notes, annotation text), the eCAD blocks (reference designators: D1 is a diode there), the expression and configurator blocks, the family table and the parts library are left alone. The metadata block is keyed by names; the engine keeps it apart from the history and renames its keys with rename_name.

A COMPONENT renames the same way: its id heads every name of its part (ACOMP2:Part_PZ becomes Motor:Part_PZ), a Pattern Component instance names it inside (APAT1.ACOMP2.i4 becomes APAT1.Motor.i4), and the eCAD blocks’ occurrence keys (instance, occurrence) follow it. Names are read against the document’s crate::ComponentNamespace, so what follows a component’s id is its part’s and is never rewritten.

Refused by name, so nothing is half renamed: an id that is not a feature, a pattern of components (APAT<n>: its instance ids are read by that shape), an illegal or reserved name, a name already used in the document, and an id another feature’s id extends (E4 when E4_B exists: its references could not be told apart).

Structs§

RenameOutcome
What a rename changed.

Constants§

MAX_NAME_LEN
The longest name accepted.

Functions§

name_uses
The places in document that name name (as an id or the head of a derived name): /-joined JSON paths. Empty when the name is free.
rename_feature_in_document
Rename feature old to new throughout document (a history document: features, assembly, pmi, sheets, …), in place. On a refusal the document is unchanged and the error says why.
rename_name
name with old renamed to new per the token rule, or None when it does not name old.
rename_name_in
rename_name read against a document’s components (namespace): a token that is a component there (registered, or of the ACOMP<n> shape) opens a part’s own names, which are never rewritten. For a component rename the namespace holds both the old and the new id.
validate_name
Whether name may be given to a feature: a letter, then letters, digits or -, at most MAX_NAME_LEN long, not reserved and not a component id. _, :, |, ., @, # and spaces are refused because they are the separators of the names built from an id.