此段是可以生成程序的完整代码,只有从坐标(10,10,10)到(500,500,500)一根刀轨。
motion_ptr->feed_value 的值为0时生成G00,非0时生成G01。
此代码只有直线,生成圆弧的方法类似,可参考open-api函数库里的ufd_cam_udop.c文件。
加工CAM的入口函数是udop,此入口函数和常用的UG二次开发入口函数ufusr并列,不需要在ufusr中调用,直接在ufusr所在的CPP文件中写入udop函数即可,或者将udop放在一单独的.c文件中,在ufusr所在的CPP文件中包含也可以,#include "path.c"。
编译出来的dll文件不能像普通的二次开发文件一样直接用Crtl + U 调用,必须先在ugii_env.dat文件中定义好变量,例如abs=d:\path.dll。此abc即是变量,然后使用UG的自定义加工模板调用此变量就OK了。
#include <uf_defs.h> #include <uf_cam.h> #include <uf_udop.h> #include <uf_oper.h> #include <uf_path.h> #include <uf.h> #include <uf_exit.h> #include <stdio.h> extern void udop(char *param, int *status, int parm_len) { char op_name[UF_OPER_OPNAME_LEN]; UF_UDOP_id_t udop_id; UF_UDOP_purpose_t purpose; UF_OPER_id_t oper_id; UF_PATH_id_t path_id; UF_CAM_exit_id_t exit_id = (UF_CAM_exit_id_t)param; UF_initialize(); UF_UDOP_ask_udop( exit_id, &udop_id); UF_UDOP_ask_oper( udop_id, &oper_id); UF_UDOP_ask_purpose( udop_id, &purpose); UF_OPER_ask_name( oper_id, op_name); UF_OPER_ask_path( oper_id, &path_id); if( purpose == UF_UDOP_GENERATE ) { /************ To input GOTO/ motion*************/ UF_PATH_linear_motion_t motion,*motion_ptr = &motion; motion_ptr->feed_value = 0.0; motion_ptr->feed_unit = UF_PATH_FEED_UNIT_NONE; motion_ptr->type = UF_PATH_MOTION_TYPE_CUT; motion_ptr->tool_axis[0] =0.0; motion_ptr->tool_axis[1] =0.0; motion_ptr->tool_axis[2] =1.0; motion_ptr->position[0] =10.0; motion_ptr->position[1] =10.0; motion_ptr->position[2] =10.0; UF_PATH_create_linear_motion( path_id, motion_ptr); motion_ptr->position[0] =500.0; motion_ptr->position[1] =500.0; motion_ptr->position[2] =500.0; UF_PATH_create_linear_motion( path_id, motion_ptr); UF_PATH_cutcom_t cutcom_data; cutcom_data.cutcom_mode = UF_PATH_CUTCOM_ON; cutcom_data.plane_type = UF_PATH_PLANE_TYPE_XY; cutcom_data.cutcom_on_status = UF_PATH_CUTCOM_ON_BEFORE_ENGAGE; cutcom_data.cutcom_off_status = UF_PATH_CUTCOM_OFF_AFTER_RETRACT; cutcom_data.adjust_register = 2; cutcom_data.full_cutcom_output = TRUE; cutcom_data.adjust_flag = TRUE; UF_PATH_create_cutcom( path_id, &cutcom_data, NULL ); UF_PATH_end_tool_path( path_id ); } UF_terminate(); }