How to create a familyInstance on a face

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I need to create a hosted sensor family element (based on the Specialy Equipment Category) on a windows surface, and I used the following to create an instance.
1. Get the face of the window
private void getFaceReference(FamilyInstance familyObject, Autodesk.Revit.DB.Document doc, out Face outFace)
{
CurveArray curves = new CurveArray();
SolidArray solids = new SolidArray();
List<Face> faceList = new List<Face>();
Options geomOptions = new Options();
geomOptions.ComputeReferences = true;
geomOptions.DetailLevel = ViewDetailLevel.Fine;
GeometryElement geom = familyObject.get_Geometry(geomOptions);
AddCurvesAndSolids(geom, ref curves, ref solids);
foreach (Solid geomSolid in solids)
{
if (null != geomSolid)
{
foreach (Face geomFace in geomSolid.Faces)
{
faceList.Add(geomFace);
}
}
}
faceList.Sort(delegate(Face p1, Face p2) {
if (p1.Area > p2.Area) return -1;
if (p1.Area < p2.Area) return 1;
return 0;
});
outFace = faceList.First();
}
2. Based on the face, I get the location and then create the family Instance on top of the window family object
BoundingBoxUV bboxUV = face.GetBoundingBox();
UV center = (bboxUV.Max + bboxUV.Min) / 2.0;
XYZ location = face.Evaluate(center);
XYZ normal = face.ComputeNormal(center);
XYZ refDir = normal.CrossProduct(XYZ.BasisZ);
instance = doc.Create.NewFamilyInstance(location, familySymbol, objectInstance, level, StructuralType.NonStructural);
However the location of the new sensor element is way off the target window object. Could you please let me know if this is the right method for creating a special new family instance?
Thanks,