1 NX9+VS2012 2 3 #include <uf.h> 4 #include <uf_obj.h> 5 #include <uf_modl.h> 6 #include <uf_part.h> 7 8 9 UF_initialize(); 10 11 //遍历当前显示部件 12 std::vector<tag_t> SolidVector; 13 tag_t ObjectTag = NULL_TAG; 14 int Type, SubType, Body_Type; 15 char msg[256]; 16 UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &ObjectTag);//遍历体 17 while (ObjectTag != NULL_TAG) 18 { 19 //查询对象的类型和子类型 20 UF_OBJ_ask_type_and_subtype(ObjectTag, &Type, &SubType); 21 if (SubType == UF_solid_body_subtype) 22 { 23 //查询体的类型 24 UF_MODL_ask_body_type(ObjectTag, &Body_Type); 25 if (Body_Type == UF_MODL_SOLID_BODY)//为实体 26 { 27 UF_OBJ_set_color(ObjectTag, 186); 28 SolidVector.push_back(ObjectTag); 29 } 30 } 31 UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &ObjectTag); 32 } 33 34 sprintf_s(msg, "当前有%d个实体", SolidVector.size()); 35 lw->Open(); 36 lw->WriteLine(msg); 37 38 39 UF_terminate();