1 UF_initialize(); 2 std::vector<tag_t>tool_tag; 3 std::vector<tag_t>del_tag; 4 tag_t ObjectTag = NULL_TAG; 5 int Type, SubType,n; 6 UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_machining_tool_type, &ObjectTag); 7 while (ObjectTag != NULL_TAG) 8 { 9 UF_OBJ_ask_type_and_subtype(ObjectTag, &Type, &SubType); 10 if (Type == UF_machining_tool_type && SubType == UF_mach_tool_subtype) 11 { 12 int count1; 13 tag_t * list1; 14 UF_NCGROUP_ask_member_list(ObjectTag, &count1, &list1); 15 if (count1 == 0) 16 { 17 del_tag.push_back(ObjectTag); 18 } 19 else 20 { 21 tool_tag.push_back(ObjectTag); 22 } 23 } 24 UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_machining_tool_type, &ObjectTag); 25 } 26 if(del_tag.size()) 27 { 28 tag_t *toollist = new tag_t[del_tag.size() - 1]; 29 size_t p = del_tag.size(); 30 n = static_cast <int> (p);//优雅的解决“从“size_t”转换到“int”,可能丢失数据” 这个错误! 31 for (size_t i = 0; i < n; i++) 32 { 33 toollist[i] = del_tag[i]; 34 } 35 UF_CALL(UF_OBJ_delete_array_of_objects(n, toollist, NULL)); 36 delete toollist; 37 } 38 39 for (int i = 0; i < tool_tag.size(); i++) 40 { 41 int count1; 42 tag_t * list; 43 char msg[256], msg1[256]; 44 UF_NCGROUP_ask_member_list(tool_tag[i], &count1, &list); 45 UF_OBJ_ask_name(tool_tag[i], msg1); 46 sprintf(msg, " 刀具下有%d个操作: ", count1); 47 strcat(msg1, msg); 48 print(msg1); 49 for (size_t j = 0; j < count1; j++) 50 { 51 char name[UF_OBJ_NAME_LEN]; 52 UF_OBJ_ask_name(list[j], name); 53 print(name); 54 } 55 UF_free(list); 56 } 57 UF_terminate();