UG二次开发模板(4)udop
udop 1,用UG打开resource\template_part\metric下的模板,复制一个用户自定义的加工方式,定义好CAM API Exit Name: UGII_BASE_XX,再点击options,customizedialog。将Environment variable name隐藏,设置好自己的对话框风格后保存退出。2,打开ugii_env.txt在最后加上:UGII_BASE_XX =路径 D:\projects\test\Release\Templet.dll保存退出。 3,打开模板程序,将接口函数改为udop头文件#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>#include <uf_ncgroup.h>#include < uf_setup.h > char op_name; UF_UDOP_id_t udop_id; UF_UDOP_purpose_t purpose; UF_OPER_id_t oper_id; UF_PATH_id_t path_id; /*****Convert UG/Open API param to CAM exit id******/ UF_CAM_exit_id_t exit_id =(UF_CAM_exit_id_t)parm ; /***** Using the exit_id to get the udopidentifier ******/ UF_initialize(); UF_UDOP_ask_udop(exit_id, &udop_id); /*****Using the udop_id to get the oper identifier ******/ UF_UDOP_ask_oper(udop_id, &oper_id); /*****Using the udop_id to get the pupose of the call ******/ UF_UDOP_ask_purpose(udop_id, &purpose); /*****Using the oper_id to get the name of the oper ******/ UF_OPER_ask_name(oper_id, op_name);file:///C:/Users/plmhome/AppData/Local/Temp/msohtmlclip1/01/clip_image001.gif /*****Using the oper_id to get the path identifier ******/ UF_OPER_ask_path(oper_id, &path_id); /*得到程序ID*/tag_tsetupTag; tag_t root; tag_t oper_tag; UF_CALL(UF_SETUP_ask_setup(&setupTag )); UF_CALL(UF_SETUP_ask_program_root(setupTag, &root )); UF_CALL(UF_NCGROUP_ask_object_of_name(root, op_name,&oper_tag )); if( purpose ==UF_UDOP_USER_PARAMS ) { intresponse; XXXX(&response,oper_tag); // XXXX:对话框名 } else if( purpose== UF_UDOP_GENERATE ) { { 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_RAPID;//切削motion_ptr->feed_value=1000; //转速 motion_ptr->feed_unit=UF_PATH_FEED_UNIT_NONE; motion_ptr->tool_axis =0.0; motion_ptr->tool_axis =0.0; motion_ptr->tool_axis =1.0;//指定刀具轴心法向 motion_ptr->position =0.0; motion_ptr->position =0.5; motion_ptr->position =50; //指定刀具到达的点 UF_PATH_create_linear_motion( path_id,motion_ptr); } } 4,制作好对话框 1,在extern int XXXX ( int *response)添加程序id:,tag_t oper_tag2,定义结构用以各回调函数间传递信息1) XXXX.h添加结构struct user_data{ tag_t oper_tag;};2) XXXX.template.c user_data obj; obj.oper_tag=oper_tag; if ( ( error_code = UF_STYLER_create_dialog ( "beixi.dlg", CHANGE_cbs, /* Callbacks fromdialog */ CHANGE_CB_COUNT, /* number of callbacks*/ &obj, /* This is your client data */ response )) != 0 ) 3) 各个回调函数中得到传递的资料 user_data *obj; obj=(user_data*)client_data;XXX=obj.oper_tag; 3,初始化对话框UF_STYLER_item_value_type_tvalue; value.item_attr=UF_STYLER_VALUE; UF_ATTR_value_t ATTR_value; int ATTR_type; ATTR_value.value.string=new char;//分配内存 /////////////////////////////// ATTR_type=0; value.item_id= XXX;//需要添加数据的ID UF_ATTR_find_attribute(oper_tag,UF_ATTR_string,"属性名",&ATTR_type); if(0==ATTR_type) { value.value.integer=2; UF_STYLER_set_value(dialog_id,&value);
} if(UF_ATTR_string==ATTR_type) { UF_ATTR_read_value(oper_tag,"属性名",UF_ATTR_string,&ATTR_value); value.value.integer=atoi(ATTR_value.value.string);//atof UF_STYLER_set_value(dialog_id,&value); } ///////////////////////////////////// delete[]ATTR_value.value.string; UF_STYLER_free_value(&value); //释放空间 4, CHANGE_ok_cb//////////////////1,得到oper_taguser_data*obj; obj=(user_data*)client_data; tag_t oper_tag; oper_tag=obj->oper_tag; UF_STYLER_item_value_type_t value; value.item_attr=UF_STYLER_VALUE; UF_ATTR_value_t ATTR_value; ATTR_value.type = UF_ATTR_string; ATTR_value.value.string=newchar;//分配内存 //////////////////2,删除属性 UF_ATTR_delete_all(oper_tag,UF_ATTR_any); /////////////////////////////3,添加输入框中的各种数值 value.item_id=XXX; UF_STYLER_ask_value(dialog_id,&value); sprintf(ATTR_value.value.string,"%d",value.value.integer); UF_CALL(UF_ATTR_assign(oper_tag, "属性名",ATTR_value)); //sprintf(ATTR_value.value.string,"%f",value.value. real); // UF_CALL(UF_ATTR_assign(oper_tag, "属性名",ATTR_value));
/////////////////////////////4,添加所选加工tagif(0==count) { uc1601("未选择加工面",1); } if(0<count) { sprintf(ATTR_value.value.string,"%d",count); UF_CALL(UF_ATTR_assign(oper_tag,"geometry_count",ATTR_value)); for(int i=0; i<count; i++) { char inf=""; sprintf(inf,"geometry_id%d",i); ATTR_value.value.string =UF_TAG_ask_handle_of_tag(obj->obj); UF_CALL(UF_ATTR_assign(oper_tag,inf,ATTR_value)); } } ////////////////////delete []ATTR_value.value.string;UF_STYLER_free_value(&value); 5,生成刀轨 1)查找属性//////////////////////////////////////// 1查找intintfind_int_attribute(int *value, char title[], tag_t oper_tag ) { UF_ATTR_value_t ATTR_value; int ATTR_type=0; UF_CALL(UF_ATTR_find_attribute(oper_tag,UF_ATTR_string,title,&ATTR_type));
if(0==ATTR_type){ return ATTR_type; UF_terminate ();}if(UF_ATTR_string==ATTR_type){ ATTR_value.value.string=new char; UF_ATTR_read_value(oper_tag,title,UF_ATTR_string,&ATTR_value); *value=atoi(ATTR_value.value.string); delete []ATTR_value.value.string;}return ATTR_type;}////////////////////////////////// 2查找doubleintfind_double_attribute(double *value, char title[], tag_t oper_tag ) { UF_ATTR_value_t ATTR_value; int ATTR_type=0; UF_CALL(UF_ATTR_find_attribute(oper_tag,UF_ATTR_string,title,&ATTR_type));if(0==ATTR_type){ return ATTR_type; UF_terminate ();}if(UF_ATTR_string==ATTR_type){ ATTR_value.value.string=new char; UF_ATTR_read_value(oper_tag,title,UF_ATTR_string,&ATTR_value); *value=atoi(ATTR_value.value.string); delete []ATTR_value.value.string;}return ATTR_type;
} //////////////////////////////////3查找tag intfind_tag_attribute( char title[], tag_t *geometry_tag, tag_t oper_tag ) { UF_ATTR_value_t ATTR_value; intATTR_type=0; UF_CALL(UF_ATTR_find_attribute(oper_tag,UF_ATTR_string,title,&ATTR_type));if(0==ATTR_type){ return ATTR_type; UF_terminate ();}if(UF_ATTR_string==ATTR_type){ tag_t tag; ATTR_value.value.string=new char; UF_ATTR_read_value(oper_tag,title,UF_ATTR_string,&ATTR_value); tag=UF_TAG_ask_tag_of_handle(ATTR_value.value.string); *geometry_tag=tag; delete []ATTR_value.value.string; }return ATTR_type;} 2)///////////////////////////////主函数 int cut_num; char title="属性名"; int ATTR_type=0; ATTR_type=find_int_attribute(&cut_num,title,oper_tag);//查找int形 if(0==ATTR_type) { uc1601("参数错误。",1);
UF_terminate(); return; } ATTR_type=0; double per_cut=0; strcpy(title," 属性名"); ATTR_type=find_double_attribute(&per_cut,title,oper_tag); //查找double形 if(0==ATTR_type) { uc1601("参数错误。",1);UF_terminate(); return; } 1,查找刀具属性tag_ttool_id=NULL;doubletool_diam=0;UF_OPER_ask_cutter_group(oper_tag,&tool_id); UF_PARAM_ask_double_value(tool_id,UF_PARAM_TL_DIAMETER,&tool_diam);
//查找直径 char tool_text;char ch_s="", ch_f="",*ch_p=NULL;double tool_s=0 ,tool_f=0;//主轴转速,进给 if(UF_CALL(UF_PARAM_ask_str_value(tool_id,1158,tool_text))==0)//属性文本{ ch_p=strstr(tool_text,"S="); if (ch_p!=NULL) { int i=0; ch_p=ch_p+2; while((48<=*ch_p&&*ch_p<=57)||46==*ch_p)//当指针指向为数字或者小数点 { ch_s=*ch_p; i++; ch_p++; } ch_s='\0'; if(i!=0) { tool_s=atof(ch_s); } //uc1601(ch_s,1); } ch_p=NULL; ch_p=strstr(tool_text,"F="); if (ch_p!=NULL) { int i=0; ch_p=ch_p+2; while((48<=*ch_p&&*ch_p<=57)||46==*ch_p)//当指针指向为数字或者小数点 { ch_f=*ch_p; i++; ch_p++; } ch_f='\0'; if(i!=0) { tool_f=atof(ch_f); } // uc1601(ch_f,1); } } 2, //主轴开UF_PATH_spindle_on_t spindle_data;spindle_data.speed = tool_s;spindle_data.maxrpm = 10000.0;spindle_data.mode = UF_PATH_SPINDLE_MODE_RPM;spindle_data.direction = UF_PATH_DIRECTION_CLOCKWISE;spindle_data.speed_flag = TRUE;spindle_data.maxrpm_flag = TRUE;spindle_data.range_flag = FALSE;UF_PATH_create_spindle_on( path_id, &spindle_data, NULL );//主轴关UF_PATH_create_spindle_off( path_id, NULL ); 3,//打开刀具补偿UF_PATH_cutcom_tcutcom_data;cutcom_data.cutcom_mode = UF_PATH_CUTCOM_LEFT;cutcom_data.plane_type = UF_PATH_PLANE_TYPE_NONE;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 = 1;cutcom_data.full_cutcom_output = TRUE;cutcom_data.adjust_flag = TRUE;UF_PATH_create_cutcom( path_id, &cutcom_data, NULL ); //关闭刀具补偿cutcom_data.cutcom_mode = UF_PATH_CUTCOM_OFF;UF_PATH_create_cutcom( path_id, &cutcom_data, NULL );
页:
[1]