PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

PLM之家PLMHome-国产软件践行者

[资料] UG二次开发模板(4)udop

[复制链接]

2013-9-23 22:30:41 5302 0

admin 发表于 2013-9-23 22:30:41 |阅读模式

admin 楼主

2013-9-23 22:30:41

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
udop
1,用UG打开resource\template_part\metric下的模板,复制一个用户自定义的加工方式,定义好CAM API Exit Name: UGII_BASE_XX,再点击options,customizedialogEnvironment 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);
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.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_tag
. ^* Z8 U  v; B$ K! S: A3 Y1 g0 z7 b

0 D. V9 q! O; w; Y, y. t& k
2,定义结构用以各回调函数间传递信息
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);
7 `1 X! A7 d- u4 j9 g% M
        
     }
     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));
& z) }/ \# ?: i
/////////////////////////////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));
! S3 V; B, Q- ^( o; Y1 V
  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;

6 K8 ]* P: }6 x4 d) @! b2 V( }}
//////////////////////////////////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);
. w: M4 C$ ~6 \: `; w
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);
! N  o! V3 V3 O  I. }* z//查找直径
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 );
4 p# Q8 m( t: W
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了