NX二次开发

在GC工具里面是有一个重命名装配组件的命令的,除了这个外,好像没看到NX里还有其他可以重命名装配组件的命令,本来以为在UFUN ASSEM装配的头文件里会有更改装配部件名字的函数,但是没有找到,可能没有。本来以为UF_ASSEM_rename_instance这个可以,后来发现还不行,这个只能改右键属性名字。

但是我找到了替换组件的函数,我觉得这个是可以实现功能的。后来我按照自己想到的思路,对照着GC工具就写了一下。

我的思路是这样的:一个单选对话框->选择装配组件->得到tag->由tag得到装配组件的part名字->把名字显示到一个字符串窗口->用户更改名字->copy本地那个装配组件.prt文件->把新名字命名给copy后的那个.prt文件->

然后用替换组件函数替换copy后的那个.prt文件->最后在把copy前那个旧的.prt文件删掉

1 1 //RenameComponent 2 2 3 3 // Mandatory UF Includes 4 4 #include <uf.h> 5 5 #include <uf_object_types.h> 6 6 7 7 // Internal Includes 8 8 #include <NXOpen/ListingWindow.hxx> 9 9 #include <NXOpen/NXMessageBox.hxx> 10 10 #include <NXOpen/UI.hxx> 11 11 12 12 // Internal+External Includes 13 13 #include <NXOpen/Annotations.hxx> 14 14 #include <NXOpen/Assemblies_Component.hxx> 15 15 #include <NXOpen/Assemblies_ComponentAssembly.hxx> 16 16 #include <NXOpen/Body.hxx> 17 17 #include <NXOpen/BodyCollection.hxx> 18 18 #include <NXOpen/Face.hxx> 19 19 #include <NXOpen/Line.hxx> 20 20 #include <NXOpen/NXException.hxx> 21 21 #include <NXOpen/NXObject.hxx> 22 22 #include <NXOpen/Part.hxx> 23 23 #include <NXOpen/PartCollection.hxx> 24 24 #include <NXOpen/Session.hxx> 25 25 26 26 #include <uf.h> 27 27 #include <uf_ui.h> 28 28 #include <uf_modl.h> 29 29 #include <uf_part.h> 30 30 #include <uf_curve.h> 31 31 #include <uf_assem.h> 32 32 #include <uf_obj.h> 33 33 #include <windows.h> 34 34 #include <stdarg.h> 35 35 #include <strstream> 36 36 #include <iostream> 37 37 #include <string> 38 38 #include <io.h> 39 39 40 40 // Std C++ Includes 41 41 #include <iostream> 42 42 #include <sstream> 43 43 44 44 using namespace NXOpen; 45 45 using std::string; 46 46 using std::exception; 47 47 using std::stringstream; 48 48 using std::endl; 49 49 using std::cout; 50 50 using std::cerr; 51 51 52 52 53 53 //------------------------------------------------------------------------------ 54 54 // NXOpen c++ test class 55 55 //------------------------------------------------------------------------------ 56 56 class MyClass 57 57 { 58 58 // class members 59 59 public: 60 60 static Session *theSession; 61 61 static UI *theUI; 62 62 63 63 MyClass(); 64 64 ~MyClass(); 65 65 66 66 void do_it(); 67 67 void print(const NXString &); 68 68 void print(const string &); 69 69 void print(const char*); 70 70 71 71 int DelectValue;//对话框返回值,决定是否删除原组件 72 72 string NameOrPath(const char* Path, int Type);//返回.prt文件名字和所在文件夹路径 73 73 void filesearch(string path, int layer);//遍历文件夹所有.prt文件 74 74 char part_name[MAX_FSPEC_BUFSIZE];//当前显示部件.prt文件所在路径 75 75 char str[133];//字符串输入对话框值 76 76 77 77 private: 78 78 Part *workPart, *displayPart; 79 79 NXMessageBox *mb; 80 80 ListingWindow *lw; 81 81 LogFile *lf; 82 82 }; 83 83 84 84 //------------------------------------------------------------------------------ 85 85 // Initialize static variables 86 86 //------------------------------------------------------------------------------ 87 87 Session *(MyClass::theSession) = NULL; 88 88 UI *(MyClass::theUI) = NULL; 89 89 90 90 //------------------------------------------------------------------------------ 91 91 // Constructor 92 92 //------------------------------------------------------------------------------ 93 93 MyClass::MyClass() 94 94 { 95 95 96 96 // Initialize the NX Open C++ API environment 97 97 MyClass::theSession = NXOpen::Session::GetSession(); 98 98 MyClass::theUI = UI::GetUI(); 99 99 mb = theUI->NXMessageBox(); 100100 lw = theSession->ListingWindow(); 101101 lf = theSession->LogFile(); 102102 103103 workPart = theSession->Parts()->Work(); 104104 displayPart = theSession->Parts()->Display(); 105105 106106 } 107107 108108 //------------------------------------------------------------------------------ 109109 // Destructor 110110 //------------------------------------------------------------------------------ 111111 MyClass::~MyClass() 112112 { 113113 } 114114 115115 //------------------------------------------------------------------------------ 116116 // Print string to listing window or stdout 117117 //------------------------------------------------------------------------------ 118118 void MyClass::print(const NXString &msg) 119119 { 120120 if(! lw->IsOpen() ) lw->Open(); 121121 lw->WriteLine(msg); 122122 } 123123 void MyClass::print(const string &msg) 124124 { 125125 if(! lw->IsOpen() ) lw->Open(); 126126 lw->WriteLine(msg); 127127 } 128128 void MyClass::print(const char * msg) 129129 { 130130 if(! lw->IsOpen() ) lw->Open(); 131131 lw->WriteLine(msg); 132132 } 133133 134134 135135 136136 static int select_filter_proc_fn(tag_t object, int type[3], void* user_data, UF_UI_selection_p_t select) 137137 { 138138 if (object == NULL) 139139 { 140140 return UF_UI_SEL_REJECT; 141141 } 142142 else 143143 { 144144 return UF_UI_SEL_ACCEPT; 145145 } 146146 } 147147 148148 static int init_proc(UF_UI_selection_p_t select, void* user_data) 149149 { 150150 int num_triples = 1;//可选类型的数量 151151 UF_UI_mask_t mask_triples[] = 152152 { UF_component_type, UF_UI_SEL_NOT_A_FEATURE, 153153 };//可选对象类型 154154 UF_UI_set_sel_mask(select, UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, num_triples, mask_triples); 155155 if ((UF_UI_set_sel_procs(select, select_filter_proc_fn, NULL, user_data)) == 0) 156156 { 157157 return UF_UI_SEL_SUCCESS; 158158 } 159159 else 160160 { 161161 return UF_UI_SEL_FAILURE; 162162 } 163163 } 164164 165165 166166 string MyClass::NameOrPath(const char* Path, int Type) 167167 { 168168 //反向找位置,分割字符串(只读取文件夹路径) 169169 string strPath = Path; 170170 string strDir; 171171 int nPos = strPath.find_last_of('\\'); 172172 if (string::npos != nPos) 173173 { 174174 strDir = strPath.substr(0, nPos); 175175 } 176176 177177 //分割字符串(只读取part名字+后缀) 178178 //方法2 179179 int pos = strPath.find_last_of('\\'); 180180 string s1(strPath.substr(pos + 1)); 181181 182182 //分割字符串(只读取part名) 183183 string PartName(s1.substr(0, s1.find(".prt"))); 184184 185185 if (Type == 1) 186186 { 187187 return PartName;//返回名字 188188 } 189189 else if (Type == 2) 190190 { 191191 return strDir;//返回文件夹路径 192192 } 193193 } 194194 195195 196196 void MyClass::filesearch(string path, int layer) 197197 { 198198 char msg[256] = ""; 199199 char msgg[256] = ""; 200200 struct _finddata_t filefind; 201201 string f; 202202 string curr = path + "\\*.*"; 203203 int done = 0, i, handle; 204204 if ((handle = _findfirst(curr.c_str(), &filefind)) != -1) 205205 { 206206 while (!(done = _findnext(handle, &filefind))) 207207 { 208208 if (strcmp(filefind.name, "..") == 0) 209209 continue; 210210 for (i = 0; i < layer; i++) 211211 printf("\t"); 212212 if ((_A_SUBDIR == filefind.attrib)) // 是目录 213213 { 214214 curr = path + "\\" + filefind.name; 215215 sprintf(msg, "%s\n", curr.c_str()); 216216 //UF_UI_write_listing_window(msg); 217217 filesearch(curr, layer + 1); // 递归遍历子目录 218218 } 219219 else // 是文件 220220 { 221221 222222 sprintf(msg, "%s", filefind.name); 223223 if (strlen(msg) > 4) 224224 { 225225 strncpy(msgg, msg + strlen(msg) - 4, 4); 226226 if (strcmp(msgg, ".prt") == 0) // 文件格式 227227 { 228228 f = path + "\\" + filefind.name; 229229 sprintf(msg, "%s\n", f.c_str()); 230230 //UF_UI_write_listing_window(msg); 231231 232232 //分割字符串(只读取part名) 233233 string PartName = NameOrPath(f.c_str(), 1); 234234 string PartPath = NameOrPath(f.c_str(), 2); 235235 236236 //分割字符串(只读取part名) 237237 string PartName1 = NameOrPath(part_name, 1); 238238 239239 //找到名字相同的.prt文件 240240 if (PartName == PartName1) 241241 { 242242 //转换 243243 char NewName1[256]; 244244 sprintf(NewName1, "\\%s.prt", str); 245245 string NewName2 = NewName1; 246246 //字符串拼接 247247 string NewName = PartPath + NewName2; 248248 249249 //copy出一个新的.prt文件 250250 CopyFile(f.c_str(), NewName.c_str(), FALSE); 251251 252252 //由名字得到装配部件实例的TAG 253253 tag_t instanceTAG = UF_ASSEM_ask_instance_of_name(UF_PART_ask_display_part(), part_name); 254254 255255 //重新命名装配部件的part名称 256256 UF_PART_load_status_t load_status; 257257 UF_ASSEM_use_alternate(&instanceTAG, NewName.c_str(), str, str, &load_status); 258258 259259 //由对话框值判断是否删除原组件 260260 if (DelectValue == 5) 261261 { 262262 //删除旧名字的.prt文件 263263 DeleteFile(f.c_str()); 264264 } 265265 266266 267267 } 268268 269269 } 270270 } 271271 } 272272 } 273273 _findclose(handle); 274274 } 275275 } 276276 277277 278278 //------------------------------------------------------------------------------ 279279 // Do something 280280 //------------------------------------------------------------------------------ 281281 void MyClass::do_it() 282282 { 283283 284284 // TODO: add your code here 285285 286286 UF_initialize(); 287287 288288 //单对象选择对话框 289289 char sCue[] = "单对象选择对话框"; 290290 char sTitle[] = "选择一个装配组件"; 291291 int iScope = UF_UI_SEL_SCOPE_NO_CHANGE; 292292 int iResponse; 293293 tag_t tView; 294294 double adCursor[3]; 295295 tag_t ComponentTag = NULL_TAG;//单选控件获得的tag 296296 UF_UI_select_with_single_dialog(sCue, sTitle, iScope, init_proc, NULL, &iResponse, &ComponentTag, adCursor, &tView); 297297 298298 //获取装配部件的part名称 299299 char refset_name[UF_OBJ_NAME_BUFSIZE]; 300300 char instance_name[UF_CFI_MAX_FILE_NAME_BUFSIZE]; 301301 double origin[3]; 302302 double csys_matrix[9]; 303303 double transform[4][4]; 304304 UF_ASSEM_ask_component_data(ComponentTag, part_name, refset_name, instance_name, origin, csys_matrix, transform); 305305 306306 //输入字符串控件 307307 char * cue = "输入框"; 308308 //转换 309309 char str1[133]; 310310 sprintf(str1, "%s", part_name); 311311 //分割字符串(只读取part名) 312312 string PartName1 = NameOrPath(str1, 1); 313313 sprintf(str, "%s", PartName1.c_str()); 314314 int length = 0; 315315 uc1600(cue, str, &length); 316316 317317 //弹出对话框 318318 char sPromptStr1[] = "单选菜单对话框"; 319319 int iDefault1 = 0; 320320 char asOptions1[][38] = { "删除原组件", "保留原组件" }; 321321 int iNumOfOptions1 = 2; 322322 DelectValue = uc1603(sPromptStr1, iDefault1, asOptions1, iNumOfOptions1); 323323 324324 //获得当前显示部件.prt文件所在路径 325325 char part_fspec[MAX_FSPEC_BUFSIZE]; 326326 UF_PART_ask_part_name(UF_PART_ask_display_part(), part_fspec); 327327 328328 //获取文件夹路径 329329 string strDir = NameOrPath(part_fspec, 2); 330330 331331 //遍历文件夹 332332 filesearch(strDir, 0); 333333 334334 UF_terminate(); 335335 336336 } 337337 338338 //------------------------------------------------------------------------------ 339339 // Entry point(s) for unmanaged internal NXOpen C/C++ programs 340340 //------------------------------------------------------------------------------ 341341 // Explicit Execution 342342 extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen ) 343343 { 344344 try 345345 { 346346 // Create NXOpen C++ class instance 347347 MyClass *theMyClass; 348348 theMyClass = new MyClass(); 349349 theMyClass->do_it(); 350350 delete theMyClass; 351351 } 352352 catch (const NXException& e1) 353353 { 354354 UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message()); 355355 } 356356 catch (const exception& e2) 357357 { 358358 UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what()); 359359 } 360360 catch (...) 361361 { 362362 UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception."); 363363 } 364364 } 365365 366366 367367 //------------------------------------------------------------------------------ 368368 // Unload Handler 369369 //------------------------------------------------------------------------------ 370370 extern "C" DllExport int ufusr_ask_unload() 371371 { 372372 return (int)NXOpen::Session::LibraryUnloadOptionImmediately; 373373 } 374374 375375 Caesar卢尚宇 376376 2019812

