NX二次开发 获取组件实体

1.获取装配现在组件上的所有实体:

NXObject* ToNXObj(tag_t obj)
{
    if (obj == NULL_TAG)
    {
        return NULL;
    }
    return dynamic_cast<NXObject*>(ToTagObj(obj));
}



//单个装配组件下所有的实体
vector<tag_t> GetComponentBodies(Assemblies::Component* component)
{    
    vector<tag_t> bodies;

    tag_t compTag = component->Tag();
    tag_t member = NULL_TAG;
    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 == 70 && subType == 0)
        {
            bodies.push_back(member);
        }
        UF_ASSEM_cycle_objs_in_comp(compTag, &member);
    }

    return bodies;

}

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_part_occ_children(root, &child_part_occs);
    for (int i = 0; i < part_num; i++)
    {
        Assemblies::Component* component = dynamic_cast<Assemblies::Component*>(ToNXObj(child_part_occs[i]));
        vector<tag_t>tmpBodies = GetComponentBodies(component);

        for (auto item : tmpBodies)
        {
            bodies.push_back(item);
        }
    }

    return bodies;
}

 

  2.获取装配原先零件上的所有实体:

vector<tag_t> GetComponentOriginPartBodies()
{
    vector<tag_t> allBodies;

    Part* workPart = Session::GetSession()->Parts()->Work();
    tag_t workTag = workPart->Tag();

    tag_t root = UF_ASSEM_ask_root_part_occ(workTag);
    tag_t *child_components = NULL;
    int component_count = UF_ASSEM_ask_part_occ_children(root, &child_components);
    for (int i = 0; i < component_count; i++)
    {
        tag_t prototype = UF_ASSEM_ask_prototype_of_occ(child_components[i]);
        tag_t objTag = NULL_TAG;
        while (true)
        {
            UF_OBJ_cycle_objs_in_part(prototype, UF_solid_type, &objTag);
            if (objTag == NULL_TAG)
            {
                break;
            }
            else
            {
                int type = 0, subType = 0;
                UF_OBJ_ask_type_and_subtype(objTag, &type, &subType);
                if (type == 70 && subType == 0)
                {
                    allBodies.push_back(objTag);
                }

            }
        }
    }

    return allBodies;
}

 

 

 
  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值