← AlvaroGil.com  ·  CAD/CAM

FreeCAD addon · how it works

Resolve_Mode internals

How a pure-Python addon finds PartDesign references that the topological naming algorithm could not keep, suggests replacements by geometric similarity, and relinks them, without storing any old shapes.

Targets FreeCAD 1.1+ (tested on 27.1 dev, 2026.11.04) Scope PartDesign Core changes none, Python only License LGPL-2.1-or-later
Demo (2 min, narrated, 1080p): breaking a fillet reference in a real model, then fixing it with the suggested match, Preview, Before, and Pick in 3D view, plus the preferences.

What it does

When a recompute leaves a feature pointing at an edge or face that no longer exists, Resolve_Mode opens a panel listing every broken reference. Each one gets one of three outcomes:

The panel opens automatically after a recompute that breaks something. You can switch that off in the panel or in the preferences, and open the panel from the PartDesign toolbar instead.

Resolve Mode panel listing three broken references. The first card shows Edge13 highlighted on Pad, with Preview, Before, Accept and Pick in 3D view buttons
Three broken references after the sketch profile was redrawn. Before is on for the first one.
The ambiguous card expanded, listing candidate edges with similarity bars from 78% down to 58%, each with preview and accept buttons
An ambiguous match: the original edge was split into two, so no single candidate wins.

Pipeline

A single document observer drives everything. Observer slots only record which document changed. The actual work runs on the Qt event loop after the recompute has finished, and is postponed while doc.Recomputing is true, because FreeCAD pumps events during a recompute.

Detecting broken references

The scan covers every PartDesign::* feature, every sketch, and anything else inside a PartDesign::Body. For each, it reads all properties whose type starts with App::PropertyLinkSub: fillet and chamfer Base, pocket and pad UpToFace, AttachmentSupport, pattern directions, mirror planes, sketch ExternalGeometry, and so on. It only looks at Edge, Face and Vertex entries.

An entry counts as broken when either of these is true:

  1. FreeCAD marked it missing. When the element map can't resolve the stored mapped name, the Python value carries a ? prefix:
    >>> App.ActiveDocument.Fillet.Base
    (<PartDesign::Pad>, ['Edge4', 'Edge7', '?Edge10', 'Edge15'])
  2. The index is out of range for the target shape, for example Face9 on a shape that now has 7 faces.

If the target itself failed to recompute, the reference is marked blocked and isn't matched. Its geometry isn't trustworthy until the upstream feature is fixed. Once that happens, the next scan picks it up with real candidates, so cascades resolve top-down.

Fingerprints instead of old shapes

Matching needs to know what the lost element looked like. Resolve_Mode doesn't keep the old shape. After every successful recompute, it stores a small fingerprint of each referenced element:

FieldEdgeFaceVertex
t typecurve class (Line, Circle, BSplineCurve…)surface class (Plane, Cylinder…)Point
s sizelengthareanone
c centrecentre of masspoint
d directionline direction or circle axis (unsigned)oriented plane normal, or cylinder/cone axisnone
r radiuscircle radiuscylinder or sphere radius, torus major radiusnone

They live in one hidden App::PropertyMap called ResolveModeSignatures on the referencing feature, keyed by property|target|element. Here are the actual entries from the test model:

Base|Pad|Edge13              {"c":[10.0,12.0,5.0],"d":[-1.0,0.0,0.0],"k":"Edge","r":null,"s":20.0,"t":"Line"}
AttachmentSupport|Pad|Face4  {"c":[10.0,12.0,2.5],"d":[-0.0,1.0,-0.0],"k":"Face","o":true,"r":null,"s":100.0,"t":"Plane"}

Details that matter:

Matching

For a broken reference, every element of the same kind on the same target is fingerprinted on the fly and scored against the stored fingerprint. Elements already used by other entries of the same property are skipped, so a fillet never suggests an edge it already has. The score is a weighted mean of the components both fingerprints have. Missing components are left out and the remaining weights renormalized.

ComponentWeightScore
position0.35exp(−distance / (0.25 × model diagonal)), so geometry that moved with a dimension change still scores well
size0.25min/max of length or area
type0.151 if the same class, otherwise 0.3
direction0.15|cos| for axes and lines. For oriented plane normals max(0, cos), so a flipped face scores 0
radius0.10min/max

The ranked list is then classified using three thresholds you can change in the preferences:

The runner-up rule is deliberate. When one edge splits into two, both halves score about the same. The panel shows that as "no confident match" instead of guessing.

Fallback for sketches with no stored fingerprint

For a sketch attached in FlatFace mode, the sketch's own placement still records where the face was: Placement × AttachmentOffset⁻¹. The addon builds a plane-only fingerprint from it and scores candidates by their distance to that plane and their normal. This works even on files that broke before Resolve_Mode was installed.

Repair

Preview without committing

references.preview_shape() regenerates one feature in a throwaway transaction:

doc.openTransaction("Resolve_Mode preview")
write_groups(obj, prop, groups_with_candidate)   # other broken entries of the property left out
obj.recompute()                                  # this feature only, not its dependents
shape = obj.Shape.copy()
doc.abortTransaction()                           # link, shape and placement come back
if it_was_failing and obj.isValid():
    obj.recompute()                              # abort doesn't restore the error flag; this does