补充:

今天又写了第二种方法(2019年8月13日)

1 1 //NX9_NXOpenCPP_Wizard2 2 2 3 3 // Mandatory UF Includes 4 4 #include <uf.h> 5 5 #include <uf_object_types.h> 6 6 7 7 // Internal Includes 8 8 #include <NXOpen/ListingWindow.hxx> 9 9 #include <NXOpen/NXMessageBox.hxx> 10 10 #include <NXOpen/UI.hxx> 11 11 12 12 // Internal+External Includes 13 13 #include <NXOpen/Annotations.hxx> 14 14 #include <NXOpen/Assemblies_Component.hxx> 15 15 #include <NXOpen/Assemblies_ComponentAssembly.hxx> 16 16 #include <NXOpen/Body.hxx> 17 17 #include <NXOpen/BodyCollection.hxx> 18 18 #include <NXOpen/Face.hxx> 19 19 #include <NXOpen/Line.hxx> 20 20 #include <NXOpen/NXException.hxx> 21 21 #include <NXOpen/NXObject.hxx> 22 22 #include <NXOpen/Part.hxx> 23 23 #include <NXOpen/PartCollection.hxx> 24 24 #include <NXOpen/Session.hxx> 25 25 26 26 27 27 #include <uf.h> 28 28 #include <uf_assem.h> 29 29 #include <uf_obj.h> 30 30 #include <uf_part.h> 31 31 #include <uf_modl.h> 32 32 #include <uf_ui.h> 33 33 #include <windows.h> 34 34 #include <uf_disp.h> 35 35 36 36 37 37 // Std C++ Includes 38 38 #include <iostream> 39 39 #include <sstream> 40 40 41 41 using namespace NXOpen; 42 42 using std::string; 43 43 using std::exception; 44 44 using std::stringstream; 45 45 using std::endl; 46 46 using std::cout; 47 47 using std::cerr; 48 48 49 49 50 50 //------------------------------------------------------------------------------ 51 51 // NXOpen c++ test class 52 52 //------------------------------------------------------------------------------ 53 53 class MyClass 54 54 { 55 55 // class members 56 56 public: 57 57 static Session *theSession; 58 58 static UI *theUI; 59 59 60 60 MyClass(); 61 61 ~MyClass(); 62 62 63 63 void do_it(); 64 64 void print(const NXString &); 65 65 void print(const string &); 66 66 void print(const char*); 67 67 68 68 //单选 69 69 int DelectValue;//对话框返回值,决定是否删除原组件 70 70 string NameOrPath(const char* Path, int Type);//返回.prt文件名字和所在文件夹路径 71 71 72 72 private: 73 73 Part *workPart, *displayPart; 74 74 NXMessageBox *mb; 75 75 ListingWindow *lw; 76 76 LogFile *lf; 77 77 }; 78 78 79 79 //------------------------------------------------------------------------------ 80 80 // Initialize static variables 81 81 //------------------------------------------------------------------------------ 82 82 Session *(MyClass::theSession) = NULL; 83 83 UI *(MyClass::theUI) = NULL; 84 84 85 85 //------------------------------------------------------------------------------ 86 86 // Constructor 87 87 //------------------------------------------------------------------------------ 88 88 MyClass::MyClass() 89 89 { 90 90 91 91 // Initialize the NX Open C++ API environment 92 92 MyClass::theSession = NXOpen::Session::GetSession(); 93 93 MyClass::theUI = UI::GetUI(); 94 94 mb = theUI->NXMessageBox(); 95 95 lw = theSession->ListingWindow(); 96 96 lf = theSession->LogFile(); 97 97 98 98 workPart = theSession->Parts()->Work(); 99 99 displayPart = theSession->Parts()->Display(); 100100 101101 } 102102 103103 //------------------------------------------------------------------------------ 104104 // Destructor 105105 //------------------------------------------------------------------------------ 106106 MyClass::~MyClass() 107107 { 108108 } 109109 110110 //------------------------------------------------------------------------------ 111111 // Print string to listing window or stdout 112112 //------------------------------------------------------------------------------ 113113 void MyClass::print(const NXString &msg) 114114 { 115115 if(! lw->IsOpen() ) lw->Open(); 116116 lw->WriteLine(msg); 117117 } 118118 void MyClass::print(const string &msg) 119119 { 120120 if(! lw->IsOpen() ) lw->Open(); 121121 lw->WriteLine(msg); 122122 } 123123 void MyClass::print(const char * msg) 124124 { 125125 if(! lw->IsOpen() ) lw->Open(); 126126 lw->WriteLine(msg); 127127 } 128128 129129 130130 131131 static int select_filter_proc_fn(tag_t object, int type[3], void* user_data, UF_UI_selection_p_t select) 132132 { 133133 if (object == NULL) 134134 { 135135 return UF_UI_SEL_REJECT; 136136 } 137137 else 138138 { 139139 return UF_UI_SEL_ACCEPT; 140140 } 141141 } 142142 143143 static int init_proc(UF_UI_selection_p_t select, void* user_data) 144144 { 145145 int num_triples = 1;//可选类型的数量 146146 UF_UI_mask_t mask_triples[] = 147147 { UF_component_type, UF_UI_SEL_NOT_A_FEATURE, 148148 };//可选对象类型 149149 UF_UI_set_sel_mask(select, UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, num_triples, mask_triples); 150150 if ((UF_UI_set_sel_procs(select, select_filter_proc_fn, NULL, user_data)) == 0) 151151 { 152152 return UF_UI_SEL_SUCCESS; 153153 } 154154 else 155155 { 156156 return UF_UI_SEL_FAILURE; 157157 } 158158 } 159159 160160 string MyClass::NameOrPath(const char* Path, int Type) 161161 { 162162 //反向找位置,分割字符串(只读取文件夹路径) 163163 string strPath = Path; 164164 string strDir; 165165 int nPos = strPath.find_last_of('\\'); 166166 if (string::npos != nPos) 167167 { 168168 strDir = strPath.substr(0, nPos); 169169 } 170170 171171 //分割字符串(只读取part名字+后缀) 172172 //方法2 173173 int pos = strPath.find_last_of('\\'); 174174 string s1(strPath.substr(pos + 1)); 175175 176176 //分割字符串(只读取part名) 177177 string PartName(s1.substr(0, s1.find(".prt"))); 178178 179179 if (Type == 1) 180180 { 181181 return PartName;//返回名字 182182 } 183183 else if (Type == 2) 184184 { 185185 return strDir;//返回文件夹路径 186186 } 187187 } 188188 189189 //------------------------------------------------------------------------------ 190190 // Do something 191191 //------------------------------------------------------------------------------ 192192 void MyClass::do_it() 193193 { 194194 195195 // TODO: add your code here 196196 197197 UF_initialize(); 198198 199199 //单对象选择对话框 200200 char sCue[] = "单对象选择对话框"; 201201 char sTitle[] = "选择一个装配组件"; 202202 int iScope = UF_UI_SEL_SCOPE_NO_CHANGE; 203203 int iResponse; 204204 tag_t tView; 205205 double adCursor[3]; 206206 tag_t ComponentTag = NULL_TAG;//单选控件获得的tag 207207 UF_UI_select_with_single_dialog(sCue, sTitle, iScope, init_proc, NULL, &iResponse, &ComponentTag, adCursor, &tView); 208208 209209 //获取装配部件的part名称 210210 char part_name[MAX_FSPEC_BUFSIZE];//当前显示部件.prt文件所在路径 211211 char refset_name[UF_OBJ_NAME_BUFSIZE]; 212212 char instance_name[UF_CFI_MAX_FILE_NAME_BUFSIZE]; 213213 double origin[3]; 214214 double csys_matrix[9]; 215215 double transform[4][4]; 216216 UF_ASSEM_ask_component_data(ComponentTag, part_name, refset_name, instance_name, origin, csys_matrix, transform); 217217 218218 //输入字符串控件 219219 char * cue = "输入框"; 220220 //转换 221221 char str1[133]; 222222 sprintf(str1, "%s", part_name); 223223 //分割字符串(只读取part名) 224224 string PartName1 = NameOrPath(str1, 1); 225225 char str[133];//字符串输入对话框值 226226 sprintf(str, "%s", PartName1.c_str()); 227227 int length = 0; 228228 uc1600(cue, str, &length); 229229 230230 //弹出对话框 231231 char sPromptStr1[] = "单选菜单对话框"; 232232 int iDefault1 = 0; 233233 char asOptions1[][38] = { "删除原组件", "保留原组件" }; 234234 int iNumOfOptions1 = 2; 235235 DelectValue = uc1603(sPromptStr1, iDefault1, asOptions1, iNumOfOptions1); 236236 237237 //返回原型标识 238238 tag_t ComponentPart = UF_ASSEM_ask_prototype_of_occ(ComponentTag); 239239 240240 //设置为工作部件 241241 UF_ASSEM_set_work_part(ComponentPart); 242242 243243 //获得当前工作部件.prt文件所在路径 244244 char part_fspec1[MAX_FSPEC_BUFSIZE]; 245245 UF_PART_ask_part_name(UF_ASSEM_ask_work_part(), part_fspec1); 246246 247247 //重命名实例名称 248248 UF_PART_rename(ComponentPart, str); 249249 250250 //获得当前显示部件.prt文件所在路径 251251 char part_fspec[MAX_FSPEC_BUFSIZE]; 252252 UF_PART_ask_part_name(UF_PART_ask_display_part(), part_fspec); 253253 254254 //获取文件夹路径 255255 string strDir = NameOrPath(part_fspec, 2); 256256 257257 //转换 258258 char msg[256]; 259259 sprintf_s(msg, "\\%s.prt", str); 260260 string strDir1 = msg; 261261 262262 //字符串拼接 263263 string strDir2 = strDir + strDir1; 264264 265265 //另存为改名后的.prt 266266 UF_PART_save_as(strDir2.c_str()); 267267 268268 //把显示部件设置为工作部件 269269 UF_ASSEM_set_work_part(UF_PART_ask_display_part()); 270270 271271 //部件清理,移除高亮 272272 NXOpen::PartCleanup *partCleanup1; 273273 partCleanup1 = theSession->NewPartCleanup(); 274274 partCleanup1->SetTurnOffHighlighting(true); 275275 partCleanup1->DoCleanup(); 276276 277277 //删除旧的.prt文件 278278 if (DelectValue == 5) 279279 { 280280 DeleteFile(part_fspec1); 281281 } 282282 283283 UF_terminate(); 284284 } 285285 286286 //------------------------------------------------------------------------------ 287287 // Entry point(s) for unmanaged internal NXOpen C/C++ programs 288288 //------------------------------------------------------------------------------ 289289 // Explicit Execution 290290 extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen ) 291291 { 292292 try 293293 { 294294 // Create NXOpen C++ class instance 295295 MyClass *theMyClass; 296296 theMyClass = new MyClass(); 297297 theMyClass->do_it(); 298298 delete theMyClass; 299299 } 300300 catch (const NXException& e1) 301301 { 302302 UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message()); 303303 } 304304 catch (const exception& e2) 305305 { 306306 UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what()); 307307 } 308308 catch (...) 309309 { 310310 UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception."); 311311 } 312312 } 313313 314314 315315 //------------------------------------------------------------------------------ 316316 // Unload Handler 317317 //------------------------------------------------------------------------------ 318318 extern "C" DllExport int ufusr_ask_unload() 319319 { 320320 return (int)NXOpen::Session::LibraryUnloadOptionImmediately; 321321 } 322322 323323 324324 Caesar卢尚宇 325325 2019813

补充2019年11月18日

今天有网友合工大-wzl给我留言,纠正了一个bug,在这个例子中,这个函数tag_t instanceTAG = UF_ASSEM_ask_instance_of_name(UF_PART_ask_display_part(), part_name);

里面的这个输入参数,part_name,不应该是part的名字,应该是装配部件的实例名称instance_name。这个地方是我的一个疏忽,因为默认情况下应该part名字和实例名字是一个名字。

感谢网友纠正的错误。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )