Reference to Grid and Level from link

Reference to Grid and Level from link

ModPlus
Enthusiast Enthusiast
480 Views
4 Replies
Message 1 of 5

Reference to Grid and Level from link

ModPlus
Enthusiast
Enthusiast

To create a correct reference that will be used to create the dimension, for some elements (Grids, Levels) we need to create it this way:

var reference = new Reference(grid);

And how to create a reference for these elements if they are in a linked file?

0 Likes
Accepted solutions (1)
481 Views
4 Replies
Replies (4)
Message 2 of 5

scgq425
Advocate
Advocate

Hi ModPlus

in revit link reference , use revitlinkreference() function can get the target link element reference , but will post error when create dimension , u can see the picture that the same refernce convert to string will get two result . so u can use the code change refernce stable string   to create dimension .

scgq425_0-1711419433451.png

```

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.xxx-xxxxxxxx, 209.147513214079),
-XYZ.BasisZ);
var dim = RevitCommandData.Document.Create.NewDimension(RevitCommandData.ActiveView, fakeLine,
referenceArray);
}),"test");

```

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes
Message 3 of 5

ModPlus
Enthusiast
Enthusiast

@scgq425  you have shown an example with Floor and in fact, what you have shown is not necessary to do. You can take references to geometric objects from elements with geometry and create dimensions without any problems.

But my question is about the elements, for which references should be taken NOT from geometry - Grids, Levels

0 Likes
Message 4 of 5

scgq425
Advocate
Advocate
Accepted solution

@ModPlus

the level and grid u can use new refernce() to get reference , if the level or grid in linkinstance , u can covert them stable-string to get reference , in this code , show u how to get link-grid and link-level . when u create dimension , can lookup the target element stable-string and in code to convert them . 

```

//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");

```

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes
Message 5 of 5

ModPlus
Enthusiast
Enthusiast

@scgq425  thanks for the answers. I did it differently, but your tips helped me out

0 Likes