How can we use the Flip Work Plane control as available in the Revit UI, using the Revit API?
The Flip Work Plane control shows up when a Work Plane-based family instance is selected and looks like this:
Clicking this control, flips the work plane for the selected family instance.
Using the Revit API, we can easily identify if an instance’s work plane has been flipped or not and also use the same property to flip it too (if there is a need, as was asked in the question above). The FamilyInstance.IsWorkPlaneFlipped property helps us achieve this. So with a simple case of two mass family instances in a Revit model (shows the work plane as well), with both above the work plane,:
executing the code included below shows how the work plane of the selected instance gets flipped:
The code (in which only a single line is really the crux of this post) is included below:
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
Document document = commandData.Application.ActiveUIDocument.Document;
using (Transaction trans = new Transaction(document, "WorkPlane"))
{
trans.Start();
foreach (FamilyInstance famInst in commandData.Application.ActiveUIDocument.Selection.Elements)
{
famInst.IsWorkPlaneFlipped = true;
}
trans.Commit();
}
return Result.Succeeded;
}
}
}