Create.NewDimension – multiple reference errors (Invalid number of references, Line is not perpendicular, …) when pairing Grid curve ref with Column center ref
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I’m writing a Revit 2024 add-in that should auto-dimension every structural column to its nearest grid.
Full source (Visual Studio solution, command classes, collectors, etc.) is on GitHub:
https://github.com/vamsi736/FastTag
What I’m doing
Grid | grid.Curve.Reference (same one the UI uses when you click the grid line) |
Column | column.GetReferences( FamilyInstanceReferenceType.CenterLeftRight or CenterFrontBack ).FirstOrDefault() |
Then I place them in a ReferenceArray and call doc.Create.NewDimension.
Minimal code
using (Transaction tx = new Transaction(doc, "Test dim"))
{
tx.Start();
Grid g = verticalGrid; // any grid in view
FamilyInstance col = column; // HSS column
Reference gridRef = g.Curve.Reference; // ✔︎ not null
Reference colRef = col.GetReferences(
FamilyInstanceReferenceType.CenterLeftRight)
.FirstOrDefault(); // ✔︎ not null
ReferenceArray ra = new ReferenceArray();
ra.Append(gridRef);
ra.Append(colRef);
Line dimLine = BuildPerpLine(g, col); // confirmed perpendicular
Dimension dim = doc.Create.NewDimension(
activeView, dimLine, ra, dimType); // ⬅︎ FAILS
tx.Commit();
}
Exceptions I’ve hit
“Invalid number of references.” | most attempts with two refs above |
“The reference line is not perpendicular to the reference.” | if I swap LeftRight / FrontBack orientation |
“Input references are not valid for a dimension.” | sporadically when I tried Bottom or Origin refs |
“Cannot obtain geometry reference.” | when col.GetReferences(…) returns null |
If I replace gridRef with a face reference (Options { ComputeReferences=true } → first face), the dimension is created successfully – but it disappears when grids are hidden, so I’d much rather keep the curve reference.
Questions
Does NewDimension require the two refs to be of the same sub-type (edge-edge, plane-plane, etc.)?
Is there a column reference (axis, face, extrusion edge?) that is compatible with grid.Curve.Reference?
Is there a way to convert an edge/curve ref to a compatible “line” ref programmatically?
Any other work-around to get a stable column-to-grid dimension that survives VV/workset toggles?
Revit 2024.2 • C# • .NET 4.8
Thanks a lot for any insight!
Full source (Visual Studio solution, command classes, collectors, etc.) is on GitHub:
https://github.com/vamsi736/FastTag
Unibim Services pvt. ltd.