【问题标题】:How to place element on wall via revit api如何通过 revit api 将元素放置在墙上
【发布时间】:2019-08-20 13:10:08
【问题描述】:

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

我在模型的墙上放置了一些元素。我能够放置第一个元素,但不知道如何放置第二个和连续的元素。我已经上传了我所取得的成就以及我接下来要做什么的源代码和图像。家庭不是寄宿家庭。

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;
}

【问题讨论】:

  • 你试过JoinGeometryUtils.JoinGeometry()吗?
  • 我认为这在我的情况下不起作用,因为我的元素没有托管,我想要一种方法来找到如何将下一个元素放在前一个元素之后。

标签: c# revit-api revit


【解决方案1】:

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

 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();

请提出更好的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    相关资源
    最近更新 更多