How to create a familyInstance on a face

How to create a familyInstance on a face

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

How to create a familyInstance on a face

Anonymous
Not applicable

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,

 

0 Likes
1,131 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk

Dear Msoong,

 

Brett Burling sort of answered that question here:

 

http://forums.autodesk.com/t5/revit-api/newfamilyinstance-on-a-reference-plane/m-p/5445747

 

You could ask him for some more clarification.

 

I already have  🙂

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3

Anonymous
Not applicable

Dear Jeremy,

   Thanks for your reply. I will try out the recommand solution.

 

Regards,

Michael

0 Likes