Item |
public FamilyInstance NewFamilyInstance( Reference reference, Line position, FamilySymbol symbol )
Exception | Condition |
---|---|
ArgumentNullException | Thrown when a non-optional argument was null. |
ArgumentException | Thrown when the function cannot get a face from the reference, or, when the family cannot be placed as line-based on an input face reference, because its FamilyPlacementType is not WorkPlaneBased or CurveBased |
ArgumentsInconsistentException | Thrown when the family cannot be placed on this line as it does not coincide with the input face. |
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 instance fails to be created an exception may be thrown.
Note: if the created family instance includes nested instances, the API framework will automatically regenerate the document during this method call.
public void PlaceStiffenerOnWallFaceRef(Autodesk.Revit.DB.Document doc) { FilteredElementCollector wallCollector = new FilteredElementCollector(doc); wallCollector.OfClass(typeof(Wall)); Wall wall = wallCollector.FirstElement() as Wall; // The structural stiffeners family type is compatible with line-based face placement FilteredElementCollector fsCollector = new FilteredElementCollector(doc); fsCollector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_StructuralStiffener); FamilySymbol stiffenerSymbol = fsCollector.FirstElement() as FamilySymbol; // Get side face of wall IList<Reference> sideFaces = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior); Reference sideFaceRef = sideFaces[0]; // Generate line for path Face face = wall.GetGeometryObjectFromReference(sideFaceRef) as Face; BoundingBoxUV bbox = face.GetBoundingBox(); UV lowerLeft = bbox.Min; UV upperRight = bbox.Max; double deltaU = upperRight.U - lowerLeft.U; double deltaV = upperRight.V - lowerLeft.V; double vOffset = deltaV * 0.60; // 60% up the wall face UV firstPoint = lowerLeft + new UV(deltaU * 0.20, vOffset); UV lastPoint = lowerLeft + new UV(deltaU * 0.80, vOffset); Line line = Line.CreateBound(face.Evaluate(firstPoint), face.Evaluate(lastPoint)); doc.Create.NewFamilyInstance(sideFaceRef, line, stiffenerSymbol); }