学UG二次开发就上UG网:
创建常规 孔UF函数:UF_MODL_create_simple_hole(先创建一个圆柱,先后通过链表识别圆柱上的面,再来创建一个孔),本例是通过调用子程序来完成的。
创建孔C++代码
NX二次开发创建孔源代码:
- 子程序:
- /*定义全局变量,用于转递相对定位的目标边*/
- tag_t target_edge;
- /*注册孔定位的用户函数*/
- int rpo_routine_hole(tag_t obj_id)
- {
- int irc;
- uf_list_p_t edge_list;
- tag_t obj_id_target[1], obj_id_tool[1];
- char *constraint_value[] = { "0.0" };
- char *constraint_array[] = { "PARA_DIST_PARMS" };
- int target_qualifier[] = { UF_MODL_ARC_CENTER };
- int tool_qualifier[] = { UF_MODL_ARC_CENTER };
- UF_MODL_ask_feat_edges(obj_id, &edge_list);
- UF_MODL_ask_list_item(edge_list, 0, &obj_id_tool[0]);
- UF_MODL_delete_list(&edge_list);
- obj_id_target[0] = target_edge;
- irc = UF_MODL_create_rpo_constraints(obj_id, NULL_TAG, NULL_TAG, obj_id_target,
- target_qualifier, obj_id_tool, tool_qualifier, constraint_value, constraint_array, 1);
- return irc;
- }
- static void create_hole(void)
- {
- UF_FEATURE_SIGN sign = UF_NULLSIGN;
- double origin[3] = { 0, 0, 0 };
- char * height = "10";
- char * diam = "50";
- double direction[3] = { 0, 0, 1 };
- tag_t cyl_obj_id;
- uf_list_p_t face_list, edge_list;
- tag_t placement_face, thru_face;
- #if CREATE_HOLE_DEBUG
- tag_t face_tag, edge_tag;
- int count, i;
- char buff[100], name[255];
- #endif
- double location[3] = { 0, 0, 20 };
- double direction1[3] = { 0, 0, -1 };
- char * diame = "20";
- char *depth = "100";
- char *angle = "0";
- tag_t hole_tag;
- /*create cylinder*/
- UF_MODL_create_cyl1(sign, origin, height, diam, direction, &cyl_obj_id);
- /*find placement face and thru face*/
- UF_MODL_ask_feat_faces(cyl_obj_id, &face_list);
- #if CREATE_HOLE_DEBUG
- UF_MODL_ask_list_count(face_list, &count);
- for (i = 0; i<count; i++)
- {
- UF_MODL_ask_list_item(face_list, i, &face_tag);
- sprintf(buff, "%d", i);
- strcpy(name, "face");
- strcat(name, buff);
- UF_OBJ_set_name(face_tag, name);
- }
- #endif
- UF_MODL_ask_list_item(face_list, 0, &placement_face);
- UF_MODL_ask_list_item(face_list, 1, &thru_face);
- /*delete the uf_list_p_t data*/
- UF_MODL_delete_list(&face_list);
- /*获得块上边的标识,用于相对定位*/
- UF_MODL_ask_feat_edges(cyl_obj_id, &edge_list);
- #if CREATE_HOLE_DEBUG
- UF_MODL_ask_list_count(edge_list, &count);
- for (i = 0; i<count; i++)
- {
- UF_MODL_ask_list_item(edge_list, i, &edge_tag);
- sprintf(buff, "%d", i);
- strcpy(name, "edge");
- strcat(name, buff);
- UF_OBJ_set_name(edge_tag, name);
- }
- #endif
- UF_MODL_ask_list_item(edge_list, 1, &target_edge);
- UF_MODL_delete_list(&edge_list);
- /*register constrain function*/
- UF_MODL_register_rpo_routine(rpo_routine_hole);
- /*create hole*/
- UF_MODL_create_simple_hole(location, direction1, diame, depth, angle,
- placement_face, thru_face, &hole_tag);
- /*remove register constrain function*/
- UF_MODL_unregister_rpo_routine();
- }
- /*中磊国际模具培训-在圆柱上创建孔*/
- {
- if (UF_initialize() != 0)
- return;
- create_hole();
- UF_terminate();
- }
复制代码
|