NSDT工具推荐Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器 - REVIT导出3D模型插件 - 3D模型语义搜索引擎 - Three.js虚拟轴心开发包

Revit 2015 之后的 API 增强功能之一是提供新的 DirectShape 和 TessellatedShapeBuilder 类的导入 API 功能。

这些可以显着提高性能并为生成库和导入几何图形(尤其是重复形状)提供强大的新可能性。

另一方面,对最小尺寸的限制与过去相同。

1、DirectShape 性能

关于性能,这是去年 12 月在测试阶段首次推出后来自开发人员的第一个热烈反应和快速报告:

我稍微检查了 DirectShape 功能。我的结果非常有趣。

我实施了一个生成“房间实体”的基准测试。

过去,我必须为此创建一个新族,使用自由形式元素定义其几何形状,保存族,将其加载到项目中并放置一个实例。

对于 1390 个房间,该方法花费了大约 2 个小时,并且每个房间的文件大小增加了大约 60 Kb。

我使用 DirectShape 元素的第一个替代测试实施总共需要 40 秒,并且每个房间的文件大小增加了 2 Kb。

这为创建快速“永久”几何体提供了奇妙的新可能性!

更不用说现在的代码简单多了!

了解 Revit API 后,有一个明显的限制,但是......

2、DirectShape 最小尺寸

这是一个现在出现过几次的问题:

问题:我在 Revit 2015 中使用 TessellatedShapeBuilder 从一组面中创建了一个 DirectShape。

Revit 接受的边的最小长度为 0.0026 英尺。 如果我使用 0.0025 英尺,Revit 会崩溃。

我可以更改此公差吗?

或者是否有任何其他方法可以构造接受小于 0.0026 英尺的边的 DirectShape 元素?

答案:很遗憾,答案是否定的。

此容差无法更改,而且我不知道有任何其他方法可以创建 DirectShape 元素来规避该限制。

在 Revit 中创建对象时,你必须考虑大局,这让希望表现非常详细的金属和亚毫米木结构的人们感到懊恼。

创建单个模型线段的限制在 1/16 英寸左右,这同样适用于 DirectShape 元素边缘。

我实施了一些外部命令来对此进行测试。

它定义了一个名为 Iterate_until_crash 的静态布尔开关变量。

它默认设置为 false,在这种情况下,外部命令只需创建一个边长为 0.5 英尺的 DirectShape 四面体,如下所示:

它在 Visual Studio 调试输出窗口中报告其已完成的任务,如下所示:

  • 创建边长为 0.5 的 DirectShape 四面体...
  • 当 Iterate_until_crash 设置为 true 时,代码进入一个无限循环,在每次迭代中创建连续的 DirectShape 元素,每个元素的边长都是前面的一半。

不过,它很快就会抛出异常,因此没有任何形状最终被提交,调试输出现在报告:

Creating DirectShape tetrahedron with side length 0.5...
Creating DirectShape tetrahedron with side length 0.25...
Creating DirectShape tetrahedron with side length 0.125...
Creating DirectShape tetrahedron with side length 0.0625...
Creating DirectShape tetrahedron with side length 0.03125...
Creating DirectShape tetrahedron with side length 0.015625...
Creating DirectShape tetrahedron with side length 0.0078125...
Creating DirectShape tetrahedron with side length 0.00390625...
Creating DirectShape tetrahedron with side length 0.001953125...
  • RevitAPI.dll 中出现“Autodesk.Revit.Exceptions.InvalidOperationException”类型的第一次机会异常
  • 创建边长为 0.001953125 的 DirectShape 四面体引发异常“无法创建一致的顶点列表”

异常被传递回标准 Revit 故障处理程序:

下面是整个外部命令的实现:

#region Namespaces
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
#endregion
 
namespace DirectShapeMinSize
{
  [Transaction( TransactionMode.Manual )]
  public class Command : IExternalCommand
  {
    /// <summary>
    /// Set this to true to iterate through smaller 
    /// and smaller tetrahedron sizes until we hit
    /// Revit's precision limit.
    /// </summary>
    static bool Iterate_until_crash = false;
 
