
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I made a simple wall-mounted family using the "Generic Model wall based.rft" template. The family is just an extrusion attached to the top side of the wall as viewed in the Ref. Level
wall-mounted-box.rfa:
I want to import this wall-mounted-box.rfa into another Family (I will call this import.rfa) that also uses the "Generic Model wall based.rft" template. I want to place the box on the opposite side of the wall though, like the picture below. I can do this easily within the Revit UI. But I can't figure it out with the Revit API.
import.rfa:
Here is code showing the methods I've tested
string templateFileName = @"C:\ProgramData\Autodesk\RAC 2016\Family Templates\English_I\Generic Model wall based.rft"; Document document = uiApplication.Application.NewFamilyDocument(templateFileName); Family family; using (Transaction transaction = new Transaction(document)) { transaction.Start("Load Family"); document.LoadFamily(@"...\wall-mounted-box.rft", out family); transaction.Commit(); } FamilySymbol symbol = document.GetElement(family.GetFamilySymbolIds().First()) as FamilySymbol; FilteredElementCollector wallCollector = new FilteredElementCollector(document); Wall wall = wallCollector.OfClass(typeof(Wall)).FirstElement() as Wall; using (Transaction transaction = new Transaction(document)) { tx.Start("Instantiate Family"); symbol.Activate(); // METHOD 1: Default wall host FamilyInstance familyInstance = document.FamilyCreate.NewFamilyInstance(new XYZ(0,0,0), symbol, wall, StructuralType.NonStructural); // METHOD 2: try setting referenceDirection document.FamilyCreate.NewFamilyInstance(new XYZ(0,0,0), symbol, new XYZ(0,-1,0), wall, StructuralType.NonStructural);
// METHOD 3: Try flipping the FamilyInstance
familyInstance.flipFacing();
// setup for METHOD 4/5 Reference reference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior).First(); // METHOD 4: use reference to face with method from this site // http://adndevblog.typepad.com/aec/2015/06/revitapi-create-familyinstance-on-a-wall-face.html document.FamilyCreate.NewFamilyInstance(reference, new XYZ(0, 0, 0), new XYZ(0, -1, 0), symbol); // METHOD 5: Get the face to place on // I just grabbed the index-2 face arbitrarily since this method doesn't work anyways Options opt = new Options(); opt.ComputeReferences = true; Face face = (wall.get_Geometry(opt).First() as Solid).Faces.get_Item(2); document.FamilyCreate.NewFamilyInstance(face, new XYZ(0, 0, 0), new XYZ(0, -1, 0), symbol); tx.Commit(); } SaveAsOptions saveAsOptions = new SaveAsOptions(); saveAsOptions.OverwriteExistingFile = true; document.SaveAs(@"...\import.rft", saveAsOptions);
METHOD 1 and METHOD 2 just places the box on the default side of the wall which is the top. Looks exactly like the wall-mounted-box.rfa picture.
METHOD 3 doesn't work because familyInstance.CanFlipFacing is false.
Here are the properties I grabbed from FamilyInstances I creating using the Revit UI.
default orientation on top of wall:
opposite orientation on bottom of wall:
METHOD 5 says "Family cannot be placed as hosted on an input face reference, because its FamilyPlacementType is not WorkPlaneBased"
METHOD 4 also says that FamilyPlacementType is not WorkPlaneBase.
How do I do this?
Solved! Go to Solution.