Invalid Number of References

Invalid Number of References

Anonymous
Not applicable
1,630 Views
2 Replies
Message 1 of 3

Invalid Number of References

Anonymous
Not applicable

Hello Every One,

I am trying to set references between Column Face and Grid, Revit throws Invalid Number of References exception, by Debugging in can get Three references in reference array size.

Thanks in advance.

 

Here is My code  : 

 

const double _eps = 1.0e-9;

/// <summary>
/// Check whether two real numbers are equal
/// </summary>
static public bool IsEqual(double a, double b)
{
return Math.Abs(a - b) < _eps;
}

static public bool IsParallel(XYZ a, XYZ b)
{
double angle = a.AngleTo(b);
return _eps > angle || IsEqual(angle, Math.PI);
}

static XYZ Normal(Line line)
{
XYZ p = line.GetEndPoint(0);
XYZ q = line.GetEndPoint(1);
XYZ v = q - p;

return v.CrossProduct(XYZ.BasisZ).Normalize();
}


public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Application Context.
UIDocument uidoc = commandData.Application.ActiveUIDocument;
var doc = uidoc.Document;

 

//#region Creation Transaction Area

using (var t = new Transaction(doc))
{
#region Creat Walls
t.Start("Creat First Wall");


FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(Grid));
Grid grid = collector.ToElements().FirstOrDefault() as Grid;
XYZ grNormal = Normal(grid.Curve as Line);
LocationPoint pc = null;

ReferenceArray referenceArray = new ReferenceArray();
referenceArray.Clear();
referenceArray.Append(grid.Curve.Reference);


Options opt = new Options
{
ComputeReferences = true,
IncludeNonVisibleObjects = true,
View = doc.ActiveView

};

ObjectType objectType = ObjectType.Element;


Reference re = uidoc.Selection.PickObjects(objectType).FirstOrDefault();
Element e = doc.GetElement(re);
if (e.Location != null)
{
pc = e.Location as LocationPoint;
}
Face face = null;
GeometryElement geo = e.get_Geometry(opt);
foreach (GeometryObject obj in geo)
{
GeometryInstance instance = obj as GeometryInstance;
if (instance != null)
{
GeometryElement instanceObj = instance.GetInstanceGeometry();
foreach (GeometryObject geoObj in instanceObj)
{
Solid solid = geoObj as Solid;
if (solid != null)
{
FaceArray fa = solid.Faces;

foreach (Face f in fa)
{
PlanarFace pf = f as PlanarFace;
if (IsParallel(grNormal, pf.FaceNormal) )
{
//face = f;
referenceArray.Append(pf.Reference);
}
}

}

}

}

}


List<LocationPoint> points = new List<LocationPoint>();

XYZ pcxyz = pc.Point as XYZ;
Line line = Line.CreateBound(pcxyz, grid.Curve.GetEndPoint(0));

doc.Create.NewDimension(doc.ActiveView, line, referenceArray);

 

 

 

t.Commit();

}

 


return Result.Succeeded;

 

}

 

 

 

0 Likes
Accepted solutions (1)
1,631 Views
2 Replies
Replies (2)
Message 2 of 3

TripleM-Dev.net
Advisor
Advisor
Accepted solution

Hi,

 

I see you use referenceArray.Append(grid.Curve.Reference); in the code.

Retreiving the Grid.Curve and use the reference of the curve to dimension worked in Revit 2015 maybe 2016

 

But in R2018/2019 it doesn't result in a valid reference for dimension

Use the code below to create references from grids for dimensions.

 

Grid grid1 = (grid)doc.GetElement(GridElementid);
ReferenceArray DimRefs = new ReferenceArray;

DimRefs.Append(new Reference(grid1));

 

 

Als see this post: Grid Dimensioning 

Don't know if this solves the issue, also depending on Revit version.

 

- Michel

Message 3 of 3

Anonymous
Not applicable

Thanks, @TripleM-Dev.net  

 

0 Likes