Skip to content

Read the types of a family and compute the shape of each one from the file - #358

Merged
mahach666 merged 15 commits into
mainfrom
rfa-family-types
Dec 4, 2026
Merged

mahach666 merged 15 commits into
mainfrom
rfa-family-types

Conversation

@mahach666

@mahach666 mahach666 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

What changes and why

Exporting a family (.rfa) to HTML should let the viewer switch between the types of the family, with the geometry following the type. This is the RvtIO side; the viewer side is IOExtend/IOViewer#100 and needs a published RvtIO.Scene that contains this change. Everything is read from the family file by RvtIO. Nothing from Revit is used to read or compute.

  • RvtDocument.FamilyOwnerId names the owner family of a family document, and ProjectElementsOnly no longer drops the content of a family document (it was the whole model, so a family scene had no geometry).

  • The meshes and the scene of a family file show the family at its saved type: solid forms and loaded families, without the hosts, reference planes and voids of the template. MeshSet.FamilyGaps and the family-incomplete diagnostic say when the shape may be incomplete.

  • RvtDocument.FamilyTypes reads the types of a family file with their parameter values. RvtSceneResult.FamilyTypes lists them next to the scene (the scene still holds the saved type only; IOScene is unchanged). A table that cannot be read exactly gives the family-types-unreadable diagnostic and no list.

  • ElementMeshes.ComputeFamilyType computes the shape of another type by solving the relations of the family: sketches, dimensions, alignments, reference planes and lines, and formulas. It covers extrusions with straight, arc and circle profiles, revolutions, combinations of forms and loaded families. Imported drawings, and loaded instances that are not computed, are taken from the file in the types that give them what the saved type gives them.

    A type is computed only when every record that refers to the forms is recognized, something holds the family in place, the relations leave no part of the shape free and do not contradict each other, the profiles stay valid, and what is computed for the saved type is what the file stores. Otherwise the type has a Refusal with a stable code (unsupported-construct, unrecognized-reference, unverified-anchor, underdetermined, inconsistent, saved-state-mismatch, degenerate-geometry, not-computed) and no approximate shape is given.

  • RvtSceneOptions.FamilyTypeProgram gives, in place of the instances of the other types, a script and its data (Resources/family_types.js) with which a page computes the chosen type itself, refusing with the same codes; C# can still compute every type. Triangles taken from the file lie in the data compressed, so familyTypeProgram returns a promise.

  • Round surfaces of a family can be shown round (ElementMeshOptions.SmoothFamilySurfaces, set by RvtSceneOptions.FineCircularEdges for a family file). Projects keep their facets.

  • Fixes found on the way that also reach projects:

    • a face of a surface of revolution bounded only by its meridians that meets the axis at both ends (half a sphere) was drawn flat;
    • clipping a geometry to its bounding box no longer cuts what lies on the box within 1e-9 ft.

Limits to know about:

  • The rule that holds a family in place was derived from experiments in Revit and checked against Revit on two distinct families. For a family outside that set the checks reject contradictions and ambiguity, but they cannot prove that Revit keeps the same plane in place. Maintainers are asked to confirm the rule.
  • The calculation of a type exists in C# and in JavaScript; tests run the script under Node and hold the two to each other where they run the same family.
  • Families of Revit 2013 and 2014 are not read (as before).
  • Materials of computed faces are not compared with Revit; a type that sets the material parameter to By Category falls back to the style of the stored face.
  • The rules added by the last commit are not compared with Revit, and docs/scene.md#families does not describe them yet.

