点击查看详细介绍

递归方式获得装配下指定节点下的所有子组件Component 精华帖

nxopen 7年前 2638 13

购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008  QQ号:85585969  


比如你要获得组件所有的装配节点,可以从根节点进行遍历,如果你只想获得你指定节点下面的子组件,传入的第一个参数就传入你指定的节点Component即可。

例:获得根节点下的所有子组件(及装配全部子组件,用NXOpen方式)

//获得根节点
Assemblies::Component *rootComponent = theSession->Parts()->Display()->ComponentAssembly()->RootComponent();
vector<Assemblies::Component *> pComponents;
GetAppointComponents(rootComponent , pComponents); //获得根节点下所有组件
//-------以下为递归函数------
//获得指定节点下的所有组件函数(采用递归方式)
void GetAppointComponents(Assemblies::Component *component, vector<Assemblies::Component *>& pComponents)
{

●●●请先 登陆注册 后查看●●●

   for(int i=0; i<childComponent.size(); i++)            
   {
     pComponents.push_back(childComponent);
     GetAppointComponents( childComponent,  pComponents);
   }
}


0

最新回复 (13)
  • licxsw 7年前
    1

    dsfasfasfasfasfasfas

  • qq576705724 7年前
    2

    啦啦啦啦啦咯啦咯啦咯啦啦啦啦

  • lrsunny 7年前
    3

    感谢楼主解惑,最近被这个问题困了好久

  • lrsunny 7年前
    4

    有C版本的 代码吗?

  • liuxiong 6年前
    5

    112241114

  • bao7659535 VIP会员 6年前
    6

    谢谢分享(*?∀?)=3

  • fuyueliang 6年前
    7

    谢谢分享!!!!

  • liketulip 4年前
    8

    谢谢分享,基础却实用

  • jamsona 4年前
    9

    学习学习。。。。。。

  • hades 4年前
    10

    谢谢分享,基础却实用,牛逼了,正需要这个

  • hades 4年前
    11

    pComponents.push_back(childComponent[i]);这里错了吧

  • dzx99 3年前
    12

    学习,谢谢分享!!

  • 李林威 3年前
    13

    谢谢分享,基础却实用

请登录后发表新帖