admin 发表于 2014-2-18 13:07:13

NX二次开发:选择方式代码大全

选择方式包括通过mask过滤,通过type选择,或者通过选择所有的对象。

/------------------------------------------------------------------------------
// Selection with mask
//------------------------------------------------------------------------------
TaggedObject* MyClass::select_by_mask()
{
NXString message("Select an object by mask:");
NXString title("Select object");
Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;
Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
bool include_features = 0;
bool keep_highlighted = 0; // Define the mask triple(s), see also uf_object_types.h.
// Uncomment or combine the desired mask triples
std::vector<Selection::MaskTriple> maskArray(1);
maskArray = Selection::MaskTriple( UF_solid_type, UF_solid_body_subtype, 0 ); // Bodies
/*
maskArray = Selection::MaskTriple( UF_solid_type, UF_all_subtype, UF_UI_SEL_FEATURE_ANY_FACE); // Faces
maskArray = Selection::MaskTriple( UF_solid_type, UF_all_subtype, UF_UI_SEL_FEATURE_ANY_EDGE); // Edges
maskArray = Selection::MaskTriple( UF_component_type, 0, 0 ); // Components
maskArray = Selection::MaskTriple( UF_line_type, 0, 0 ); // Lines
maskArray = Selection::MaskTriple( UF_drafting_entity_type, 0, 0 ); // Drafting objects
*/
Point3d cursor;
TaggedObject *object; // Select objects using filter defined by maskArray triples
Selection::Response res = selmgr->SelectTaggedObject(
   message, title, scope, action, include_features,
            keep_highlighted, maskArray, &object, &cursor ); if( res == Selection::ResponseObjectSelected )
{
return object;
}
return 0;
}//------------------------------------------------------------------------------
// Selection with type array
//------------------------------------------------------------------------------
TaggedObject* MyClass::select_by_type()
{
NXString message("Select an object by type:");
NXString title("Select object");
Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;
bool keep_highlighted = 0; // Define the mask triple(s), see also uf_object_types.h.
// Uncomment or combine the desired types
std::vector<Selection::SelectionType> typeArray(1);
typeArray = Selection::SelectionTypeAll;
/*
typeArray = Selection::SelectionTypeFeatures;
typeArray = Selection::SelectionTypeCurves;
typeArray = Selection::SelectionTypeFaces;
typeArray = Selection::SelectionTypeEdges;
typeArray = Selection::SelectionTypeCurvesAndEdges;
*/
Point3d cursor;
TaggedObject *object; // Select objects using filter defined by type array
Selection::Response res = selmgr->SelectTaggedObject(
   message, title, scope, keep_highlighted,
   typeArray, &object, &cursor ); if( res == Selection::ResponseObjectSelected )
{
return object;
}
return 0;
}//------------------------------------------------------------------------------
// Selection any objects
//------------------------------------------------------------------------------
std::vector< NXOpen::TaggedObject * > MyClass::select_any_objects()
{
NXString message("Select any objects:");
NXString title("Select objects");
Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;
bool include_features = 0;
bool keep_highlighted = 0;
std::vector< NXOpen::TaggedObject * > objectArray; // Select any object array
Selection::Response res = selmgr->SelectTaggedObjects(
   message, title, scope, include_features,
   keep_highlighted, objectArray ); return objectArray;
}



sl2651668521 发表于 2014-3-2 18:36:05

老大 为什么把你的这个代码放在这里会提示错误啊。。。新手一枚,问题幼稚,请多指教 谢谢

admin 发表于 2014-3-2 19:34:19

sl2651668521 发表于 2014-3-2 10:36
老大 为什么把你的这个代码放在这里会提示错误啊。。。新手一枚,问题幼稚,请多指教 谢谢 ...

你抱什么错
头文件 加了么

admin 发表于 2014-3-2 19:34:21

sl2651668521 发表于 2014-3-2 10:36
老大 为什么把你的这个代码放在这里会提示错误啊。。。新手一枚,问题幼稚,请多指教 谢谢 ...

你抱什么错
头文件 加了么

sl2651668521 发表于 2014-3-2 19:47:18

还需要加什么头文件? 我是利用vc中ug模块建立的工程

wyw6686 发表于 2015-11-5 14:55:45

老大,这个 selmgr 是个什么东西,怎么定义啊?

玉叶飘红 发表于 2015-11-13 21:09:39

果然经典:lol
页: [1]
查看完整版本: NX二次开发:选择方式代码大全