快捷导航 上传作品

[c++] UG二次开发创建孔C++教程下载就上UG网

[复制链接]
ug9.0发表于 2016-6-3 07:05:04 | 显示全部楼层 |阅读模式
学UG二次开发就上UG网:
创建常规 孔UF函数:UF_MODL_create_simple_hole(先创建一个圆柱,先后通过链表识别圆柱上的面,再来创建一个孔),本例是通过调用子程序来完成的。

创建孔C++代码

创建孔C++代码

NX二次开发创建孔源代码:
  1. 子程序:
  2. /*定义全局变量,用于转递相对定位的目标边*/
  3.     tag_t target_edge;

  4.     /*注册孔定位的用户函数*/
  5.     int rpo_routine_hole(tag_t obj_id)
  6.     {
  7.         int irc;
  8.         uf_list_p_t edge_list;

  9.         tag_t obj_id_target[1], obj_id_tool[1];
  10.         char *constraint_value[] = { "0.0" };
  11.         char *constraint_array[] = { "PARA_DIST_PARMS" };
  12.         int target_qualifier[] = { UF_MODL_ARC_CENTER };
  13.         int tool_qualifier[] = { UF_MODL_ARC_CENTER };

  14.         UF_MODL_ask_feat_edges(obj_id, &edge_list);
  15.         UF_MODL_ask_list_item(edge_list, 0, &obj_id_tool[0]);
  16.         UF_MODL_delete_list(&edge_list);

  17.         obj_id_target[0] = target_edge;

  18.         irc = UF_MODL_create_rpo_constraints(obj_id, NULL_TAG, NULL_TAG, obj_id_target,
  19.             target_qualifier, obj_id_tool, tool_qualifier, constraint_value, constraint_array, 1);

  20.         return irc;
  21.     }

  22.     static void create_hole(void)
  23.     {
  24.         UF_FEATURE_SIGN sign = UF_NULLSIGN;
  25.         double origin[3] = { 0, 0, 0 };
  26.         char * height = "10";
  27.         char * diam = "50";
  28.         double direction[3] = { 0, 0, 1 };
  29.         tag_t cyl_obj_id;
  30.         uf_list_p_t face_list, edge_list;
  31.         tag_t placement_face, thru_face;
  32. #if CREATE_HOLE_DEBUG
  33.         tag_t face_tag, edge_tag;
  34.         int count, i;
  35.         char buff[100], name[255];
  36. #endif

  37.         double location[3] = { 0, 0, 20 };
  38.         double direction1[3] = { 0, 0, -1 };
  39.         char * diame = "20";
  40.         char *depth = "100";
  41.         char *angle = "0";
  42.         tag_t hole_tag;

  43.         /*create cylinder*/
  44.         UF_MODL_create_cyl1(sign, origin, height, diam, direction, &cyl_obj_id);


  45.         /*find placement face and thru face*/
  46.         UF_MODL_ask_feat_faces(cyl_obj_id, &face_list);
  47. #if CREATE_HOLE_DEBUG
  48.         UF_MODL_ask_list_count(face_list, &count);
  49.         for (i = 0; i<count; i++)
  50.         {
  51.             UF_MODL_ask_list_item(face_list, i, &face_tag);
  52.             sprintf(buff, "%d", i);
  53.             strcpy(name, "face");
  54.             strcat(name, buff);
  55.             UF_OBJ_set_name(face_tag, name);
  56.         }
  57. #endif
  58.         UF_MODL_ask_list_item(face_list, 0, &placement_face);
  59.         UF_MODL_ask_list_item(face_list, 1, &thru_face);
  60.         /*delete the uf_list_p_t data*/
  61.         UF_MODL_delete_list(&face_list);

  62.         /*获得块上边的标识,用于相对定位*/
  63.         UF_MODL_ask_feat_edges(cyl_obj_id, &edge_list);
  64. #if CREATE_HOLE_DEBUG
  65.         UF_MODL_ask_list_count(edge_list, &count);
  66.         for (i = 0; i<count; i++)
  67.         {
  68.             UF_MODL_ask_list_item(edge_list, i, &edge_tag);
  69.             sprintf(buff, "%d", i);
  70.             strcpy(name, "edge");
  71.             strcat(name, buff);
  72.             UF_OBJ_set_name(edge_tag, name);
  73.         }
  74. #endif
  75.         UF_MODL_ask_list_item(edge_list, 1, &target_edge);
  76.         UF_MODL_delete_list(&edge_list);

  77.         /*register constrain function*/
  78.         UF_MODL_register_rpo_routine(rpo_routine_hole);
  79.         /*create hole*/
  80.         UF_MODL_create_simple_hole(location, direction1, diame, depth, angle,
  81.             placement_face, thru_face, &hole_tag);
  82.         /*remove register constrain function*/
  83.         UF_MODL_unregister_rpo_routine();
  84.     }



  85.     /*中磊国际模具培训-在圆柱上创建孔*/
  86.     {
  87.         if (UF_initialize() != 0)
  88.             return;
  89.         create_hole();
  90.         UF_terminate();
  91.     }

复制代码




就上UG网淘宝直营店
回复

使用道具 评分 举报

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

本版积分规则