学UG就上UG网:
在本例UG二次开发中,使用到了三个函数,它们分别是创建圆柱、创建基准平面、创建孔,UF_MODL_create_simple_hole(创建孔函数);
C++UG二次开发
UG二次开发C++源码:
- #include <uf_obj.h>
- #include <uf_layer.h>
- /*中磊国际模具培训-创建对话框式布尔运算*/
- tag_t view_tag = NULL_TAG;
-
- /*学NX二次开发就上UG网-www.9sug.com圆柱参数 */
- double cyl_origin[3] = { 0, 0, 0 };
- char * cyl_height = "10";
- char * cyl_diam = "20";
- double cyl_direction[3]{0, 0, 1};
- tag_t cyl_obj_id;
- uf_list_p_t face_list;
- /*学NX二次开发就上UG网-www.9sug.com创建基准平面 */
- int num_refs = 1;
- tag_t object_tags[3];
- tag_t object_tags1[3];
- int point_select[3] = { 0, 1, 0};
- int which_plane = 1;
- char *offset_string = "5.0";
- int num_dplanes;
- tag_t dplane_tag[2];
- tag_t dplane_tag1[2];
- int layer_fea_nu;
- tag_t * layer_fea_id;
- /*学NX二次开发就上UG网-www.9sug.com创建孔参数 */
- double location[3] = { 5, 0, 10 };
- double direction[3] = { -1, 0, 0 };
- char * diame = "5";
- char * depth = "20";
- char * angle = "0";
- tag_t face_li;
- tag_t face_t1;
- tag_t hole_obj_id;
- /*学NX二次开发就上UG网-www.9sug.com圆柱参数 */
- UF_MODL_create_cyl1(UF_NULLSIGN, cyl_origin, cyl_diam, cyl_height, cyl_direction, &cyl_obj_id);
-
- /*获得圆柱体所有的面,存入链表*/
- UF_MODL_ask_feat_faces(cyl_obj_id, &face_list);
- UF_MODL_ask_list_item(face_list, 2, &object_tags[0]);
- UF_MODL_delete_list(&face_list);
- /*设置61为工作层,将以下创建的基准平面放到61层*/
- UF_LAYER_set_status(61, UF_LAYER_WORK_LAYER);
- /*创建基准平面*/
- UF_MODL_create_relative_dplane(num_refs, object_tags, point_select,
- which_plane, NULL, NULL, "0.0", &num_dplanes, dplane_tag);
- /*获得基准平面的object Tag*/
- object_tags1[0] = dplane_tag[0];
- UF_MODL_ask_feat_object(dplane_tag[0], &layer_fea_nu, &layer_fea_id);
- UF_OBJ_set_blank_status(layer_fea_id[0], UF_OBJ_BLANKED);
- UF_free(layer_fea_id);
- /*由第一个基准平面偏置出第二个基准平面,使第二个基准平面与圆柱平面相切*/
- UF_MODL_create_relative_dplane(1, object_tags1, point_select, which_plane,
- NULL, NULL, offset_string, &num_dplanes, dplane_tag1);
- /*设置第一层为工作层*/
- UF_LAYER_set_status(1, UF_LAYER_WORK_LAYER);
- /*创建孔特征*/
- face_li = dplane_tag1[0];
- face_t1 = object_tags[0];
- UF_MODL_create_simple_hole(location, direction, diame,
- depth, angle, face_li, face_t1, &hole_obj_id);
- /*调整视图到合适大小*/
- UF_VIEW_ask_work_view(&view_tag);
- UF_VIEW_fit_view(view_tag, 0.7);
-
- /* Terminate the API environment */
复制代码
|