新的版本中增加了这个属性,据国外同行测试会影响速度。我查看帮助文件,发现2017版本已经有这个属性。
国外同行Github代码地址:
https://github.com/razorcx/speed-test/blob/master/SpeedTest/Program.cs
using System.Collections;
using System.Collections.Generic;
using Tekla.Structures;
using Tekla.Structures.Filtering;
using Tekla.Structures.Filtering.Categories;
using Tekla.Structures.Model;
namespace SpeedTest
{
public class Program
{
static void Main(string[] args)
{
new SpeedTest().Run();
}
}
public class SpeedTest
{
public void Run()
{
var model = new Model();
//IMPORTANT!!! ModelObjectEnumerator.AutoFetch = true;
var parts1 = model.GetAllParts(true); //fastest!!!
//USING THE FILTER EXPRESSIONS - ModelObjectEnumerator.AutoFetch = true
var parts2 = model.GetParts(true); //very fast with more flexibility
//ModelObjectEnumerator.AutoFetch - ModelObjectEnumerator.AutoFetch = false
var parts3 = model.GetAllParts(false); //very slow
//USING THE FILTER EXPRESSIONS - ModelObjectEnumerator.AutoFetch = false
var parts4 = model.GetParts(false); //very slower
}
}
public static class ExtensionMethods
{
public static List<Part> GetAllParts(this Model model, bool autoFetch)
{
//IMPORTANT!!!
ModelObjectEnumerator.AutoFetch = autoFetch;
//parts
var types = new[] { typeof(Beam), typeof(BentPlate),
typeof(ContourPlate), typeof(PolyBeam) };
var parts = model
.GetModelObjectSelector()
.GetAllObjectsWithType(types)
.ToAList<Part>();
return parts;
}
public static List<T> ToAList<T>(this IEnumerator enumerator)
{
var list = new List<T>();
while (enumerator.MoveNext())
{
var current = (T)enumerator.Current;
if (current != null)
list.Add(current);
}
return list;
}
public static List<Part> GetParts(this Model model, bool autoFetch)
{
ObjectFilterExpressions.Type objectType = new ObjectFilterExpressions.Type();
NumericConstantFilterExpression type =
new NumericConstantFilterExpression(TeklaStructuresDatabaseTypeEnum.PART);
var expression2 = new BinaryFilterExpression(objectType, NumericOperatorType.IS_EQUAL, type);
BinaryFilterExpressionCollection filterCollection =
new BinaryFilterExpressionCollection
{
new BinaryFilterExpressionItem(expression2, BinaryFilterOperatorType.BOOLEAN_AND),
};
//IMPORTANT!!!
ModelObjectEnumerator.AutoFetch = autoFetch;
return model
.GetModelObjectSelector()
.GetObjectsByFilter(filterCollection)
.ToAList<Part>();
}
}
}
这篇博客探讨了 Tekla Structures 中一个新添加的属性如何影响模型对象枚举的速度。通过测试代码展示了不同设置下获取零件的速度差异,包括 ModelObjectEnumerator.AutoFetch 的真伪对性能的影响。实验结果显示,AutoFetch 设置为 true 可显著提升枚举速度。
ModelObjectEnumerator.AutoFetch&spm=1001.2101.3001.5002&articleId=120592851&d=1&t=3&u=b22b788cf8264c40af38c1423ac14bd7)
373

被折叠的 条评论
为什么被折叠?



