【问题标题】:How can I display the created cube in Revit API?如何在 Revit API 中显示创建的立方体?
【发布时间】:2021-03-03 09:14:56
【问题描述】:

这听起来像是一个非常基本的问题,对此我深表歉意 - 但是,我在任何地方都找不到任何关于此的信息。

我正在尝试创建一个由模型线组成的立方体并将其放入绘图中的命令。对于多维数据集的创建,我在 Jeremy Tammik 的博客上找到了一些关于此的文档并获得了以下代码:

static Solid CreateCube(double d)
{
     return CreateRectangularPrism(
          XYZ.Zero, d, d, d);
}
static Solid CreateRectangularPrism(
     XYZ center,
     double d1,
     double d2,
     double d3)
{
     List<Curve> profile = new List<Curve>();
     XYZ profile00 = new XYZ(-d1 / 2, -d2 / 2, -d3 / 2);
     XYZ profile01 = new XYZ(-d1 / 2, d2 / 2, -d3 / 2);
     XYZ profile11 = new XYZ(d1 / 2, d2 / 2, -d3 / 2);
     XYZ profile10 = new XYZ(d1 / 2, -d2 / 2, -d3 / 2);

     profile.Add(Line.CreateBound(profile00, profile01));
     profile.Add(Line.CreateBound(profile01, profile11));
     profile.Add(Line.CreateBound(profile11, profile10));
     profile.Add(Line.CreateBound(profile10, profile00));

     CurveLoop curveLoop = CurveLoop.Create(profile);

     SolidOptions options = new SolidOptions(
     ElementId.InvalidElementId,
     ElementId.InvalidElementId);

     return GeometryCreationUtilities
     .CreateExtrusionGeometry(
     new CurveLoop[] { curveLoop },
     XYZ.BasisZ, d3, options);
}

在 Execute() 方法中,我只有这个:

     using (Transaction tx = new Transaction(doc))
     {
        tx.Start("create cube");


        Solid cube = CreateCube(100);
        
        // What shall I do next??
        tx.Commit();
     }

此时我被卡住了,因为我似乎找不到任何方法在绘图中显示这个立方体。此外,更让我困惑的是立方体的 ID 设置为 -1。我还检查了它在代码中的可见性,它似乎是正确的,但是,它没有出现在绘图中的任何地方。我错过了什么?我怎样才能让它出现在图纸中?

非常欢迎任何提示,文档是代码!

谢谢。

【问题讨论】:

    标签: c# class-library revit-api


    【解决方案1】:

    您创建了一个 GeometryObject 但没有 Revit 元素,然后您看不到任何对象,因为没有要显示的数据库对象。

    您可以创建 DirectShape 并设置您创建的几何图形:

         var ds = DirectShape.CreateElement(revitDocument, new ElementId(BuiltInCategory.OST_GenericModel));
         ds.SetName("Cube");
         ds.SetShape(new List<GeometryObject>() { cube });
    

    【讨论】:

      猜你喜欢
      • 2021-06-01
      • 2019-08-06
      • 1970-01-01
      • 2019-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多