首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何通过revit api将图元放置在墙上

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

Stack Overflow用户
提问于 2019-08-16 19:46:09
回答 1查看 563关注 0票数 1

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

我在模型中的墙上放置了一些元素。我能够放置第一个元素,但不知道如何放置第二个和连续的元素。我已经上传了我所取得的成就和我想要做的下一步的源代码和图像。该族不是主体族。

代码语言:javascript
复制
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;
}

EN

Stack Overflow用户

回答已采纳

发布于 2019-08-20 13:10:08

我找到了我的解决方案。我只需要找到下一个定位点。这就是我是如何做到的。

代码语言:javascript
复制
 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();

请建议一个更好的方法。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57524082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档