Creating Dimensions for Linked Models

Creating Dimensions for Elements with Solid Geometry like Floors

Today, while answering a question on the Revit API Forum about how to get the reference of a linked model to implement dimensioning Reference to Grid and Level from link, I used the CreateLinkReference(doc) method to get it directly, but the dimension creation failed.
The error reported an invalid reference. Later, I debugged and successfully dimensioned using a manually created link reference, so I suspected the issue specific to the acquired reference. Checking the reference string in the background revealed inconsistencies.

![Image Description](https://cdn.bimath.com/blog/pg/Snipaste_2026-01-04_16-02-02.png)

Later, I saw this article Revit Handling Linked File Dimension Reference. After modification, dimension creation was successful. It seems that the issue was with the reference-stable conversion, causing the direct acquisition to fail.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var floor = RevitCommandData.Document.GetElement(5676918) as Floor;
var reference = floor.GetTopFaceReferences().First();

var linkInstance = RevitCommandData.Document.GetElement(5678360) as RevitLinkInstance;
var linkDoc = linkInstance.GetLinkDocument();
var targetLinkEle = linkDoc.GetElement(5677607) as Floor;
var linkFace =
targetLinkEle.GetGeometryObjectFromReference(HostObjectUtils.GetTopFaces(targetLinkEle).First()) as
Face;
var linkRef = HostObjectUtils.GetTopFaces(targetLinkEle).First().CreateLinkReference(linkInstance);
var str = linkRef.ConvertToStableRepresentation(RevitCommandData.Document);
var str2 = referenceLink.ConvertToStableRepresentation(RevitCommandData.Document);
var strs = str.Split(':').ToList();
var newStr = $"{strs[0]}:0:RVTLINK:{strs[2]}:{strs[3]}:{strs[4]}";
var newReference = Reference.ParseFromStableRepresentation(RevitCommandData.Document, newStr);
var testRef = newReference.ConvertToStableRepresentation(RevitCommandData.Document);

TransactionUtils.Execute(RevitCommandData.Document,new Action<IDisposable>(x =>
{
var referenceArray = new ReferenceArray();
referenceArray.Append(reference);
referenceArray.Append(newReference);
var fakeLine = Line.CreateUnbound(new XYZ(-49.469472958128, 1769.33005941939, 209.147513214079),
-XYZ.BasisZ);
var dim = RevitCommandData.Document.Create.NewDimension(RevitCommandData.ActiveView, fakeLine,
referenceArray);
}),"test");

Creating Dimensions for Non-Solid Elements like Levels and Grids

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#region Create Link Level And Grid Dimension
//ModelLine
// var line = RevitCommandData.Document.GetElement(5679235) as ModelLine;
// var linkInstance = RevitCommandData.Document.GetElement(5678360) as RevitLinkInstance;
// var linkDoc = linkInstance.GetLinkDocument();
// var referenceLine = line.GeometryCurve.Reference;
// //Linked Grid
// var linkGrid = linkDoc.GetElement(5684684) as Autodesk.Revit.DB.Grid;
// var linkGridRefLine = (linkGrid.Curve.Reference).CreateLinkReference(linkInstance);
// var linkGridStr = linkGridRefLine.ConvertToStableRepresentation(RevitCommandData.Document);
// var strs = linkGridStr.Split(':').ToList();
// var completeGridRef = $"{strs[0]}:0:RVTLINK:{strs[2]}:{strs[3]}:{strs[4]}";
// var targetRef = Reference.ParseFromStableRepresentation(RevitCommandData.Document, completeGridRef);
// // Local Level
// var level = RevitCommandData.Document.GetElement(5672502) as Level;
// var levelRefPlane = new Reference(level);
// //Link Level
// var linkLevel = linkDoc.GetElement(5672528) as Level;
// var linkLevelRefLine = (new Reference(linkLevel)).CreateLinkReference(linkInstance);
// var linkLevelStr = linkLevelRefLine.ConvertToStableRepresentation(RevitCommandData.Document);
// var linkRefSplits = linkLevelStr.Split(':');
// var completeLevelRef = $"{linkRefSplits[0]}:0:RVTLINK:{linkRefSplits[2]}:0:SURFACE";
// var targetLevelRef = Reference.ParseFromStableRepresentation(RevitCommandData.Document, completeLevelRef);
//
//
// TransactionUtils.Execute(RevitCommandData.Document , new Action<IDisposable>(x =>
// {
// //Create Link-Level And Local-Level
// // var array = new ReferenceArray();
// // array.Append(levelRefPlane);
// // array.Append(targetLevelRef);
// // var l = Line.CreateUnbound(new XYZ(160.658709208543, -55.1818640250467, 39.7924116653103), -XYZ.BasisZ);
// // var dimLevel = RevitCommandData.Document.Create.NewDimension(RevitCommandData.ActiveView, l, array);
// //Create Link-Grid And ModelLine
// var array2 = new ReferenceArray();
// array2.Append(referenceLine);
// array2.Append(targetRef);
// var l2 = Line.CreateUnbound(new XYZ(34.4348591859389, 52.0854280621026, 0), XYZ.BasisY);
// var dimGrid = RevitCommandData.Document.Create.NewDimension(RevitCommandData.ActiveView, l2, array2);
// }),"test");

#endregion