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