NX二次开发-选择对象控件过滤(高级过滤)

2023-12-18 15:00:09

一、概述

????????在NX二次开发的时候,我们经常会用到选择对象控件。但是在选择对象的时候,我们往往需要指定选择对象的类型和范围,此时就需要对选择对象控件设置过滤,避免选中不必要的对象和规定选择的范围,提升方便用户的使用体验。

二、实现方法

????????通过设置控件属性,确定选择对象控件选择的类型。此处选择的类型可以是多个,类型值可以在帮助文档中查找。本例子适用可以选择边对象,也可以选择组件对象。

//两种写法,原理一样
NXOpen::Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
std::vector<NXOpen::Selection::MaskTriple>selectionMask_array(2);//括号内数字:maskArray数组大小(有多少种选择就写多少)//具体用法参考MaskTriple
selectionMask_array[0].Type = UF_component_type;
selectionMask_array[0].Subtype = UF_component_subtype;//装配中的对象
selectionMask_array[1].Type = UF_component_type;
selectionMask_array[1].Subtype = UF_part_occurrence_subtype;//装配导航器上的树节点对象
selectionMask_array[2].Type = UF_solid_type;//选择实体上的边
selectionMask_array[2].Subtype = UF_solid_edge_subtype;
selectionMask_array[2].SolidBodySubtype = UF_UI_SEL_FEATURE_ANY_EDGE;

NXOpen::BlockStyler::PropertyList *selComponentProps = selComp->GetProperties();//selComp为对象收集器的ID
selComponentProps->SetSelectionFilter("SelectionFilter", action, selectionMask_array);
delete selComponentProps;
selComponentProps = NULL;
//------------------------------------------------------------
Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
std::vector<Selection::MaskTriple>maskArray(3); //括号内数字:maskArray数组大小(有多少种选择就写多少)
maskArray[0] = Selection::MaskTriple(UF_component_type, UF_component_subtype, 0);
maskArray[1] = Selection::MaskTriple(UF_component_type, UF_part_occurrence_subtype, 0);
maskArray[2] = Selection::MaskTriple(UF_solid_type, UF_solid_edge_subtype, UF_UI_SEL_FEATURE_ANY_EDGE);
selComp->GetProperties()->SetSelectionFilter("SelectionFilter", action, maskArray);

三、效果展示:

文章来源:https://blog.csdn.net/weixin_47753171/article/details/135059656
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。