NX/UG二次开发——查找失去关联的wave面
查找失去关联的PMI标注
在UG使用过程中,模型变更后有些wave面可能会失去关联。失去关联的wave面可以通过模型树来发现。这里介绍一种二次开发的方法,来识别失去关联的wave面,以便开发者对失去关联的wave面进行编辑。
1.遍历获得所有wave面片体的tag
void get_solid_tag(std::vector<tag_t>& extract_sheets_collection)
{
int thetype, thesubtype, body_type;
tag_t objectTAG = NULL_TAG;
UF_OBJ_cycle_objs_in_part(UF_ASSEM_ask_work_part(), UF_solid_type, &objectTAG);//获得部件上对象类型为UF_solid_type的TAG
while (objectTAG != NULL_TAG)
{
UF_OBJ_ask_type_and_subtype(objectTAG, &thetype, &thesubtype);//获得块的类型和子类型
if (thesubtype == UF_solid_body_subtype)
{
UF_MODL_ask_body_type(objectTAG, &body_type);
if (body_type == UF_MODL_SHEET_BODY)
{
extract_sheets_collection.push_back(objectTAG);//获取片体(wave面)tag
}
}
UF_OBJ_cycle_objs_in_part(UF_ASSEM_ask_work_part(), UF_solid_type, &objectTAG);
}
}
2.检查wave面的关联性
bool wave_is_associate(tag_t sheet_tag)
{
NXOpen::Session *theSession = NXOpen::Session::GetSession();
NXOpen::Part *workPart(theSession->Parts()->Work());
NXOpen::Part *displayPart(theSession->Parts()->Display());
//体找特征
uf_list_p_t extract_faces_feats;
UF_MODL_ask_body_feats(sheet_tag, &extract_faces_feats);//遍历获得的是片体的tag,要通过体找面获得wave面的tag。
UF_MODL_ask_list_item(extract_faces_feats, 0, &extract_face_tag);//wave面片体获得的面是一个面,因此链表第一个tag就是wave面的tag。
//检测抽面是否关联
NXOpen::Session::UndoMarkId markId1;
markId1 = theSession->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Redefine Feature");
NXOpen::Features::ExtractFace *extractFace1(dynamic_cast<NXOpen::Features::ExtractFace *>(NXOpen::NXObjectManager::Get(extract_face_tag)));//将UF对象转换为NXOPEN对象。
NXOpen::Features::ExtractFaceBuilder *extractFaceBuilder1;
extractFaceBuilder1 = workPart->Features()->CreateExtractFaceBuilder(extractFace1);
extract_bool = extractFaceBuilder1->Associative();//调用构建器中的关联函数,查看是否关联
return extract_bool;//返回布尔值,如果关联为true,不关联为false。
}
3.执行函数
void MyClass::do_it()
{
// TODO: add your code here
UF_initialize();
std::vector<tag_t> extract_sheets_collection;
void get_solid_tag(extract_sheets_collection);//获得零件中所有PMI的tag。
bool result;
for (int i = 0; i < (int)extract_sheets_collection.size(); i++)//
{
result = wave_is_associate(extract_sheets_collection[i]);//检查PMI是否关联,关联返回true,不关联返回false。
}
UF_terminate();
}