1、函数说明:获取装配下单个组件下的所有实体
参数说明:传入参数为组件对象tag
返回值:组件中所有实体对象
vector<tag_t> GetComponentBodies(Assemblies::Component* component)
{
vector<tag_t> bodies;
tag_t compTag = component->Tag();
tag_t member = NULL_TAG;
if (compTag == NULL_TAG)
{
return bodies;
}
UF_ASSEM_cycle_objs_in_comp(compTag, &member);
while (member != NULL_TAG)
{
int type = 0, subtype = 0;
UF_OBJ_ask_type_and_subtype(member, &type, &subtype);
if (type == UF_solid_type && subtype == 0)
{
bodies.push_back(member);
}
UF_ASSEM_cycle_objs_in_comp(compTag, &member);
}
return bodies;
}
2、函数说明:获取装配下所有实体对象返回值:装配中所有实体对象
vector<tag_t> GetAssemBodies()
{
vector<tag_t> bodies;
Part* workPart = Session::GetSession()->Parts()->Work();
tag_t workTag = workPart->Tag();
tag_t root = UF_ASSEM_ask_root_part_occ(workTag);
tag_t* child_part_occs;
int part_num = UF_ASSEM_ask_all_part_occ_children(root, &child_part_occs);
for (int i=0; i<part_num; i++)
{
Assemblies::Component* component = dynamic_cast<Assemblies::Component*>(NXObjectManager::Get(child_part_occs[i]));
vector<tag_t> tmpBodies = GetComponentBodies(component);
for (vector<tag_t>::iterator item = tmpBodies.begin(); item != tmpBodies.end(); item++)
{
bodies.push_back(*item);
}
}
UF_free(child_part_occs);
return bodies;
}
3、函数说明:将组件设置为当前工作部件
void SetComponentPartAsWorkPart(tag_t componentTag)
{
Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
Assemblies::Component *component1(dynamic_cast<Assemblies::Component *>(NXOpen::NXObjectManager::Get(componentTag)));
PartLoadStatus *partLoadStatus1;
theSession->Parts()->SetWorkComponent(component1, &partLoadStatus1);
workPart = theSession->Parts()->Work();
delete partLoadStatus1;
}
402

被折叠的 条评论
为什么被折叠?



