【NX二次开发】创建有界平面UF_MODL_create_bplane
先准备几条曲线如下图所示,我们用这几条线来创建一个有界平面:
效果:
源码:
//有界平面 extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); uc1601("有界平面", 1); tag_t tagLine[6] = { 45888,46337,46215,46015,45057,45256 }; UF_STRING_t generator; UF_STRING_p_t ge = &generator; UF_MODL_init_string_list(ge); int iqy = 2;//闭合环数量 int iby = 6;//边缘总数 UF_MODL_create_string_list(iqy, iby, ge); ge->id[0] = tagLine[0]; ge->id[1] = tagLine[1]; ge->id[2] = tagLine[2]; ge->id[3] = tagLine[3]; ge->id[4] = tagLine[4]; ge->string[0] = 5;//第1条环有几条边 ge->dir[0] = 1; //方向1、-1意义不大 ge->id[5] = tagLine[5]; ge->string[1] = 1; //第2条环有几条边 ge->dir[1] = 1; double tol[3]; //公差 tol[0] = 0.001; tol[1] = 0.5 * (PI / 180); tol[2] = 0.02; tag_t tagFace1 = 0; UF_MODL_create_bplane(ge, tol, &tagFace1);//有界平面 UF_terminate(); } extern int ufusr_ask_unload(void) { return (UF_UNLOAD_IMMEDIATELY); }
下面还有一个官方例子,我们先看效果:
源码:
//有界平面 #include <stdio.h> #include <string.h> #include <uf.h> #include <uf_modl.h> #include <uf_curve.h> #include <uf_part.h> #include <uf_csys.h> #define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X))) static int report(char *file, int line, char *call, int irc) { if (irc) { char messg[133]; printf("%s, line %d: %s\n", file, line, call); (UF_get_fail_message(irc, messg)) ? printf(" returned a %d\n", irc) : printf(" returned error %d: %s\n", irc, messg); } return(irc); } static void do_ugopen_api(void) { //有界平面边公差 double tol[3]; /* data points for objects in loops */ static double points[45] = { 4.,-2.,0.,4.,4.,0.,-4.,4.,0.,-4., -4.,0.,0.,-2.,0.,-2.,3.,0.,-3.,3.,0.,-3.,2.,0., -2.,2.,0.,-2.,-1.,0.,2.,3.,0.,3.,3.,0.,3.,2.,0., 2.,2.,0.,2.,3.,0. }; static double startang = 0.0; static double endang = 6.28318530717958648; static double arcrad = 1.0; char prtnam[133]; int loops[4]; int numlps = 4; int units = 2; int arc = 1; int k, total; tag_t bpobj; tag_t part; tag_t objarray1[4]; tag_t objarray2[3]; tag_t objarray3, wcs_tag; tag_t objarray4[4]; UF_STRING_t generator; UF_STRING_p_t ge = &generator; UF_CURVE_line_t line1; UF_CURVE_line_t line2; UF_CURVE_line_t line3; UF_CURVE_line_t line4; UF_CURVE_line_t line5; UF_CURVE_line_t line6; UF_CURVE_line_t line7; UF_CURVE_line_t line8; UF_CURVE_line_t line9; UF_CURVE_arc_t arc1; line1.start_point[0] = points[3]; line1.start_point[1] = points[4]; line1.start_point[2] = points[5]; line1.end_point[0] = points[0]; line1.end_point[1] = points[1]; line1.end_point[2] = points[2]; line2.start_point[0] = points[6]; line2.start_point[1] = points[7]; line2.start_point[2] = points[8]; line2.end_point[0] = points[3]; line2.end_point[1] = points[4]; line2.end_point[2] = points[5]; line3.start_point[0] = points[9]; line3.start_point[1] = points[10]; line3.start_point[2] = points[11]; line3.end_point[0] = points[6]; line3.end_point[1] = points[7]; line3.end_point[2] = points[8]; line4.start_point[0] = points[15]; line4.start_point[1] = points[16]; line4.start_point[2] = points[17]; line4.end_point[0] = points[18]; line4.end_point[1] = points[19]; line4.end_point[2] = points[20]; line5.start_point[0] = points[18]; line5.start_point[1] = points[19]; line5.start_point[2] = points[20]; line5.end_point[0] = points[21]; line5.end_point[1] = points[22]; line5.end_point[2] = points[23]; line6.start_point[0] = points[30]; line6.start_point[1] = points[31]; line6.start_point[2] = points[32]; line6.end_point[0] = points[33]; line6.end_point[1] = points[34]; line6.end_point[2] = points[35]; line7.start_point[0] = points[33]; line7.start_point[1] = points[34]; line7.start_point[2] = points[35]; line7.end_point[0] = points[36]; line7.end_point[1] = points[37]; line7.end_point[2] = points[38]; line8.start_point[0] = points[36]; line8.start_point[1] = points[37]; line8.start_point[2] = points[38]; line8.end_point[0] = points[39]; line8.end_point[1] = points[40]; line8.end_point[2] = points[41]; line9.start_point[0] = points[39]; line9.start_point[1] = points[40]; line9.start_point[2] = points[41]; line9.end_point[0] = points[42]; line9.end_point[1] = points[43]; line9.end_point[2] = points[44]; arc1.start_angle = startang; arc1.end_angle = endang; arc1.arc_center[0] = points[27]; arc1.arc_center[1] = points[28]; arc1.arc_center[2] = points[29]; arc1.radius = arcrad; strcpy(prtnam, "bplane"); uc1601("创建部件bplane.prt", 1); UF_CALL(UF_PART_new(prtnam, units, &part)); UF_CALL(UF_CSYS_ask_wcs(&wcs_tag)); UF_CALL(UF_CSYS_ask_matrix_of_object(wcs_tag, &arc1.matrix_tag)); //为有界平面创建几何图形 //1个外围回路和3个孔回路 //创建外围边界环路 -- 3条线和1条弧线 uc1601("创建外围环", 1); loops[0] = 4; UF_CALL(UF_CURVE_create_line(&line1, &objarray1[0])); UF_CALL(UF_CURVE_create_line(&line2, &objarray1[1])); UF_CALL(UF_CURVE_create_line(&line3, &objarray1[2])); //通过三个点创建一个弧 uf5063(&arc, points, &points[12], &points[9], &objarray1[3]); //创建孔边界环路1 -- 2条线和1条弧线 uc1601("创建内环1", 1); loops[1] = 3; UF_CALL(UF_CURVE_create_line(&line4, &objarray2[0])); UF_CALL(UF_CURVE_create_line(&line5, &objarray2[1])); (uf5063)(&arc, &points[21], &points[24], &points[15], &objarray2[2]); //创建孔边界环路2 -- 1个圆弧 uc1601("创建内环2", 1); loops[2] = 1; UF_CALL(UF_CURVE_create_arc(&arc1, &objarray3)); //创建孔边界环路2 -- 4条线 uc1601("创建内环3", 1); loops[3] = 4; UF_CALL(UF_CURVE_create_line(&line6, &objarray4[0])); UF_CALL(UF_CURVE_create_line(&line7, &objarray4[1])); UF_CALL(UF_CURVE_create_line(&line8, &objarray4[2])); UF_CALL(UF_CURVE_create_line(&line9, &objarray4[3])); UF_MODL_init_string_list(ge); UF_MODL_create_string_list(numlps, 12, ge); //将数据存储到字符串列表结构中 total = 0; ge->string[0] = loops[0]; ge->dir[0] = 1; for (k = 0; k < loops[0]; k++) ge->id[total++] = objarray1[k]; ge->string[1] = loops[1]; ge->dir[1] = -1; for (k = 0; k < loops[1]; k++) ge->id[total++] = objarray2[k]; ge->string[2] = loops[2]; ge->dir[2] = 1; ge->id[total++] = objarray3; ge->string[3] = loops[3]; ge->dir[3] = -1; for (k = 0; k < loops[3]; k++) ge->id[total++] = objarray4[k]; if (total != 12) printf("Error in total value!\n"); tol[0] = .001; tol[1] = .5 * (PI / 180); tol[2] = .02; //创建有界平面 uc1601("创建有界平面1", 1); UF_CALL(UF_MODL_create_bplane(ge, tol, &bpobj)); UF_MODL_free_string_list(ge); } void ufusr(char *param, int *retcode, int paramLen) { if (!UF_CALL(UF_initialize())) { do_ugopen_api(); UF_CALL(UF_terminate()); } } int ufusr_ask_unload(void) { return (UF_UNLOAD_IMMEDIATELY); }