• NX二次开发-算法篇-创建最大边界包容盒


     1     NX9+VS2012
     2     
     3     #include <uf.h>
     4     #include <uf_obj.h>
     5     #include <uf_modl.h>
     6     #include <uf_part.h>
     7 
     8     UF_initialize();
     9 
    10     //遍历当前显示部件所有体
    11     std::vector<tag_t> SolidVector;
    12     tag_t ObjectTag = NULL_TAG;
    13     int Type, SubType, Body_Type;
    14     int Count = 0;
    15     char msg[256];
    16     UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &ObjectTag);
    17     while (ObjectTag != NULL_TAG)
    18     {
    19         UF_OBJ_ask_type_and_subtype(ObjectTag, &Type, &SubType);
    20         if (SubType == UF_solid_body_subtype)
    21         {
    22             UF_MODL_ask_body_type(ObjectTag, &Body_Type);
    23             if (Body_Type == UF_MODL_SOLID_BODY)
    24             {
    25                 UF_OBJ_set_color(ObjectTag, 186);
    26                 SolidVector.push_back(ObjectTag);
    27                 Count++;
    28             }
    29         }
    30         UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &ObjectTag);
    31     }
    32 
    33     //求所有体的最大边界
    34     double MaxBox[6] = {10000, 10000, 10000, -10000, -10000, -10000};
    35     for (int i = 0; i < Count; i++)
    36     {
    37         double Box[6];
    38         UF_MODL_ask_bounding_box(SolidVector[i], Box);
    39         MaxBox[0] = MaxBox[0] < Box[0]? MaxBox[0]:Box[0];
    40         MaxBox[1] = MaxBox[1] < Box[1]? MaxBox[1]:Box[1];
    41         MaxBox[2] = MaxBox[2] < Box[2]? MaxBox[2]:Box[2];
    42         MaxBox[3] = MaxBox[3] > Box[3]? MaxBox[3]:Box[3];
    43         MaxBox[4] = MaxBox[4] > Box[4]? MaxBox[4]:Box[4];
    44         MaxBox[5] = MaxBox[5] > Box[5]? MaxBox[5]:Box[5];
    45     }
    46 
    47     //转换
    48     char Length[200], Width[200], Height[200];
    49     sprintf(Length, "%f", MaxBox[3] - MaxBox[0]);
    50     sprintf(Width, "%f", MaxBox[4] - MaxBox[1]);
    51     sprintf(Height, "%f", MaxBox[5] - MaxBox[2]);
    52 
    53     char* Len[3];
    54     Len[0] = Length;
    55     Len[1] = Width;
    56     Len[2] = Height;
    57 
    58     //创建块
    59     double Ori[3] = {MaxBox[0], MaxBox[1], MaxBox[2]};
    60     tag_t BlkTag = NULL_TAG;
    61     UF_MODL_create_block1(UF_NULLSIGN, Ori, Len, &BlkTag);
    62 
    63     //特征找体
    64     tag_t BodyTag = NULL_TAG;
    65     UF_MODL_ask_feat_body (BlkTag,&BodyTag);        
    66 
    67     //设置透明度
    68     UF_OBJ_set_translucency(BodyTag, 50);
    69     
    70     UF_terminate();

  • 相关阅读:
    Socket send函数和recv函数详解
    isdigit()函数用法
    C语言的那些小秘密之字节对齐
    The Five Best Linux BitTorrent Clients
    怎么计算网站高峰期并发量和所需的带宽?
    软件需求包括3个不同的层次 业务需求、用户需求和功能需求
    右键删除选中的行总提示rowIndex
    SQL Server[转]SQL Server中临时表与表变量的区别
    面向对象的软件工程应用浅研
    OO开发思想:面向对象的开发方法(Object oriented,OO)
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/10957433.html
Copyright © 2020-2023  润新知