快捷导航 上传作品

[c++] NX二次开发线性阵列孔C++源码教程下载就上UG网

[复制链接]
ug9.0发表于 2016-6-4 07:43:30 | 显示全部楼层 |阅读模式
学UG二次开发就上UG网:
线性阵列函数:UF_MODL_create_linear_iset(创建一个方块体与一个圆柱,并执行求差,然后对得到的孔进行线性阵列)

阵列UG二次开发

阵列UG二次开发

NX二次开发阵列C++源代码:
   
  1. UF_FEATURE_SIGN sign;
  2.     UF_FEATURE_SIGN sign1;
  3. #define a UF_NULLSIGN
  4. #define c UF_NEGATIVE
  5.     int m;

  6. #define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))

  7.     static int report(char *file, int line, char *call, int irc)
  8.     {
  9.         if (irc)
  10.         {
  11.             char    messg[133];
  12.             printf("%s, line %d:  %s\n", file, line, call);
  13.             (UF_get_fail_message(irc, messg)) ?
  14.                 printf("    returned a %d\n", irc) :
  15.                 printf("    returned error %d:  %s\n", irc, messg);
  16.         }
  17.         return(irc);
  18.     }
  19.     void float_to_char(double b, char cc[])
  20.     {
  21.         FILE *fp5;
  22.         fp5 = fopen("aut.dat", "w");
  23.         fprintf(fp5, "%15.8f\n", b);
  24.         fclose(fp5);
  25.         cc[0] = '\0';
  26.         fp5 = fopen("aut.dat", "r");
  27.         fscanf(fp5, "%s\n", cc);
  28.         fclose(fp5);
  29.         return;
  30.     }
  31.     static void do_ugopen_api(float abc[], float orig1[], float orig2[])
  32.     {
  33.         int method = 0;
  34.         double block_orig[3] = { orig1[0], orig1[1], orig1[2] };
  35.         double cyl_orig[3] = { orig2[0], orig2[1], orig2[2] };
  36.         char *block_len[3];
  37.         char bb[4][20];
  38.         char *cyl_height;
  39.         char *cyl_diam;
  40.         char cc[3][20];
  41.         double direction[3] = { 0, 0, m };
  42.         char *number_in_x;
  43.         char *distance_x;
  44.         char *number_in_y;
  45.         char *distance_y;
  46.         char dd[5][20];
  47.         tag_t blk_obj;
  48.         tag_t cyl_obj_id;
  49.         uf_list_p_t feature_list;
  50.         tag_t feature_obj_id;

  51.         float_to_char(abc[0], bb[0]);
  52.         block_len[0] = bb[0];
  53.         float_to_char(abc[1], bb[1]);
  54.         block_len[1] = bb[1];
  55.         float_to_char(abc[2], bb[2]);
  56.         block_len[2] = bb[2];
  57.         UF_CALL(UF_MODL_create_block1(sign, block_orig, block_len, &blk_obj));
  58.         float_to_char(abc[3], cc[0]);
  59.         cyl_height = cc[0];
  60.         float_to_char(abc[4], cc[1]);
  61.         cyl_diam = cc[1];
  62.         UF_CALL(UF_MODL_create_cyl1(sign1, cyl_orig, cyl_height, cyl_diam, direction, &cyl_obj_id));
  63.         float_to_char(abc[5], dd[0]);
  64.         number_in_x = dd[0];
  65.         float_to_char(abc[6], dd[1]);
  66.         distance_x = dd[1];
  67.         float_to_char(abc[7], dd[2]);
  68.         number_in_y = dd[2];
  69.         float_to_char(abc[8], dd[3]);
  70.         distance_y = dd[3];
  71.         UF_CALL(UF_MODL_create_list(&feature_list));
  72.         UF_CALL(UF_MODL_put_list_item(feature_list, cyl_obj_id));
  73.         UF_CALL(UF_MODL_create_linear_iset(method, number_in_x, distance_x, number_in_y, distance_y,
  74.             feature_list, &feature_obj_id));
  75.         return;
  76.     }
  77.     void main()
  78.     {
  79.         float bac[9] = { 5.0, 4.0, 3.0, 4.0, 1.0, 3.0, 1.5, 2.0, 2.0 };
  80.         //长方体和圆柱体的尺寸参数
  81.         float orig1[3] = { 0.0, 0.0, 0.0 };  //长方体的原点
  82.         float orig2[3] = { 1.0, 1.0, 0.0 };  //圆柱体的原点
  83.         sign1 = c;   //表示圆柱体
  84.         sign = a;    //表示长方体
  85.         m = 1;
  86.         do_ugopen_api(bac, orig1, orig2);
  87.         return;
  88.     }

  89. 调用程序:
  90. /* TODO: Add your application code here */

  91.     /*中磊国际模具培训-线型阵列*/
  92.     {


  93.         if (!UF_CALL(UF_initialize()))
  94.         {
  95.             main();
  96.         }
  97.         UF_CALL(UF_terminate());
  98.     }
复制代码



就上UG网淘宝直营店
回复

使用道具 评分 举报

您需要登录后才可以回帖 登录 | 注册UG网

本版积分规则