NavisWorks二次开发-获取当前选择集的属性值

NavisWorks二次开发-获取当前选择集的属性值
下面给出一个例子:
把构件中所有含有元素特性的全部筛选出来。
选中构件的特性窗口

废话不多说,直接上代码。


       
       public void GetHandle(Document doc)//一个获取实体句柄的函数
    {
        string handlevalue=null;
        string[] HandleValue=null;
        string EntityHandle;
        List<Model_Para> para = new List<Model_Para>();
        if (Application.ActiveDocument != null &&
           !Application.ActiveDocument.IsClear)
        {               
            //documentControl1.Document.Tool.Value = Autodesk.Navisworks.Api.Tool.Select;
            foreach (ModelItem item in Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems)
            {
                Model_Para model_Para = new Model_Para();//放循环外面会造成添加到集合里的元素参数变成一样的,并且导致下面的集合add之后只有一个元素
                //iterate the item's PropertyCategory entries   lcldrevit_parameter_225862  225864  570150  570152
                foreach (PropertyCategory category in item.PropertyCategories)
                {
                    if (category.Name== "LcRevitData_Element")
                    {
                        foreach (DataProperty dataProperty in category.Properties)
                        {
                            string name = dataProperty.DisplayName;
                            if (name.EndsWith("编码"))//"570150 LcOaNat64AttributeValue"我个人理解是在系统中的名称                        
                            {
                                handlevalue = dataProperty.Value.ToString();//得到是字符串类似“displaystring:EB4”
                                HandleValue = handlevalue.Split(':');//按“:”分割
                                model_Para.Para = HandleValue[1];
                                model_Para.modelItem = item;
                                para.Add(model_Para);                                  
                            }
                            if (name.EndsWith("编码描述"))
                            {
                                handlevalue = dataProperty.Value.ToString();
                                HandleValue = handlevalue.Split(':');
                                model_Para.Define = HandleValue[1];
                            }
                            if (dataProperty.CombinedName.Name.ToString()=="LcRevitPropertyElementId")
                            {
                                handlevalue = dataProperty.Value.ToString();
                                HandleValue = handlevalue.Split(':');
                                model_Para.Id = HandleValue[1];
                            }
                        }
                    }                     
                   
                }                   
            }
         
        }
       
    }


现在的问题是如何根据自己设置的条件检索所有具有某种参数的构件集合呢?
	
具体的代码如下:
public void Search_Test()
    {
        Document doc = Application.ActiveDocument;
        Search search = new Search();
        SearchCondition searchCondition = SearchCondition.HasCategoryByDisplayName("元素");
        //searchCondition = searchCondition.DisplayStringContains("项目编码");
        //SearchCondition searchCondition = SearchCondition.HasPropertyByDisplayName("元素", "项目编码");
        search.SearchConditions.Add(searchCondition);
        search.Selection.SelectAll();
        search.Locations = SearchLocations.DescendantsAndSelf;
        if (Application.ActiveDocument!=null)
        {
            var selection = Application.ActiveDocument.CurrentSelection;
            var root = doc.SelectionSets.RootItem;
            Application.ActiveDocument.CurrentSelection.CopyFrom(search.FindAll(Application.ActiveDocument, false));
            ModelItemCollection modelCollec = new ModelItemCollection();
            foreach (var item in selection.SelectedItems)
            {
                modelCollec.Add(item);
            }
            SelectionSet selectionSet = new SelectionSet(modelCollec);
            selectionSet.DisplayName = "筛选的含有编码选择集";
            //doc.SelectionSets.AddCopy((root.Children[0] as GroupItem).Children[0] as GroupItem,selectionSet);
        }
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值