1 NX11+VS2013 2 3 #include <uf.h> 4 #include <uf_modl.h> 5 #include <uf_curve.h> 6 #include <uf_obj.h> 7 8 9 10 11 UF_initialize(); 12 13 //创建四条直线 14 UF_CURVE_line_t Line_coords1; 15 Line_coords1.start_point[0] = 0.0; 16 Line_coords1.start_point[1] = 0.0; 17 Line_coords1.start_point[2] = 0.0; 18 Line_coords1.end_point[0] = 10.0; 19 Line_coords1.end_point[1] = 0.0; 20 Line_coords1.end_point[2] = 0.0; 21 tag_t LineTag[4]; 22 UF_CURVE_create_line(&Line_coords1, &LineTag[0]); 23 24 UF_CURVE_line_t Line_coords2; 25 Line_coords2.start_point[0] = 10.0; 26 Line_coords2.start_point[1] = 0.0; 27 Line_coords2.start_point[2] = 0.0; 28 Line_coords2.end_point[0] = 10.0; 29 Line_coords2.end_point[1] = 10.0; 30 Line_coords2.end_point[2] = 0.0; 31 UF_CURVE_create_line(&Line_coords2, &LineTag[1]); 32 33 UF_CURVE_line_t Line_coords3; 34 Line_coords3.start_point[0] = 10.0; 35 Line_coords3.start_point[1] = 10.0; 36 Line_coords3.start_point[2] = 0.0; 37 Line_coords3.end_point[0] = 0.0; 38 Line_coords3.end_point[1] = 10.0; 39 Line_coords3.end_point[2] = 0.0; 40 UF_CURVE_create_line(&Line_coords3, &LineTag[2]); 41 42 UF_CURVE_line_t Line_coords4; 43 Line_coords4.start_point[0] = 0.0; 44 Line_coords4.start_point[1] = 10.0; 45 Line_coords4.start_point[2] = 0.0; 46 Line_coords4.end_point[0] = 0.0; 47 Line_coords4.end_point[1] = 0.0; 48 Line_coords4.end_point[2] = 0.0; 49 UF_CURVE_create_line(&Line_coords4, &LineTag[3]); 50 51 //创建块 52 UF_FEATURE_SIGN Sign = UF_NULLSIGN;//设置布尔 53 double Corner_pt[3] = { -50.0, -50.0, -110.0 };//设置原点 54 char *Edge_Len[3] = { "100", "100", "100" };//设置长宽高 55 tag_t BlkTag = NULL_TAG; 56 UF_MODL_create_block1(Sign, Corner_pt, Edge_Len, &BlkTag); 57 58 //特征找面 59 uf_list_p_t faceList; 60 UF_MODL_ask_feat_faces(BlkTag, &faceList); 61 62 //获得链表的数量 63 int count = 0; 64 UF_MODL_ask_list_count(faceList, &count); 65 66 tag_t redFaceTag = NULL_TAG; 67 for (int i = 0; i < count; i++) 68 { 69 //获取链表里的每个tag 70 tag_t faceTag = NULL_TAG; 71 UF_MODL_ask_list_item(faceList, i, &faceTag); 72 73 //获得每个面的原点 74 int Type; 75 double Point[3]; 76 double Dir[3]; 77 double Box[6]; 78 double Radius[3]; 79 double RadData[3]; 80 int NormDir; 81 UF_MODL_ask_face_data(faceTag, &Type, Point, Dir, Box, Radius, RadData, &NormDir); 82 83 //找到距离为10的面(块的顶面) 84 if (fabs(fabs(Point[2]) - 10) < 0.001) 85 { 86 //设置颜色 87 UF_OBJ_set_color(faceTag, 186); 88 redFaceTag = faceTag; 89 } 90 } 91 92 93 //创建曲线链表 94 uf_list_p_t curve_refs; 95 UF_MODL_create_list(&curve_refs); 96 //向链表中添加对象 97 uf_list_p_t face1_refs; 98 for (int i = 0; i < 4; i++) 99 { 100 UF_MODL_put_list_item(curve_refs, LineTag[i]); 101 } 102 103 //创建面链表 104 UF_MODL_create_list(&face1_refs); 105 UF_MODL_put_list_item(face1_refs, redFaceTag); 106 107 108 //创建投影曲线 109 int along_face = 0;//0 =使用投影向量(proj_vector),1 =使用面法线 110 double proj_vector[3] = { 0.0, 0.0, -1.0 };//投影的向量方向 111 tag_t proj1tag = NULL_TAG; 112 UF_MODL_create_proj_curves(curve_refs, face1_refs, along_face, proj_vector, &proj1tag); 113 114 115 //方法1 116 //获取投影曲线里的曲线 117 uf_list_p_t uf_curve_refs; 118 UF_MODL_ask_proj_curves(proj1tag, &uf_curve_refs); 119 120 //获得链表的数量 121 int curveCount = 0; 122 UF_MODL_ask_list_count(uf_curve_refs, &curveCount); 123 124 for (int i = 0; i < curveCount; i++) 125 { 126 //获取链表里的每个tag 127 tag_t curveTag = NULL_TAG; 128 UF_MODL_ask_list_item(uf_curve_refs, i, &curveTag); 129 130 //设置颜色 131 UF_OBJ_set_color(curveTag, 136); 132 } 133 134 ////方法2 135 //int n_curve_refs = 0; 136 //tag_t *curve_refsTag = NULL_TAG; 137 //UF_CURVE_ask_proj_curves(proj1tag, &n_curve_refs, &curve_refsTag); 138 139 //for (int i = 0; i < n_curve_refs; i++) 140 //{ 141 // //设置颜色 142 // UF_OBJ_set_color(curve_refsTag[i], 136); 143 //} 144 145 //删除链表 146 UF_MODL_delete_list(&uf_curve_refs); 147 UF_MODL_delete_list(&curve_refs); 148 UF_MODL_delete_list(&face1_refs); 149 UF_MODL_delete_list(&faceList); 150 151 UF_terminate(); 152 153 caesar卢尚宇 154 2020年2月29日