Visibility of family elements

Visibility of family elements

The FamilyElementVisibility class can be used to control the visibility of family elements in the project document. For example, if you have a door family, you may only want the door swing to be visible in plan views in the project document in which doors are placed, not 3D views. By setting the visibility on the curves of the door swing, you can control their visibility. FamilyElementVisibility is applicable to the following family element classes which have the SetVisibility() function:

In the example below, the resulting family document will display the text "Hello World" with a line under it. When the family is loaded into a Revit project document and an instance is placed, in plan view, only the line will be visible. In 3D view, both the line and text will be displayed, unless the Detail Level is set to Course, in which case the line will disappear.

Code Region 13-10: Setting family element visibility

public void CreateAndSetVisibility(Autodesk.Revit.DB.Document familyDocument, SketchPlane sketchPlane)
{
    // create a new ModelCurve in the family document
    XYZ p0 = new XYZ(1, 1, 0);
    XYZ p1 = new XYZ(5, 1, 0);
    Line line1 = Line.CreateBound(p0, p1);
           
    ModelCurve modelCurve1 = familyDocument.FamilyCreate.NewModelCurve(line1, sketchPlane);
           
    // create a new ModelText along ModelCurve line
    ModelText text = familyDocument.FamilyCreate.NewModelText("Hello World", null, sketchPlane, p0, HorizontalAlign.Center, 0.1);

    // set visibility for text
    FamilyElementVisibility textVisibility = new FamilyElementVisibility(FamilyElementVisibilityType.Model);
    textVisibility.IsShownInTopBottom = false;
    text.SetVisibility(textVisibility);

    // set visibility for line
    FamilyElementVisibility curveVisibility = new FamilyElementVisibility(FamilyElementVisibilityType.Model);
    curveVisibility.IsShownInCoarse = false;
    modelCurve1.SetVisibility(curveVisibility);

}