请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
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_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; /*****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); 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.0; motion_ptr->tool_axis[1] =0.0; motion_ptr->tool_axis[2] =1.0;//指定刀具轴心法向 motion_ptr->position[0] =0.0; motion_ptr->position[1] =0.5; motion_ptr->position[2] =50; //指定刀具到达的点 UF_PATH_create_linear_motion( path_id,motion_ptr); } } 4,制作好对话框 1,在extern int XXXX ( int *response)添加程序id:,tag_t oper_tag7 ~7 y* q. O9 Z6 i. F- C. B
9 W* L4 Q x$ ]9 U$ l4 b) S2,定义结构用以各回调函数间传递信息 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[133];//分配内存 /////////////////////////////// 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);
$ ~4 \" W( j' z0 C# g9 ^
} 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_tag user_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[UF_ATTR_MAX_TITLE_LEN+1];//分配内存 //////////////////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));
8 a1 D% G) c! A+ J( e/ ~# S" o/////////////////////////////4,添加所选加工tag
if(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[133]=""; 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查找int intfind_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)); ) J% @4 O* J* C1 W
if(0==ATTR_type) { return ATTR_type; UF_terminate (); } if(UF_ATTR_string==ATTR_type) { ATTR_value.value.string=new char[133]; 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查找double intfind_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[133]; 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;
( `4 o/ J# Z4 o. `}
//////////////////////////////////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[133]; 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[133]="属性名"; int ATTR_type=0; ATTR_type=find_int_attribute(&cut_num,title,oper_tag);//查找int形 if(0==ATTR_type) { uc1601("参数错误。",1);
$ F# |6 J: H7 g+ k+ A* W4 gUF_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);9 ?% {& ]( _% H& l/ n
//查找直径 char tool_text[133]; char ch_s[10]="", ch_f[10]="",*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_t cutcom_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 ); % [+ m% m) x/ w9 x! Q
|