How it was checked

  • dotnet build RvtIO.slnx -c Release has no warnings
    • 0 errors. The test project has warnings, some of them in test files that this branch adds or changes (built locally with SDK 11).
  • dotnet test passes
    • dotnet test tests/RvtIO.Tests/RvtIO.Tests.csproj (Debug, with a folder of private fixtures): net10.0 13056 passed, 0 failed, 469 skipped; net8.0 13052 passed, 0 failed, 469 skipped. Run before two comment-only edits of the last commit; the library was built in Release after them.
    • With another set of private fixtures, StoredOutline_IsTheElementBoxOfEveryRelease (2021, 2022, 2024) and SaveAs_OnSupportedSampleFiles_PreservesStreamsIdentitiesRelationshipsGeometryAndExternalRefs failed earlier, as on main; not run again.
    • dotnet build src/RvtIO.Scene/RvtIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true (as in CI): 0 errors.
  • Exports of the same files before and after are identical, or the differences are listed and intended
    • Compared earlier in this branch, on the scenes of the sample projects read with datum geometry and model lines on: the only differences were the projects with faces closed through both poles (the fix above) and a few stub projects that hold only a family catalogue entry and now carry the family-incomplete: owner warning.
    • Not repeated for the later commits; the last one changes the clipping of a geometry to its box, which projects use. IFC and compact JSON were not compared.
  • Comparison with Revit 2022 (not part of the repository): every type Revit applied for the families used as the reference of the first rules is shown and equal to Revit's vertices within 0.01 mm; the types Revit rolled back are refused. Tests that read recorded Revit answers from a folder named by RVTIO_TEST_FILES are skipped without it.
  • No Revit models, customer data or vendor files are added
    • Fixtures are built synthetically in the tests. The added lines were searched for the names of the private samples.

The plan and the design documents of this work are not part of this PR.

… file

A family file now lists its types with their parameter values, and the
scene shows the family at its saved type. Any other type gets a shape
computed from the sketches, dimensions, alignments and reference planes
of the family itself, with nothing from Revit.

A type is computed only when the family is made of extrusions whose
profiles are straight sides along the axes of the family, every record
that refers to those forms is recognized, something holds the family in
place, the relations leave no part of the shape free and do not
contradict each other, the profiles stay valid in that type, and what is
computed for the saved type is what the file stores. Otherwise the type
has a refusal with a code and the record it names, and no approximate
shape is shown. The relations are solved in exact fractions.

RvtSceneResult.FamilyTypes carries the types, the instances of the
computed ones and the refusals of the others. IOScene is unchanged.

A face of a surface of revolution bounded only by its meridians that
meets the axis at both ends, such as half a sphere, was drawn flat; its
triangles now follow the angle between the meridians. This changes the
scene of 51 of the 627 sample projects and no other project.
A family whose extrusions have arcs and circles in their profiles, or
that holds a revolution, is now computed in every one of its types, with
nothing from Revit. An arc is computed when its ends lie on the axes of
the family through its centre, a whole number of quarter turns, and the
dimensions fix its centre and radius; a circle is two such arcs or one
closed arc, and the circle of a hole is read whichever way round the file
draws its halves. A circle takes the faces the file stores for it, and a
circle the file tessellates otherwise than evenly is refused as
saved-state-mismatch.

A revolution of a whole turn about a line of its sketch along an axis of
the sketch plane, whose profile is closed loops of straight lines, is cut
into 18 facets per turn. A loop inside an odd number of loops is a hole.
A profile that crosses the axis or itself, loops that meet or stand on
both sides of the axis, or a loop that changes direction or nesting from
the saved type, is refused as degenerate-geometry. The saved type is
matched analytically, because the file cuts round surfaces as it likes:
every corner of a stored face lies on one surface, every surface has
faces that reach both its circles, and the faces of a surface share one
material. The way a stored face faces is not compared, as the cone sample
stores half of its side facing into the solid.

The reader can read the records of the document of a family loaded into a
family file, which the file keeps in a block of the partitions other than
0, and gives only the elements of that document. A nest of combinations
of forms is followed to a depth of 64 and no further.

RvtReaderOptions.FineCircularEdges and RvtSceneOptions.FineCircularEdges
are new and off by default. A circle where a cylinder meets a plane is
sampled as Revit's low detail level samples it; with the option the faces
take the finer points the file stores. A cylinder or a surface of
revolution with no trim edge takes no more grid cells than a trimmed face
may, so that a damaged file cannot ask for tens of gigabytes.

