Item |
public FamilyInstance NewFamilyInstance( Face face, XYZ location, XYZ referenceDirection, FamilySymbol symbol )
Exception | Condition |
---|---|
ArgumentNullException | Thrown when a non-optional argument was null. |
ArgumentException | Thrown when the function cannot get the Reference from the face, or, when the Family cannot be placed as line-based on an input face reference, because its FamilyPlacementType is not WorkPlaneBased |
ArgumentsInconsistentException | Thrown when reference direction is parallel to face normal at insertion point. |
InvalidOperationException | Thrown when Revit is unable to place the family instance. |
ArgumentException | Thrown if The symbol is not active. |
The type/symbol that is used must be loaded into the document before this method is called. Families and their symbols can be loaded using the Document.LoadFamily or Document.LoadFamilySymbol methods.
The host object must support insertion of instances, otherwise this method will fail. If the instances fails to be created an exception may be thrown.
Some Families, such as Beams, have more than one endpoint and are inserted in the same manner as single point instances. Once inserted, these linear family instances can have their endpoints changed by using the instance's Element.Location property.
Note: if the created family instance includes nested instances, the API framework will automatically regenerate the document during this method call.
void CreateLightFixtureOnWall(Autodesk.Revit.DB.Document document, Wall wall) { FilteredElementCollector collector = new FilteredElementCollector(document); collector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_LightingFixtures); FamilySymbol symbol = collector.FirstElement() as FamilySymbol; // The only way to get a Face to use with this NewFamilyInstance overload // is from Element.Geometry with ComputeReferences turned on Face face = null; Options geomOptions = new Options(); geomOptions.ComputeReferences = true; GeometryElement wallGeom = wall.get_Geometry(geomOptions); foreach (GeometryObject geomObj in wallGeom) { Solid geomSolid = geomObj as Solid; if (null != geomSolid) { foreach (Face geomFace in geomSolid.Faces) { face = geomFace; break; } break; } } // Get the center of the wall 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); FamilyInstance instance = document.Create.NewFamilyInstance(face, location, refDir, symbol); }