简体   繁体   English

如何在 Revit API 中显示创建的立方体?

[英]How can I display the created cube in Revit API?

This might sound like a very basic question, and I apologize for that - however, I literally couldn't find anything about this anywhere around.这听起来像是一个非常基本的问题,对此我深表歉意——但是,我在任何地方都找不到任何关于此的信息。

I am trying to make a command which creates a cube made of model lines and puts it in the drawing.我正在尝试创建一个由 model 线组成的立方体并将其放入绘图中的命令。 For the cube creation, I've found on Jeremy Tammik's blog some documentation about this and got the following code:对于多维数据集的创建,我在 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);
}

In the Execute() method, I only have this:在 Execute() 方法中,我只有这个:

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


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

At this point I am stuck, as I can't seem to find any way to display this cube in the drawing.在这一点上,我被困住了,因为我似乎找不到任何方法在绘图中显示这个立方体。 Moreover, what is further confusing me is that the cube's Id is set to -1.此外,更让我困惑的是立方体的 ID 设置为 -1。 I also checked its visibility in code and it seems to hold true, however, it does not appear anywhere in the drawing.我还检查了它在代码中的可见性,它似乎是正确的,但是,它没有出现在绘图中的任何地方。 What am I missing out?我错过了什么? How can I make it appear in the drawing?我怎样才能让它出现在图纸中?

Any tips, documentation is code is highly welcome!非常欢迎任何提示,文档就是代码!

Thank you.谢谢你。

You have created a GeometryObject but no Revit Element, then you cannot see any object because there is no a database object to show.您创建了一个 GeometryObject 但没有 Revit 元素,然后您看不到任何 object,因为没有要显示的数据库 object。

You could create a DirectShape and set the geometry that you created:您可以创建 DirectShape 并设置您创建的几何图形:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM