zoukankan      html  css  js  c++  java
  • NX二次开发-算法篇-vector函数排序(例子:遍历所有点并排序)

     1     NX9+VS2012
     2 
     3     #include <uf.h>
     4     #include <uf_ui.h>
     5     #include <uf_curve.h>
     6     #include <uf_obj.h>
     7     #include <uf_part.h>
     8     #include <vector>
     9     #include <algorithm>
    10     
    11     using namespace std;
    12 
    13 
    14     UF_initialize();
    15 
    16     //遍历前有一点需要注意,首先我们的默认基准坐标系上就有一个点,也就是原点0,0,0。
    17     //还有一个要注意的地方是我们在创建点的时候,如果用创建点命令创建一个空间的点,这个是算一个点。
    18     //如果是用草图去创建点的话,这个是两个点,因为默认草图坐标系原点处就有一个点了。
    19 
    20     vector<double> MyPointZ;
    21     //遍历当前显示部件的所有点
    22     tag_t ObjectTag = NULL_TAG;
    23     UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_point_type, &ObjectTag);
    24     while (ObjectTag != NULL_TAG)
    25     {
    26 
    27         UF_OBJ_set_color(ObjectTag, 186);//设置所有点为红色
    28 
    29         //获取点的XYZ坐标
    30         double PointCoords[3];
    31         UF_CURVE_ask_point_data(ObjectTag, PointCoords);
    32 
    33         MyPointZ.push_back(PointCoords[2]);//添加坐标点Z值到vector
    34     
    35         UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_point_type, &ObjectTag);
    36     }
    37 
    38     //vector排序去重
    39     sort( MyPointZ.begin(), MyPointZ.end());//排序
    40     MyPointZ.erase(unique(MyPointZ.begin(), MyPointZ.end()), MyPointZ.end());//去重
    41 
    42     //打印
    43     for (int i = 0; i < MyPointZ.size(); i++)
    44     {
    45         char msg[256];
    46         sprintf_s(msg, "%f
    ", MyPointZ[i]);
    47         UF_UI_open_listing_window();
    48         UF_UI_write_listing_window(msg);
    49     }
    50 
    51     UF_terminate();

  • 相关阅读:
    dotnet 新项目格式与对应框架预定义的宏
    dotnet 线程静态字段
    dotnet 线程静态字段
    dotnet 通过 WMI 拿到显卡信息
    dotnet 通过 WMI 拿到显卡信息
    dotnet 通过 WMI 获取指定进程的输入命令行
    dotnet 通过 WMI 获取指定进程的输入命令行
    dotnet 通过 WMI 获取系统信息
    dotnet 通过 WMI 获取系统信息
    PHP show_source() 函数
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/10957443.html
Copyright © 2011-2022 走看看