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();
原文地址:https://www.cnblogs.com/nxopen2018/p/10957433.html
时间: 2024-10-10 18:30:29