The fillet regenerated with the suggested edge, drawn as a shaded blue solid with later features hidden
Preview: Fillet003 as it would regenerate with Edge13.
The Pad with Edge13 highlighted in blue along the back top edge and a small red ring where the old edge was
Before: Edge13 on the Pad, the geometry before the fillet. The red ring marks where Edge10 was.

Questions from the topological naming developers

These come from the forum thread [PROPOSAL] A "Broken References" resolver panel (August 2026).

Doesn't this need the old shape stored before every change? How do you avoid using too much RAM?

raised by hypocritical (drwho495)

if we need to store the old shape before any changes, how will we do that without using up too much RAM?

No shapes are stored, old or new. Only referenced elements get a fingerprint: a handful of numbers, measured at 92–119 bytes per entry as JSON in the test models. A model with 1,000 element references carries about 100 kB of strings, inside the compressed .FCStd. While the model is healthy, nothing is kept in memory beyond that property. Candidate fingerprints are computed only for the target of a broken reference, while the panel is building, and then discarded.

Is this UI-only work, or does it need an API addition first?

raised in the thread

It's UI-only. Everything uses Python APIs FreeCAD already has:

  • the ? marker on missing sub-element names
  • Shape.countElement / getElement
  • CenterOfMass, Curve, Surface
  • dynamic properties with status bits
  • document observers and transactions
  • Coin through pivy

No C++ changes are needed. If this moved into core, the matcher would be a natural fit for App::GeoFeature, next to findSimilarNames.

Shouldn't references that go missing be fixed in the topological naming algorithm instead?

raised by hypocritical (drwho495)

References going missing when they shouldn't is an issue that should be dealt with in the topological naming algorithm (and maybe in the name matcher).

Agreed, and Resolve_Mode doesn't compete with it. It only acts on references FreeCAD has already given up on. The common case is the one MisterMaker describes: the user removed or redrew the geometry, so the element legitimately no longer exists and no naming algorithm should invent a mapping. Every improvement to the naming algorithm shrinks the set of references Resolve_Mode ever sees, which is the goal.

How does it relate to doNamesMatch / findSimilarNames from the V2 PR?

raised by hypocritical (drwho495)

They run at different stages. The V2 name matcher decides whether two names mean the same element and returns a yes or no. Resolve_Mode starts only after that has failed, and compares geometry: it ranks elements and gives a confidence. As drwho495 notes, the name matcher has no useful information to return when names don't match. Resolve_Mode fills that gap with type, size, position, direction and radius.

These methods aren't exposed in the 27.1 dev build tested here (2026.11.04). If they land, Resolve_Mode needs no change: anything they resolve never shows up with a ?.

FreeCAD doesn't tell users that something broke.

MisterMaker, and issues #20686, #27546

the software pretty much need to take them by the hand sit them down and tell them to FIX IT before they make a mess of it.

That's the reason for auto mode, which is on by default. After any recompute that leaves a broken reference, the panel opens once with the list. It doesn't nag: if the user closes it, it stays closed until the set of broken references changes. A checkbox in the panel header turns auto mode off.

Would a unified selection system change this?

raised by hypocritical (drwho495)

It would make "Pick in 3D view" simpler. Today the addon briefly shows the target feature so the user's click resolves to the right object. With a selection system that can resolve a click on the tip into an element of an earlier feature, that step goes away. Detection and matching are independent of selection.

Can there be a simplified version without stored data?

MisterMaker

if this can cause issues I would say we make a simplified version without it.

Yes. Fingerprints are a preference (Remember the geometry of referenced elements). Without them you still get detection, the auto-opening panel, blocked and cascade handling, pick in 3D, Resolve manually, and the sketch-plane fallback. Only the suggestions for edges and faces depend on stored data.

What does it cost on large models?

anticipated

Capture is linear in the number of element references. For each one it reads the element and computes its centre of mass, length or area. It runs once per finished recompute, debounced, never during the recompute. Matching is linear in the number of elements of one kind on one target, and only runs for broken references when the panel is shown.

Limitations

Code map

FileResponsibility
core/signature.pyFingerprint format, score(), classify(). Pure Python with no FreeCAD dependency, unit-tested.
references.pyScope, reading and writing link properties, detection, capture, candidates, relink(), preview_shape(), transactions. Console-safe (no GUI imports).
gui/controller.pyDocument observer, debounce, auto-open, applying fixes, dismissed-state tracking.
gui/panel.pyThe dock widget and cards. Colors come from the Qt palette, so light and dark themes both work.
gui/highlight.pyCoin overlays for Before and Preview.
gui/isolate.pyTemporarily hides and shows Body features, and restores them. Shared by picking and both preview modes.
gui/picker.pySelection observer for Pick in 3D view.
init_gui.pyRegisters the command, the PartDesign toolbar (through a workbench manipulator), the Tools menu entry, the preference page and the observer.

Tests

python -m pytest -q tests
freecadcmd tests/fc_scenario.py