A family with a combination of forms or with nested family instances is
still refused as unsupported-construct.
When an arc of a two-arc loop has an end the sketch holds at no angle,
the loop is looked at for the circle it may complete, and the other
curve of the loop was taken from the lines of the sketch before it was
checked to be one. A damaged file whose other curve names a line that
was not read threw a KeyNotFoundException out of the family model
builder and through the read of the scene.

Every curve of a loop is now checked to be a line of the sketch before
any is looked at with the others, so such a file is refused as
unrecognized-reference.
…nst Revit

A combination of forms (joined solid geometry) whose members are
extrusions and revolutions the family already computes is now computed
in every type. It is drawn as the faces of its members, whole: where the
members overlap, the faces inside the union stay, so the shell is a
drawing of the union and not a trimmed closed one. For the saved type
each member is checked on its own stored faces, since the file stores the
members uncut; the joined shape, which the file stores trimmed and
tessellated again, is checked only by its bounding box against that of
the stored faces of its members.

A combination without members, a form that two combinations hold, a
member that is no extrusion or revolution of the family or that a family
parameter shows or hides, and a parameter that drives the combination
itself are refused. Nested combinations and a member that cuts keep the
refusal unsupported-construct.

The caps of a circle that has circular holes (a ring) face inward, as the
file stores them, like those of a circle alone. A side alignment of two
joined lines of a sketch that run along one axis is read as the relation
the join already gives.

The volume of a revolution at the stored positions is pinned to what
Revit 2022 gives for the two cone families of the corpus. A valve whose
revolutions the file stores with corners inside their surfaces, and whose
flanges are nested family instances, is still refused.
The faces the file stores for a revolution are now accepted when a
corner lies on a side of the polygon the file cuts a circle into: a
chord between two neighbouring stored corners of the circle that go
round the axis or, where the file leaves a corner out (the rim of the
valve at 90 degrees), a chord between two corners of the regular
polygon that all the stored corners of the circle lie on the grid of.
A corner inside the circle that is on no such side stays a
saved-state-mismatch, to 1e-6 feet.

A parameter that drives a dimension or a form and is given by a formula
no longer makes a family refuse: each type stores the value the
parameter has, and it is used as stored. The check of the saved type
against the stored faces stays.

With both, the valve without its four nested flanges is computed in all
14 types, and the volumes of its body and ring agree with Revit 2022 to
7.8e-4. The valve itself is still refused as unsupported-construct for
the flanges: the file stores their shape for the saved type only, so
the other types are not shown.
…laced

An instance of a family loaded into a family file (the four flanges of the AquaFix valve) is
computed in every type from the document of the loaded family, which the file keeps in a block
of its own. The loaded family takes the values of the type of the host through the associations
of the instance, its extrusions are solved like those of the host, and its faces are placed by
the origin and basis of the instance. For the saved type the placed faces must be the faces the
file stores for the instance, one for one, and each face takes the style of the stored face it
is. A type that chooses another type of the loaded family is refused alone; a loaded family of
several types, hidden or void content, a revolution, a combination, an instance or a parameter
of visibility or material of its own, and a basis that is no rotation are refused with the reason.

A shared parameter that a loaded family uses is read from the first block of the file. A
dimension that holds an angle, reference lines that lie apart from the drawn lines of a sketch,
and an instance tied to a work plane are read as relations.

The 14 types of the valve are computed with their flanges; the ends of every flange, its sizes
across the pipe and its volume agree with the measure taken in Revit 2022 (see the flange tests
for the tolerances).
A family file could nest formulas deeper than the stack allows, or give a column or argument count that sizes an array before the
record is checked. Formulas nested deeper than 200 are refused with the reason, a size table whose count the record cannot hold is
not read, and a call with more than 1024 arguments is refused.
…hers

