Issue In linked revit grid reference while creating dimensions using linked grid and host model element.

Issue In linked revit grid reference while creating dimensions using linked grid and host model element.

iaj172001
Observer Observer
601 Views
0 Replies
Message 1 of 1

Issue In linked revit grid reference while creating dimensions using linked grid and host model element.

iaj172001
Observer
Observer

Hello,

I'm trying to create dimensions using NewDimension method of revit api, but there are some issues with reference of the selected grids of the linked file and that's why it's not creating the dimension(e.g. one reference is linked model grids reference and another is from the host models duct edge reference(computed using element geometry)). I tried taking transform of the linked revit file and also created the reference from the linked instance to the host model but nothing worked for my case. It's now throwing the exception "Autodesk.Revit.Exceptions.ArgumentException: 'The references are not geometric references.
Parameter name: references'". 

For the better explanation and understating I'm attaching the a code example(sample method to create dimension using linked file grids and host file duct element) for what I am trying to achieve.   Also when I lookup the manually created dimension it's shows the whole linked Instance as one of the two references for the dimension between linked grid and host model element(see attached snippet usecase.png), so here's I end-up in doubt whether it's possible to create such dimensions using revit api which we can create manually without any issues or not because manually it's allowing to create a dimension between linked grid and host model duct element(see sample.png)? 
What did I missed ?. Any help is highly appreciated.

My code example case : 

 

 

private void CreateDimensionForLinkedModelGrids(Document doc, Document linkedDoc, Element element, ElementId viewId, Grid nearestGrid, GridRowModel rowData)
{
try
{
RevitLinkInstance linkInstance = CurrentSelectedLinkDocRvtLnkInstance;
var newPlane = Plane.CreateByNormalAndOrigin((doc.GetElement(viewId) as View).ViewDirection, (doc.GetElement(viewId) as View).Origin);
var startPt = GetAttachFromPoint(doc, element, nearestGrid, rowData.AttachFromSelected);
startPt = newPlane.ProjectOnto(startPt);

Transform linkTransform = linkInstance.GetTransform();
var nearestGridLine = nearestGrid.Curve.CreateTransformed(linkTransform) as Line;

//Autodesk.Revit.DB.Curve nearestGridLineCurve = nearestGrid.Curve as Autodesk.Revit.DB.Curve;
//var intersectionResultGridLine = nearestGridLineCurve.Project(new XYZ(startPt.X, startPt.Y, startPt.Z));
var intersectionResultGridLine = nearestGridLine.Project(new XYZ(startPt.X, startPt.Y, startPt.Z));
var endPtProjected = intersectionResultGridLine.XYZPoint;
var endPt = newPlane.ProjectOnto(endPtProjected);

var dimLine = Line.CreateBound(startPt, endPt);

var refArray = new ReferenceArray();
var firstRef = new Reference(nearestGrid);
//var firstRef = nearestGridLine.Reference; //it gives null ref
firstRef = firstRef.CreateLinkReference(linkInstance);
//var firstRef = new Reference(linkInstance);
//firstRef = firstRef.CreateLinkReference(linkInstance);


Reference secondRef = null;
XYZ centerLineOrigin = null;
if (element.Location is LocationCurve locCurve)
{

if (locCurve.Curve is Line line)
{
centerLineOrigin = line.Origin;
secondRef = line.Reference;
}
}
if(secondRef == null)
{
Options options = new Options()
{
ComputeReferences = true,
IncludeNonVisibleObjects = true,
//View = (doc.GetElement(viewId) as View),
DetailLevel = ViewDetailLevel.Fine
};

GeometryElement geometry = element.get_Geometry(options);
Reference ductCenterlineRef = null;


foreach (GeometryObject geometryObject in geometry)
{
if (geometryObject is GeometryInstance geometryInstance)
{
foreach (GeometryObject instanceGeometry in geometryInstance.GetInstanceGeometry())
{
if (instanceGeometry is Line line)
{

secondRef = line.Reference;
break;
}
}
}
else if (geometryObject is Line line)
{

secondRef = line.Reference;
break;
}
else if (geometryObject is Solid solid)
{
foreach (Edge edge in solid.Edges)
{

if (edge != null )
{
Curve lnc = edge.AsCurve();
if(lnc is Line )
{
var ln = lnc as Line;
centerLineOrigin = new XYZ(Math.Round(centerLineOrigin.X, 1), Math.Round(centerLineOrigin.Y, 1), 0);
var lineOrigin = ln.Origin;
lineOrigin = new XYZ(Math.Round(lineOrigin.X, 1), Math.Round(lineOrigin.Y, 1), 0);
// We found a line edge that might represent the centerline
if (lineOrigin.IsAlmostEqualTo(centerLineOrigin) || lineOrigin.Negate().IsAlmostEqualTo(centerLineOrigin))
{
secondRef = edge.Reference;
break;
}
}

}
}
}
}
}
refArray.Append(firstRef);
refArray.Append(secondRef);

using (Transaction tr = new Transaction(doc, "Create Dim"))
{
tr.Start();
doc.Create.NewDimension((doc.GetElement(viewId) as View), dimLine, refArray);
tr.Commit();
}

}
catch (Exception ex)
{
ex.ErrorLogEntry(MethodBase.GetCurrentMethod().Name);
//throw;
}
}

0 Likes
602 Views
0 Replies
Replies (0)