Secondary development of Revit family

In Revit, the elements provided for a user-defined "family", all operations are carried out around the Revit family of this element.

  1. Category family

    The system is divided into Revit aromatic group, built family, family member standards.

    1. Group System: The system is aromatic in Autodesk Revit predefined group comprising a basic building elements, such as walls, windows and doors. For example: The basic wall system comprises a Group type definitions interior walls, exterior walls, foundation walls, walls and partition walls of conventional style; copy and modify existing system families, but not to create a new family system; can be defined by specifying new parameters new the family types.
    2. Standard Component Families: By default, the standard component families loaded in the project template, but more standard component library stored in the component families. Group members used to create and modify Editor. You can copy and modify existing family members, may also create a new group member in accordance with various aromatic templates. Family Templates can be based on the body of a model, it can also be a separate model. Group-based body comprises a body member needs. For example: in a wall as the main door family family, including independence group posts, trees and furniture; family templates help to create and manipulate a group member. Standard component families can be located outside the project environment, and with the extension .rfa, they can be loaded into the project passed from one project to another, but if required can also be saved from the project file to your library.
    3. Built Group: Built-family member may be a model of a particular project, it may be annotated member. It can only be created in the current project in place family, so they can only be used for the project-specific objects, such as: custom wall treatment. When you create a place family, select a category, and the category that you use will determine the appearance and display control means in the project.

    And we Revit secondary development, and Family is mainly related to building standards and in-place family, although the family system is also referred to as family, and no relevant attributes and characteristics of the Family. This chapter explains the correlation between the Family. Figure 1-1:

    A family (Famliy) in Revit system, is not allowed to exist independently, must be affiliated on a family category, race category more specific than family, family is like an abstract class, family type is a class, a family case examples of the object elements.

  2. Family visit

    Get the type of the group from the group FamilySymbol Example:

    1. FamilySymbol symbol = familylnstance. Symbol  
    2. FamilySymbol symbol = RevitDoc. GetElement(familyInstance.GetTypeId()) as FamilySymbol  

    Family get from family types:

    Family family = symbol. Family  

    Get family types from the family:

    FamilySymbolSet setOfSymbols = family. Symbols;

    Examples of the aromatic group Get Type

    FamilylnstanceFilter familylnstanceFilter = new FamilyInstanceFilter(RevitDoc,symbol, Id);

    FilteredElementCollector filteredElements = new FilteredElementCollector(RevitDoc);

    filteredElements = filteredElements. WherePasses(familylnstanceFilter);

    foreach (Familylnstance element in filteredElements)

    {

    // instance of ethnic groups

    }

  3. Examples of aromatic Construction

    Respectively doc.LoadFamily (file, out family); loading a group, create a family instance by doc.Create.NewFamilyInstance.

    /// <summary>

    /// create a door family's case

    /// </summary>

    /// <param name="RevitDoc"></param>

    /// <param name="doorTypeName"></param>

    public void CreatDoorInstance(Document doc, string doorTypeName = "0762 x 2032 mm")

    {

    FamilySymbol doorType = null;

     

    String File = @ "C: \ ProgramData \ Autodesk \ RVT 2017 \ the Libraries \ Chinese_INTL \ door \ M_ single - panel .rfa" ;

    // Get the family

    Family family = null;

    // Load the specified family

    bool loadSuccess = doc.LoadFamily(file, out family);

    if (loadSuccess)

    {

    // Get the current family for all types of verification

    foreach (ElementId doorTypeId in family.GetValidTypes())

    {

    // Get the current family types

    doorType = doc.GetElement(doorTypeId) as FamilySymbol;

    // Specify the current family types

    if (doorType != null)

    {

    if (doorType.Name == doorTypeName)

    {

    break;

    }

    }

    }

    }

    else

    {

    Autodesk.Revit.UI.TaskDialog.Show ( "failure" , "Load family failed" );

    }

    // Create a door using the Family Types

    if (doorType != null)

    {

    // First find the linear wall

    ElementFilter wallFilter = new ElementClassFilter(typeof(Wall));

    FilteredElementCollector filteredElements = new FilteredElementCollector(doc);

    filteredElements = filteredElements.WherePasses(wallFilter);

    Wall wall = null;

    Line line = null;

    foreach (Wall element in filteredElements)

    {

    LocationCurve locationCurve = element.Location as LocationCurve;

    if (locationCurve != null)

    {

    line = locationCurve.Curve as Line;

    if (line != null)

    {

    wall = element;

    break;

    }

    }

    }

    // 在墙的中心位置创建一个门

    if (wall != null)

    {

    XYZ midPoint = (line.GetEndPoint(0) + line.GetEndPoint(1)) / 2;

    Level wallLevel = doc.GetElement(wall.LevelId) as Level;

    //创建一个族实例

    FamilyInstance door = doc.Create.NewFamilyInstance(midPoint, doorType, wall, wallLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

    Autodesk.Revit.UI.TaskDialog.Show("成功", door.Id.ToString());

    System.Diagnostics.Trace.WriteLine("门创建完成: " + door.Id.ToString());

    }

    else

    {

    Autodesk.Revit.UI.TaskDialog.Show("元素不存在", "没有找到符合条件的墙");

    }

    }

    else

    {

    Autodesk.Revit.UI.TaskDialog.Show("族类型不存在", "没有找到族类型'" + doorTypeName + "'");

    }

    }

  4. 元素的编辑

    元素的移动、旋转和镜像,当前对对象进行操作时需要注意以下几点,不管是移动和旋转镜像,需要当前族具有此类特性,如一些族限制了标高,则Z方向不管赋值是否,都无法产生移动,其代码如下:

    public void ElementUtil(Document doc, FamilyInstance familyInstance) {

     

    //元素的移动

    ElementTransformUtils.MoveElement(doc, familyInstance.Id, new XYZ(0, 0, 0));

    ElementTransformUtils.RotateElement(doc, familyInstance.Id, Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 1, 1)), 30);

    Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisX, XYZ.Zero);

    ElementTransformUtils.MirrorElement(doc, familyInstance.Id, plane);

    }

Guess you like

Origin www.cnblogs.com/minhost/p/11586392.html