再开始接触Naviworks的开发时候会出现Dataproperty的值unknow的情况,这种场景不是报错而是在代码中需要判定值的属性,API会提供一个单独的转换方法,从这些方法中即可获取到正确的属性值。
像是上图一个墙体的属性在代码中直接ToString(),会获取到unknow,是因为没有使用单独的转化方法,通过下面的代码,对每个value进行单独的判定转换,即可获取到所有的值。
在Naviworks中依旧存在英寸与毫米的换算系数的情况,这种需要在进行一步转换。
var stringBuilder = new StringBuilder();
var doc = Application.ActiveDocument;
var selection = doc.CurrentSelection.SelectedItems;
var selectItem = selection[0];
foreach (var selectItemPropertyCategory in selectItem.PropertyCategories)
{
if (selectItemPropertyCategory.DisplayName.Equals("Element"))
{
foreach (var property in selectItemPropertyCategory.Properties)
{
if (property.Name.Contains("IFC"))
continue;
var value = property.Value;
if (value.IsDisplayString)
{
var stringTest = value.ToDisplayString();
}
else if (value.IsDoubleLength)
{
var valueParse = value.ToDoubleLength();
stringBuilder.AppendLine($"{property.DisplayName} - {valueParse}");
}
else if (value.IsDoubleArea)
{
var valueParse = value.ToDoubleArea();
stringBuilder.AppendLine($"{property.DisplayName} - {valueParse}");
}
else if (value.IsDoubleVolume)
{
var valueParse = value.ToDoubleVolume();
stringBuilder.AppendLine($"{property.DisplayName} - {valueParse}");
}
}
}
}