    public Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements )
    {
      UIApplication uiapp = commandData.Application;
      UIDocument uidoc = uiapp.ActiveUIDocument;
      Application app = uiapp.Application;
      Document doc = uidoc.Document;
 
      // Find GraphicsStyle
 
      FilteredElementCollector collector
        = new FilteredElementCollector( doc )
          .OfClass( typeof( GraphicsStyle ) );
 
      GraphicsStyle style = collector.Cast<GraphicsStyle>()
        .FirstOrDefault<GraphicsStyle>( gs => gs.Name.Equals( "<Sketch>" ) );
 
      ElementId graphicsStyleId = null;
 
      if( style != null )
      {
        graphicsStyleId = style.Id;
      }
 
      // Modify document within a transaction
 
      using( Transaction tx = new Transaction( doc ) )
      {
        tx.Start( "Create DirectShape" );
 
        double length = 1; // foot
 
        try
        {
          do
          {
            length = 0.5 * length;
 
            Debug.Print(
                "Creating DirectShape tetrahedron with side length {0}...",
                length );
 
            List<XYZ> args = new List<XYZ>( 3 );
 
            TessellatedShapeBuilder builder = new TessellatedShapeBuilder();
 
            builder.OpenConnectedFaceSet( false );
 
            args.Add( XYZ.Zero );
            args.Add( length * XYZ.BasisX );
            args.Add( length * XYZ.BasisY );
            builder.AddFace( new TessellatedFace( args, ElementId.InvalidElementId ) );
 
            args.Clear();
            args.Add( XYZ.Zero );
            args.Add( length * XYZ.BasisX );
            args.Add( length * XYZ.BasisZ );
            builder.AddFace( new TessellatedFace( args, ElementId.InvalidElementId ) );
 
            args.Clear();
            args.Add( XYZ.Zero );
            args.Add( length * XYZ.BasisY );
            args.Add( length * XYZ.BasisZ );
            builder.AddFace( new TessellatedFace( args, ElementId.InvalidElementId ) );
 
            args.Clear();
            args.Add( length * XYZ.BasisX );
            args.Add( length * XYZ.BasisY );
            args.Add( length * XYZ.BasisZ );
            builder.AddFace( new TessellatedFace( args, ElementId.InvalidElementId ) );
 
            builder.CloseConnectedFaceSet();
 
            TessellatedShapeBuilderResult result
              = builder.Build(
                TessellatedShapeBuilderTarget.Solid,
                TessellatedShapeBuilderFallback.Abort,
                graphicsStyleId );
 
            // Pre-release code from DevDays
 
            //DirectShape ds = DirectShape.CreateElement(
            //  doc, result.GetGeometricalObjects(), "A", "B");
 
            //ds.SetCategoryId(new ElementId(
            //  BuiltInCategory.OST_GenericModel));
 
            // Code updated for Revit UR1
 
            ElementId categoryId = new ElementId(
              BuiltInCategory.OST_GenericModel );
 
            DirectShape ds = DirectShape.CreateElement(
              doc, categoryId, "A", "B" );
 
            ds.SetShape( result.GetGeometricalObjects() );
 
            ds.Name = "Test";
          }
          while( Iterate_until_crash && 0 < length );
        }
        catch( Exception e )
        {
          Debug.Print(
            "Creating DirectShape tetrahedron with side length {0} "
            + "threw exception '{1}'",
            length, e.Message );
 
          message = e.Message;
          return Result.Failed;
        }
        tx.Commit();
      }
      return Result.Succeeded;
    }
  }
}

点击下载 DirectShapeMinSize.zip,它提供了 DirectShapeMinSize 外部命令的完整源代码、Visual Studio 解决方案和加载项清单。


原文链接:DirectShape Performance and Minimum Size

BimAnt翻译整理,转载请标明出处