刀具改名

  1 //存放刀具容器
  2     std::vector<string> rootName;
  3     std::vector<tag_t> toolTag;
  4 
  5     // TODO: add your code here
  6     UF_initialize();
  7 
  8     tag_t obj = NULL_TAG;
  9     UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_machining_tool_type, &obj);
 10     while (obj != NULL_TAG)
 11     {
 12         int Type = 0, Subtype = 0;
 13         UF_OBJ_ask_type_and_subtype(obj, &Type, &Subtype);
 14         if (Subtype == UF_mach_tool_subtype)
 15         {
 16             UF_CUTTER_ask_type_and_subtype(obj, &Type, &Subtype);
 17             //铣刀
 18             if (Type== UF_CUTTER_TYPE_MILL)
 19             {
 20                 char tollname[256];
 21                 UF_OBJ_ask_name(obj, tollname);
 22 
 23                 if (RR(tollname, "DJ") || RR(tollname, "R") || RR(tollname, "NR"))
 24                 {
 25                     //是倒角刀
 26                 }
 27                 else
 28                 {
 29                     double 直径;
 30                     UF_PARAM_ask_double_value(obj, UF_PARAM_TL_DIAMETER, &直径);
 31                     char tollname1[256];
 32                     //int DD = (int)直径;
 33                     sprintf(tollname1, "D%g", 直径);
 34                     UF_OBJ_set_name(obj, tollname1);
 35                 }
 36             }
 37             //钻头
 38             if (Type == UF_CUTTER_TYPE_DRILL)
 39             {
 40                 char tollname[256];
 41                 UF_OBJ_ask_name(obj, tollname);
 42                 if (RR(tollname, "DD") || RR(tollname, "V") || RR(tollname, "E"))
 43                 {
 44                     //是打点刀
 45                 }
 46                 else
 47                 {
 48                     double 直径;
 49                     UF_PARAM_ask_double_value(obj, UF_PARAM_TL_DIAMETER, &直径);
 50                     char tollname1[256];
 51                     sprintf(tollname1, "Z%g", 直径);
 52                     UF_OBJ_set_name(obj, tollname1);
 53                     //toolTag.push_back(obj);
 54                     //rootName.push_back(tollname1);
 55                 }
 56                 //铰孔前粗踩刀
 57                 double 直径1;
 58                 UF_PARAM_ask_double_value(obj, UF_PARAM_TL_DIAMETER, &直径1);
 59                 if (直径1==2.9|| 直径1 == 3.9|| 直径1 == 4.9|| 直径1 == 5.9)
 60                 {
 61                     double 直径;
 62                     UF_PARAM_ask_double_value(obj, UF_PARAM_TL_DIAMETER, &直径);
 63                     char tollname1[256];
 64                     sprintf(tollname1, "C%g", 直径);
 65                     UF_OBJ_set_name(obj, tollname1);
 66                 }
 67             }
 68         }
 69         UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_machining_tool_type, &obj);
 70     }
 71 
 72     tag_t reObj = NULL_TAG;
 73     UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_machining_tool_type, &reObj);
 74     while (reObj != NULL_TAG)
 75     {
 76         int Type1 = 0, Subtype1 = 0;
 77         UF_OBJ_ask_type_and_subtype(reObj, &Type1, &Subtype1);
 78         if (Subtype1 == UF_mach_tool_subtype)
 79         {
 80             UF_CUTTER_ask_type_and_subtype(reObj, &Type1, &Subtype1);
 81             //铣刀
 82             if (Type1 == UF_CUTTER_TYPE_MILL)
 83             {
 84                 char tollname[256];
 85                 UF_OBJ_ask_name(reObj, tollname);
 86                 if (RR(tollname, "DJ") || RR(tollname, "R") || RR(tollname, "NR"))
 87                 {
 88                     //是倒角刀
 89                 }
 90                 else
 91                 {                    
 92                     rootName.push_back(tollname);
 93                     toolTag.push_back(reObj);
 94                 }
 95             }
 96         }
 97 
 98         UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_machining_tool_type, &reObj);
 99     }
100 
101     //removeDuplication(rootName);
102 
103 
104     sort(rootName.begin(), rootName.end());//排序
105     rootName.erase(unique(rootName.begin(), rootName.end()), rootName.end());//去重
106     //for (size_t j = 0; j < rootName.size(); j++)
107     //{
108     //    print(rootName[j].c_str());
109     //}
110 
111     vector<vector<tag_t>>reT(100);    
112     for (size_t l = 0; l < toolTag.size(); l++)
113     {
114         for (size_t m = 0; m < rootName.size(); m++)
115         {
116             char oname[256];
117             UF_OBJ_ask_name(toolTag[l], oname);
118             if (!strcmp(rootName[m].c_str(), oname))
119             {                
120                 reT[m].push_back(toolTag[l]);
121                 continue;
122             }
123         }        
124     }
125     
126     std::vector<string> zm26;
127     char zm[132];
128     for (int i = 0; i < 27; i++)
129     {
130         sprintf(zm, "%c", 64 + i);
131         zm26.push_back(zm);
132     }
133 
134     for (size_t n = 0; n < reT.size(); n++)
135     {
136         if ((int)reT[n].size() > 1)
137         {
138             for (size_t o = 1; o < reT[n].size(); o++)
139             {
140                 char name2[256];
141                 UF_OBJ_ask_name(reT[n][o], name2);
142                 strcat(name2, zm26[o].c_str());
143                 UF_OBJ_set_name(reT[n][o], name2);
144                 print(name2);
145             }
146         }
147     }    
148 
149     UF_terminate();

posted @ 2020-07-04 20:29  老婆饼里有老婆  阅读(343)  评论(0编辑  收藏  举报