比如我們想輸出模型中紅色部分部件清單
我們需要先知道紅色的代號是什么 弥咪,獲取方法 點(diǎn)此前往 。
然后修改下面代碼中color值即可族檬。
Color myColor = new Color(1.0, 0.0, 0.0); // construct color you want to find
我們可以使用如下腳本
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Navisworks.Api;
using Color = Autodesk.Navisworks.Api.Color;
namespace CScript
{
public class CScript
{
static public void Main()
{
// export name with override color https://forums.autodesk.com/t5/navisworks-api/select-elements-by-color-override/td-p/7084412
Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
Color myColor = new Color(1.0, 1.0, 0.0); // construct color you want to find
ModelItemCollection hidden = new ModelItemCollection();
ModelItemCollection oModelColl= oDoc.CurrentSelection.SelectedItems;
int n = oModelColl.Count();
if (n != 1) {
Console.WriteLine("Please Select In Selection Tree!!!");
return;
}
ModelItem ce = oModelColl[0];
var descendants = ce.Descendants;
Color itemColor;
Console.WriteLine("Start Search Color {0} from {1} ", myColor, ce.DisplayName );
foreach(ModelItem oItem in descendants) {
try{
itemColor = oItem.Geometry.PermanentColor;
if( itemColor.ToString() == myColor.ToString()){
Console.WriteLine("{3}\t{2}\t{1}",oItem.Geometry.PermanentColor, oItem.DisplayName, oItem.Parent.DisplayName, oItem.Parent.Parent.DisplayName );
hidden.Add(oItem); // 如果不需要隱藏,請把我注釋掉
}
}
catch(Exception)
{
continue;
}
}
Autodesk.Navisworks.Api.Application.ActiveDocument.Models.SetHidden(hidden, true);
}
}
}