The file stores a circle of a family as a few flat faces (eight for the
flanges of the valve, 18 for a revolution), so what was drawn had a tenth
less volume than Revit gives. For showing, circles and revolutions are cut
into 720 facets (ElementMeshes.SmoothFacets, 1.3e-5 of the volume lost), and
the saved type is drawn so too, in place of the coarse meshes of its
elements, so the shape does not change when the type does. The faces that
are checked against the file keep the facets the file stores, and the members
of a combination keep their 18 facets, as Revit draws them.

FamilySmoothTests checks the volume of what is drawn in all 14 types of the
valve against Revit: body 1e-3, ring and flanges 1e-4.
…every type

The volumes of the body and the ring were held to Revit's in the 14 types, their
boxes were not. The viewer shows the circle cut into 720 facets, and its box has
the height of the body and the length of the ring as Revit's to 1e-3 mm, and on
each axis across it the larger of Revit's two half-widths: Revit's own cut of a
circle has no corner on one axis, so its smaller half-width is up to 2.5 % below.
The figures of Revit's volumes and boxes were copied into the InlineData of
three tests. One test now reads families/aquafix-valve.oracle.tsv of the
fixture folder and holds the body, the ring and the four flanges of all 14
types to it: the drawn volumes, the ends of the flanges to 1e-3 mm, the half
widths as in the tests of the boxes.
…ing a family

The combination of the valve (stem, collar and the bar of the handwheel) was drawn
with the 18 facets of the file, on the belief that Revit draws it faceted. Revit 2022
gives it as exact cylinders (6) and planes (10); the box 101 x 99.466 it reports is that
of its own coarse cut of a circle of 101. The members are now cut into SmoothFacets like
the body, so the collar and the cone of the stem meet without a saw-tooth. The match with
the saved state still compares the facets of the file.

TheCombinationOfTheValveIsShownAsRoundAsTheBodyInEveryType was red (half-width along y
99.466 against 101) and is green in all 14 types; the saved-type test now covers the
combination too.
The names of sample files are not to be published. The test classes of the
sample gate valve are named after what it is, and they read it and Revit's
answer for it as families/gate-valve.rfa and families/gate-valve.oracle.tsv of
the fixture folder. Nothing but names and comments is changed.
An HTML page of a family held the meshes of every type, so it grew with their
number, and a family can have thousands. With
RvtSceneOptions.FamilyTypeProgram a scene gives a script and its data instead
(FamilyTypeProgram, Resources/family_types.js): the page solves the relations of
the type chosen, checks its contours, builds and triangulates its faces, and
refuses with the codes of C#. Reading the file, preparing the model and the
formulas of loaded families stay in C#, which still computes every type itself;
tests run the script under Node and hold the two to each other.

The round surfaces of any family are shown round, not only those of computed
types. For a family file the parser keeps the exact surface of a curved face,
and with ElementMeshOptions.SmoothFamilySurfaces (set by FineCircularEdges of a
scene) the corners are put on it and the edges cut to 6 degrees. Projects keep
their facets.

More families are computed in every type:
- free ends and free angles of reference lines, angular dimensions of several
  segments or between things that only slide, arcs in the profile of a
  revolution and a radial dimension on a reference circle;
- a loaded instance that is not computed is taken from the file in the types
  that give it what the saved type gives it;
- imported drawings are part of a family and move with it. Their triangles lie
  in the program compressed, so familyTypeProgram returns a promise and the page
  unpacks them with DecompressionStream;
- instances that draw nothing, and dimensions that cannot change anything a type
  shows, no longer make a family refuse;
- a loaded family that has another family loaded into it is read.

Also fixed: comparisons, "and", "or" and "not" in family formulas always gave no;
a constraint of a sketch could name the wrong curve when curves of the sketch
were absorbed or deleted; and the clipping of a geometry to its bounding box,
which projects use too, no longer cuts what lies on the box within 1e-9 ft.

The new rules are not compared with Revit.
@mahach666
mahach666 merged commit 872807d into main Dec 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant