1 UF_initialize();
2 char sCue[] = "象選擇對話框";
3 char sTitle[] = "象選擇對話框";
4 int iScope = UF_UI_SEL_SCOPE_NO_CHANGE;
5 int iResponse;
6 tag_t *tObject;
7 int count = 0;
8 UF_UI_select_with_class_dialog(sCue, sTitle, iScope, NULL, NULL, &iResponse, &count, &tObject);
9 if (count)
10 {
11 for (size_t i=0;i<count;i++)
12 {
13 UF_DISP_set_highlight(tObject[i], 0);
14 }
15
16 tag_t *object_tag = new tag_t[count];
17 for (size_t i = 0; i < count; i++)
18 {
19 object_tag[i] = tObject[i];
20 }
21
22 char part_fspec[MAX_FSPEC_BUFSIZE + 1];
23 UF_PART_ask_part_name(UF_PART_ask_display_part(), part_fspec);
24
25 //反向找位置,分割字符串(只讀取文件夾路徑)
26 string strPath = part_fspec;
27 string strDir;
28 int nPos = strPath.find_last_of('\\');
29 if (string::npos != nPos)
30 {
31 strDir = strPath.substr(0, nPos);
32 }
33 //print(strDir);
34 //文件名
35 int pos = strPath.find_last_of('\\');
36 string file_name2(strPath.substr(pos + 1));
37 string file_name(file_name2.substr(0, file_name2.find(".")));
38 file_name.append("導出文件");
39 //print(file_name);
40
41 //文件選擇對話框
42 char sPromptStr[] = "部件選擇對話框";//快捷信息
43 char sTitleStr[] = "部件選擇對話框";//對話框標題
44 char sFilterStr[] = ".prt";//文件過濾器,即只處理某一種類型文件
45 char sDefaultStr[MAX_FSPEC_BUFSIZE];//默認文件名輸出
46 //sprintf(sDefaultStr, "%s", file_name.c_str());
47 sprintf_s(sDefaultStr, 256, "%s\\%s", strDir.c_str(), file_name);
48 char sFilePath[256];//用戶選擇的文件全路徑
49 int iRespones = 0;//函數返回值
50 UF_CALL(UF_UI_create_filebox(sPromptStr, sTitleStr, sFilterStr, sDefaultStr, sFilePath, &iRespones));
51 if (iRespones == UF_UI_OK)
52 {
53 UF_CALL(UF_PART_export(sFilePath, count, object_tag));
54 //打開part
55 char file_n[MAX_FSPEC_BUFSIZE];
56 string ss = sFilePath;
57 ss.append(".prt");
58 sprintf(file_n, "%s", ss.c_str());
59 //print(file_n);
60
61 tag_t partTag = NULL_TAG;
62 UF_PART_load_status_t error_status;
63 UF_CALL(UF_PART_open(file_n, &partTag, &error_status));
64 //釋放
65 UF_PART_free_load_status(&error_status);
66 }
67 }
68 UF_terminate();