
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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;
}
Solved! Go to Solution.