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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM