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

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

小白鼠 2019-03-28 02:39:06 8 3643
比如你要获得组件所有的装配节点,可以从根节点进行遍历,如果你只想获得你指定节点下面的子组件,传入的第一个参数就传入你指定的节点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); } }


装配 · 递归 ·

发表评论

评论列表:

licxsw
2022-12-08 19:08
谢谢分享
小草
2022-07-12 13:44
匿名
2020-07-16 16:43
非常好,正在找,谢谢
匿名
2020-04-25 18:20
[blockquote][F1] 好羞射,
匿名
2020-04-25 18:17
[blockquote][F1] 好羞射,文章真的好赞啊,顶博主![/blockquote]
匿名
2019-11-25 13:20
学习一下
匿名
2019-06-29 11:45
学习一下你的方式
2019-03-28 22:58
文章很好,有借鉴意义