BIM World
A Professional BIM Learning Platform


Revit API Tutorial: How to Split a Family in Secondary Development

In Revit, the concept of dividing families does not exist.

For families based on linear shapes, the cross-section remains consistent along the entire line. To segment such a family, you simply shorten the original line and then duplicate the family at the division points.

The general workflow involves first calculating evenly spaced points along the line, then shortening the family’s line accordingly, and finally copying the family instances to create evenly distributed segments. Below is a sample implementation in C#:

private void DevideFamilyInstance(FamilyInstance famIns, int n, Document revitDoc)
{
    LocationCurve locationCurve = famIns.Location as LocationCurve;
    XYZ startPoint = locationCurve.Curve.GetEndPoint(0);
    XYZ endPoint = locationCurve.Curve.GetEndPoint(1);

    IList<XYZ> dividePoints = InsertPoint(startPoint, endPoint, n);

    Transaction transaction = new Transaction(revitDoc);
    transaction.Start("Copy family instances to specified locations");

    locationCurve.Curve = Line.CreateBound(startPoint, dividePoints[0]);
    List<ElementId> elementIdsList = new List<ElementId> { famIns.Id };
    ICollection<ElementId> elementIds = elementIdsList;

    for (int j = 1; j < n; j++)
    {
        XYZ translation = new XYZ(
            dividePoints[j - 1].X - startPoint.X,
            dividePoints[j - 1].Y - startPoint.Y,
            dividePoints[j - 1].Z - startPoint.Z
        );
        ElementTransformUtils.CopyElements(revitDoc, elementIds, translation);
    }
    transaction.Commit();
}

private List<XYZ> InsertPoint(XYZ startPoint, XYZ endPoint, int n)
{
    List<XYZ> points = new List<XYZ>();
    for (int i = 1; i < n; i++)
    {
        double x = startPoint.X + (endPoint.X - startPoint.X) * i / n;
        double y = startPoint.Y + (endPoint.Y - startPoint.Y) * i / n;
        double z = startPoint.Z + (endPoint.Z - startPoint.Z) * i / n;
        XYZ point = new XYZ(x, y, z);
        points.Add(point);
    }
    return points;
}
xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat
Like(0) 打赏
BIM WORLD » Revit API Tutorial: How to Split a Family in Secondary Development

Comment Get first!

Must log in before commenting!

 

BIM World, A Professional BIM Learning Platform

Stay updated on the latest architecture trends and share new building technologies.

Contact UsAbout Us

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

Account Login

By signing in, you agree toUser Agreement

Sign Up