NX二次开发-遍历当前part所有component,把装配子部件设置成工作部件

 1 NX11+VS2013
 2 
 3 #include <uf.h>
 4 #include <uf_disp.h>
 5 #include <uf_modl.h>
 6 #include <uf_part.h>
 7 #include <uf_obj.h>
 8 #include <uf_assem.h>
 9 #include <uf_ui.h>
10 #include <string.h>
11 #include <NXOpen/NXObjectManager.hxx>
12 #include <NXOpen/NXException.hxx>
13 #include <NXOpen/Session.hxx>
14 #include <NXOpen/Assemblies_Component.hxx>
15 #include <NXOpen/Assemblies_ComponentAssembly.hxx>
16 #include <NXOpen/BasePart.hxx>
17 #include <NXOpen/MenuBar_ContextMenuProperties.hxx>
18 #include <NXOpen/Part.hxx>
19 #include <NXOpen/PartCollection.hxx>
20 #include <NXOpen/PartLoadStatus.hxx>
21 #include <NXOpen/Selection.hxx>
22 #include <NXOpen/Session.hxx>
23 #include <NXOpen/TaggedObject.hxx>
24 #include <algorithm>
25 #include <NXOpen/STLCreator.hxx>
26 #include <NXOpen/DexManager.hxx>
27 #include <iostream>
28 #include <string.h>
29 #include <algorithm>
30 #include <iterator>
31 #include <cctype>
32 
33 
34 
35 void MyClass::CycleComponent()
36 {
37     //遍历当前part所有component
38     tag_t ComponentTag = NULL_TAG;
39     UF_OBJ_cycle_objs_in_part(UF_ASSEM_ask_work_part(), UF_component_type, &ComponentTag);
40     while (ComponentTag != NULL_TAG)
41     {
42         //获的显示的体
43         UF_OBJ_disp_props_t Componentdisp_props;
44         UF_OBJ_ask_display_properties(ComponentTag, &Componentdisp_props);
45         int ComponentBlank = Componentdisp_props.blank_status;
46         if (ComponentBlank == UF_OBJ_NOT_BLANKED)
47         {
48             //把装配子部件设置成工作部件
49             NXOpen::Assemblies::Component *component1(dynamic_cast<NXOpen::Assemblies::Component *>(NXOpen::NXObjectManager::Get(ComponentTag)));
50             NXOpen::PartLoadStatus *partLoadStatus1;
51             theSession->Parts()->SetWorkComponent(component1, NXOpen::PartCollection::RefsetOptionEntire, NXOpen::PartCollection::WorkComponentOptionVisible, &partLoadStatus1);
52             workPart = theSession->Parts()->Work();
53             delete partLoadStatus1;
54 
55             //遍历工作部件里的体
56             CycleComponentBody();
57 
58             //恢复到装配部件
59             NXOpen::Assemblies::Component *nullNXOpen_Assemblies_Component(NULL);
60             NXOpen::PartLoadStatus *partLoadStatus2;
61             theSession->Parts()->SetWorkComponent(nullNXOpen_Assemblies_Component, NXOpen::PartCollection::RefsetOptionEntire, NXOpen::PartCollection::WorkComponentOptionVisible, &partLoadStatus2);
62             workPart = theSession->Parts()->Work();
63             delete partLoadStatus2;
64         }
65 
66 
67         UF_OBJ_cycle_objs_in_part(UF_ASSEM_ask_work_part(), UF_component_type, &ComponentTag);
68     }
69 
70 }
原文地址:https://www.cnblogs.com/nxopen2018/p/10981780.html