• NX二次开发-获取当前part所在路径UF_PART_ask_part_name


     1 #include <uf.h>
     2 #include <uf_ui.h>
     3 #include <uf_part.h>
     4 #include <atlstr.h>
     5 #include <iostream>
     6 #include <sstream>
     7 using namespace std;
     8 
     9 
    10 
    11 
    12 
    13 UF_initialize();
    14 
    15 UF_UI_open_listing_window();
    16 
    17 //获取当前part所在路径
    18 char part_fspec[MAX_FSPEC_BUFSIZE + 1];
    19 UF_PART_ask_part_name(UF_PART_ask_display_part(), part_fspec);
    20 
    21 //反向找位置,分割字符串(只读取文件夹路径)
    22 string strPath = part_fspec;
    23 string strDir;
    24 int nPos = strPath.find_last_of('\');
    25 if (string::npos != nPos)
    26 {
    27     strDir = strPath.substr(0, nPos);
    28 }
    29 
    30 char msg[256];
    31 sprintf_s(msg, "当前part所在文件夹路径为:%s
    ", strDir.c_str());
    32 UF_UI_write_listing_window(msg);
    33 
    34 //分割字符串(只读取part名字+后缀)
    35 //方法1
    36 char* p = strrchr(part_fspec, '\');
    37 string s(p + 1);
    38 
    39 sprintf_s(msg, "当前part名+后缀名为:%s
    ", s.c_str());
    40 UF_UI_write_listing_window(msg);
    41 
    42 //方法2
    43 int pos = strPath.find_last_of('\');
    44 string s1(strPath.substr(pos + 1));
    45 
    46 sprintf_s(msg, "当前part名+后缀名为:%s
    ", s1.c_str());
    47 UF_UI_write_listing_window(msg);
    48 
    49 //分割字符串(只读取part名)
    50 string s2(s1.substr(0, s1.find(".")));
    51 
    52 sprintf_s(msg, "当前part名为:%s
    ", s2.c_str());
    53 UF_UI_write_listing_window(msg);
    54 
    55 //分割字符串(只读取后缀名)
    56 string s3(s1.substr(s1.find(".")+1, s1.find(" ")));
    57 
    58 sprintf_s(msg, "当前后缀名为:%s
    ", s3.c_str());
    59 UF_UI_write_listing_window(msg);
    60 
    61 
    62 UF_terminate();
    63 
    64 Caesar卢尚宇
    65 2019年7月7日

  • 相关阅读:
    2019年春季第四周作业
    第三周作业
    第二周作业
    最大值及其下标
    查找整数
    PTA3
    币值转换
    三位老师
    自我介绍
    poj 3278 Catch That Cow(bfs)
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/11147840.html
Copyright © 2020-2023  润新知