标签:pre htm style sort int ops mat def orm
1 #include <uf.h> 2 #include <uf_ui.h> 3 #include <uf_obj.h> 4 #include <uf_modl_primitives.h> 5 #include <uf_csys.h> 6 #include <uf_layer.h> 7 #include <uf_object_types.h> 8 #include <uf_modl_utilities.h> 9 #include <uf_part.h> 10 #include <uf_modl.h> 11 #include <uf_group.h> 12 #include <uf_ui.h> 13 #include <uf_layer.h> 14 #include <uf_obj.h> 15 #include <uf_object_types.h> 16 #include <uf_defs.h> 17 #include <uf_evalsf.h> 18 #include <vector> 19 #include <algorithm> 20 #include <NXOpen/ugmath.hxx> 21 #include <NXOpen/Body.hxx> 22 #include <NXOpen/NXObjectManager.hxx> 23 #include <NXOpen/Face.hxx> 24 using namespace std; 25 using namespace NXOpen;
1 vector<int> color_num; 2 vector<double> heigth; 3 vector<tag_t> face1; 4 int sss[20] = { 11,18,32,69,71,78,87,90,93,103,108,136,141,145,160,163,176,190,191,205 }; 5 color_num.insert(color_num.begin(), sss, sss + 20); 6 sort(color_num.begin(), color_num.end());//排序 7 //color_num.erase(unique(color_num.begin(), color_num.end()), color_num.end());//去重 8 9 UF_initialize(); 10 11 //方法1:UF_OBJ_cycle_objs_in_part 12 std::vector<tag_t> SolidVector; 13 tag_t ObjectTag = NULL_TAG; 14 int Type, SubType, Body_Type; 15 UF_OBJ_disp_props_t disp_props; 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_display_properties(ObjectTag, &disp_props); 20 UF_OBJ_ask_type_and_subtype(ObjectTag, &Type, &SubType); 21 if (SubType == UF_solid_body_subtype && disp_props.blank_status == UF_OBJ_NOT_BLANKED) 22 { 23 UF_MODL_ask_body_type(ObjectTag, &Body_Type); 24 if (Body_Type == UF_MODL_SOLID_BODY) 25 { 26 SolidVector.push_back(ObjectTag); 27 } 28 } 29 UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &ObjectTag); 30 }//获取体的数量 31 for (int i = 0; i < SolidVector.size(); i++) 32 { 33 34 Body *body1(dynamic_cast<Body *>(NXObjectManager::Get(SolidVector[i]))); 35 std::vector<Face*> face = body1->GetFaces();//通过体获得所有面 36 double z = -10000; 37 double z1 = 10000; 38 tag_t highest = NULL;//最高面TAG 39 for (int i = 0; i < face.size(); i++)//循环找到所有的面 40 { 41 //UF_DISP_set_highlight(face[i]->Tag(), 0); 42 UF_EVALSF_p_t evaluator = NULL; 43 double uv_min_max[4] = { 0.0, 1.0, 0.0, 1.0 }; 44 UF_EVALSF_initialize_2(face[i]->Tag(), &evaluator);//初始化一个面评估器结构 45 UF_EVALSF_ask_face_uv_minmax(evaluator, uv_min_max);//计算u,v参数空间一个面的最小值、最大值 46 double uv_pair[2] = { 0.5 * (uv_min_max[0] + uv_min_max[1]), 0.5 * (uv_min_max[2] + uv_min_max[3]) }; 47 UF_MODL_SRF_VALUE_t surf_eval; 48 UF_EVALSF_evaluate(evaluator, UF_MODL_EVAL_ALL, uv_pair, &surf_eval); 49 Point3d origin(surf_eval.srf_pos[0], surf_eval.srf_pos[1], surf_eval.srf_pos[2]);//得到UV0.5的XYZ点坐标 50 Vector3d vector1(surf_eval.srf_unormal[0], surf_eval.srf_unormal[1], surf_eval.srf_unormal[2]);//得到UV面的向量 51 UF_EVALSF_free(&evaluator); 52 if (z > surf_eval.srf_pos[2])//判断当Z值大于UV点Z值的时候 53 { 54 z = z; 55 } 56 else//当Z值小于UV点Z值的时候 57 { 58 z = surf_eval.srf_pos[2];//Z就等于UV点Z最大值 59 highest = face[i]->Tag();//找到这个面 60 } 61 } 62 //设置面高亮显示 63 //UF_DISP_set_highlight(highest, 0); 64 face1.push_back(highest); 65 } 66 67 68 //获取高度数据 69 for (int i = 0; i < face1.size(); i++) 70 { 71 int Type; 72 double Point[3]; 73 double Dir[3]; 74 double Box[6]; 75 double Radius[3]; 76 double RadData[3]; 77 int NormDir; 78 int aaa = UF_MODL_ask_face_data(face1[i], &Type, Point, Dir, Box, Radius, RadData, &NormDir); 79 heigth.push_back(Box[5]); 80 } 81 82 sort(heigth.begin(), heigth.end());//排序 83 heigth.erase(unique(heigth.begin(), heigth.end()), heigth.end());//去重 84 if (heigth.size() < 21) 85 { 86 //获取面数据 87 for (int j = 0; j < face1.size(); j++) 88 { 89 int Type; 90 double Point[3]; 91 double Dir[3]; 92 double Box[6]; 93 double Radius[3]; 94 double RadData[3]; 95 int NormDir; 96 97 UF_MODL_ask_face_data(face1[j], &Type, Point, Dir, Box, Radius, RadData, &NormDir); 98 99 tag_t facess = NULL_TAG; 100 UF_MODL_ask_face_body(face1[j], &facess); 101 vector<double>::iterator it = find(heigth.begin(), heigth.end(), Box[5]); 102 int res = it - heigth.begin(); 103 104 UF_OBJ_set_color(facess, color_num[res]); 105 } 106 } 107 else 108 { 109 UF_UI_open_listing_window(); 110 //char msg[256]; 111 //sprintf_s(msg, "%d,", res); 112 UF_UI_write_listing_window("高度个数超过20个,请重新排版!"); 113 } 114 UF_terminate();
参考文章https://www.cnblogs.com/nxopen2018/p/10957425.html
标签:pre htm style sort int ops mat def orm
原文地址:https://www.cnblogs.com/liuxiaoqing1/p/12416649.html