如何通过 revit 在墙上放置图元 api

How to place element on wall via revit api

我想将一些元素一个接一个地放置在墙上。

我正在模型中的墙上放置一些元素。我能够放置第一个元素,但不知道如何放置第二个和连续的元素。我已经上传了源代码和我所取得的成就以及我下一步想做的事情的图像。该家庭不是被接待的家庭。

public static FamilyInstance PlaceFamily (Wall wall, Family family, Document document)
{

     FamilySymbol symbol = null ;

    foreach (ElementId s in family.GetFamilySymbolIds())
    {              
        symbol = document.GetElement(s) as FamilySymbol;                
        break;            
    }

    LocationCurve locationCurve= wall.Location as LocationCurve;

        XYZ point= locationCurve.Curve.GetEndPoint(0);
        Transaction transaction2 = new Transaction(document, "place Instance");
        transaction2.Start();
        if (!symbol.IsActive)
           symbol.Activate();
        FamilyInstance instance = document.Create.NewFamilyInstance(point, symbol, StructuralType.NonStructural);

        transaction2.Commit();
        return instance;
}

我找到了我的解决方案。我只需要找到下一个位置点。这是我的做法。

 XYZ p0 = locationCurveOfWall.Curve.GetEndPoint(0);
 XYZ p1 = locationCurveOfWall.Curve.GetEndPoint(1);

 XYZ vectorAlongTheWall = new XYZ(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
 XYZ normalizeVectorAlongTheWall = vectorAlongTheWall.Normalize();

 XYZ oldStartPoint = p0;

 int n2 = (int)Math.Round(wallLength / 4); // 4 is the width of the element

Transaction transaction2 = new Transaction(document, "place Instance");
transaction2.Start();

                FamilyInstance instance2 = document.Create.NewFamilyInstance(oldStartPoint, symbol, wall, StructuralType.NonStructural);
                for (int j = 1; j < n2 - 1; j++)
                {
                    XYZ newStartPoint = new XYZ(oldStartPoint.X + 4 * normalizeVectorAlongTheWall.X, oldStartPoint.Y + 4 * normalizeVectorAlongTheWall.Y, oldStartPoint.Z + 4 * normalizeVectorAlongTheWall.Z);
                    instance2 = document.Create.NewFamilyInstance(newStartPoint, symbol, wall, StructuralType.NonStructural);
                    oldStartPoint = newStartPoint;
                }

transaction2.Commit();

请提出更好的方法。