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二次开发模板(3)功能模板

  [复制链接]

2013-11-28 15:44:45 5042 1

admin 发表于 2013-9-23 22:29:24 |阅读模式

admin 楼主

2013-9-23 22:29:24

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

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

x
功能模板
1,制作对话框
1)进入User InterfaceStyler,设计好对话框,将Launch Dialog From改为Callback保存
2)将生成的对话框文件放在模板文件夹下,以记事本格式打开XX. _template.C文件,将extern int <enter the name ofyour function> ( int *response )改为extern int XXX ( int*response )后保存。
3)打开VC的Templet,依次点击Tools->options->directories,将XX.h所在的文件夹包含进去。
4)在Templet.cpp中加入#include"XX_template.c"
#include "XX.h"
5)在程序内写入    intresponse;
          XXX (&response);点击F7,编译成功。
2对话框求值,设值
UF_STYLER_item_value_type_tvalue;
value.item_attr=UF_STYLER_VALUE;
value.item_id=XXX;  //在.h文件中定义的ID
UF_STYLER_ask_value(dialog_id,&value); //读值
/*赋值到变量中,变量在.h文件中定义,根据对话框定义不同类型:real,string,strings, integer ,integers , real, reals*/
XXX=value.value.real;//赋值
value.item_id=XXX; //在.h文件中定义的ID
value.count=1;//拉伸条移动
UF_STYLER_set_value(dialog_id,&value);//设值
UF_STYLER_free_value(&value); //释放空间
3
1),设置控件的激活状态
UF_STYLER_item_value_type_t value;
value.item_attr=UF_STYLER_SENSITIVITY; //指定设置控件的激活状态

8 H6 k2 R) x% e( _( D* K# k6 w/ Tvalue.item_id=
XXX ; //在.h文件中定义的ID
value.value.integer=FALSE; // FALSE为不激活,TRUE为激活
UF_STYLER_set_value(dialog_id,&value);
2),设置对话框是否能选择物体
UF_UI_mask_t all_mask[] = {
           UF_circle_type,0, 0,
           UF_cylinder_type,0, 0,
           UF_line_type,0, 0
       };
UF_STYLER_item_value_type_t value;
value.item_attr=UF_STYLER_SELECTION;
value.item_id=UF_STYLER_DIALOG_INDEX;
UF_STYLER_ask_value(dialog_id0,&value);
UF_UI_set_sel_type(value.value.selection,UF_UI_SEL_TYPE_INACTIVE_SELECTION );//不能选择
// UF_UI_SEL_TYPE_SINGLE_SELECTION & z3 u& E$ M* b. x9 t, r1 Y
//UF_UI_SEL_TYPE_SINGLE_DESELECTION
# v$ z; a4 b! z# a//UF_UI_SEL_TYPE_ROBUST_SELECTION
能选择4 ^1 l, y; C/ L' S# ?3 M! V
//UF_UI_SEL_TYPE_SINGLE_POSITION
: e# ^& E. R, V) ?0 Q$ U//UF_UI_SEL_TYPE_RECTANGLE_POSITION
    if (  ( UF_UI_set_sel_mask ( value.value.selection,
           UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,2, all_mask ) ) )
       {
           return(UF_UI_CB_CONTINUE_DIALOG);
       }
2,查询选择物体
UF_STYLER_item_value_type_tvalue;
       value.item_attr=UF_STYLER_SELECTION;
       value.item_id=UF_STYLER_DIALOG_INDEX;
       UF_STYLER_ask_value(dialog_id0,&value);
        UF_UI_ask_sel_object_list(value.value.selection,&count,&objects);
4,求三面交点
头文件
void change( double AB [3][4], int line);

, q1 [* x5 j: K: v9 o! n2 Gvoid row_change ( double AB [3][4], int row);
   
           
        double xyz[3];///交点坐标
        double AB [3][4]   = { { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0,0}};
       double dot_product;
       UF_VEC3_dot ( dir, center, &dot_product);
       AB [0][0] = dir[0]; AB [0][1] = dir[1];
       AB [0][2] = dir[2]; AB [0][3] = dot_product;
      
       double dot_product1;
       UF_VEC3_dot ( dir1, center1, &dot_product1);
       AB [1][0] = dir1[0]; AB [1][1] = dir1[1];
       AB [1][2] = dir1[2]; AB [1][3] = dot_product1;
      
       double dot_product2;
       UF_VEC3_dot ( dir2, floor_center, &dot_product2);
       AB [2][0] = dir2[0]; AB [2][1] = dir2[1];
       AB [2][2] = dir2[2]; AB [2][3] = dot_product2;
      
       for ( int j = 0; j < 3; j++)
       {
           change ( AB, j);
           row_change ( AB, j);
       }
      
       xyz [2] = AB [2][3];
       xyz [1] = AB [1][3] - AB [1][2] * xyz [2];
       xyz [0] = AB [0][3] - AB [0][2] * xyz [2] - AB [0][1] * xyz[1];
子函数:
void change ( double AB[3][4], int line)
{
    double max    = 0;
    double buffer = 0;
    int    bj     = -1;
    double max_x  = 0;
   
    for ( int i = line; i < 3; i++)
    {
       max_x = fabs( AB [line]);
      
       if ( max_x > max)
       {
" A" L' N) B- Y1 m* \$ c
           max = max_x;
           bj  = i;
       }
    }
   
    for ( int j = 0; j < 4; j++)
    {
       buffer = AB [bj][j];
       AB [bj][j] = AB [line][j];
       AB [line][j] = buffer;
    }
}
//初等行变换
void row_change ( doubleAB [3][4], int row)
{
    for ( int j = row; j < 3 ; j++)
    {
       double divisor = AB [j][row];
       if ( 0 != divisor)
       {
           for ( int i = row; i < 4; i++)
           {
              AB [j] = AB [j] / divisor;
           }
       }
    }
   
    for ( int k = ( row + 1); k < 3; k++)
    {
       if ( 0 != AB [k][row])
       {
           for ( int l = 0; l < 4; l++)
           {
              AB [k][l] = AB [k][l] - AB [row][l];
           }
       }
    }
}

9 u. o8 C; l- ^5
,筛选边界
uf_loop_p_t   loops_list=NULL;//回环ID
      
UF_MODL_ask_face_loops(face,&loops_list );//查询回环
      
int      loops_count=0;//回环数量
UF_MODL_ask_loop_list_count(loops_list,&loops_count);//查询回环数量
    for (int l_i=0; l_i<loops_count; l_i++)
    {
       int    loops_type=0;//回环类型
      
       uf_list_p_t   edge_list=NULL;//边缘菜单指针ID
        UF_MODL_ask_loop_list_item(loops_list,l_i,&loops_type,&edge_list);      
       if (1==loops_type)// 边界=1, 洞=2, 其他=3
           
       {
           int   edge_count=0;//边缘数量
           UF_MODL_ask_list_count ( edge_list, &edge_count );         
           tag_t    edge_id=NULL;//边缘ID
           
           
           for(int edge_i=0; edge_i<edge_count;edge_i++)
           {
              
              UF_MODL_ask_list_item( edge_list,edge_i,&edge_id);
              
              UF_MODL_create_curve_from_edge(edge_id,&edge_id);
              
           }
           
       }
    }
   
6,transform转移
#include<uf_trns.h>
5 r. g- a5 [" G
1
)平移uf5943
2)缩放uf5944
3)旋转uf5945
double matrix [ 16 ];
       int status;      
       double  angle=0;//旋转角度
uf5945(center,dir,&angle,matrix,&status);
//center物体中心,dir法向
      
       const int objects=1;//数量
       const int  move=1; // 1 :复制 2 :粘贴
       const int  layer=-1;//0:最初层; -1: 工作层; 1 - 256 : 指定层
       const int trace_curves=2; //轨迹状态, 1 开, 2 关
       uf5947(matrix,&obj_tag,&n_objects,&move,
           &layer,&trace_curves,NULL,NULL,&status);
4)投影uf5946
double matrix [ 16 ];
       int status;      
   
       uf5946(object,matrix,&status);//object:投影面或线,dir法向
       const int objects=1;//数量
       const int  move=1; // 1 :复制 2 :粘贴
       const int  layer=-1;//0:最初层; -1: 工作层; 1 - 256 : 指定层
       const int trace_curves=2; //轨迹状态, 1 开, 2 关
       uf5947(matrix,&obj_tag,&n_objects,&move,
           &layer,&trace_curves,NULL,NULL,&status);
5偏移相加 uf5942

3 l0 _# f% _/ w! u. [1 T* i$ _7
,裁剪片体
tag_t  *trim_objects;
trim_objects =new tag_t[count];
trim_objects =bound_id;
voidtrim_sheet()
{
   
    UF_MODL_vector_t projection_method ;
    projection_method.reverse_vector=0;
    projection_method.vector_type=UF_MODL_VECTOR_DIRECTION;
( l2 E. r6 S) j8 j4 _
    UF_MODL_vector_defined_by_union_tdir1;
    UF_MODL_vector_direction_t dir2;
    dir2.xyz [0]=dir[0];
    dir2.xyz [1]=dir[1];
    dir2.xyz [2]=dir[2];
    dir1.direction=dir2;
   
    projection_method.defined_by=dir1;
   
    double point_coords[3] ;
   
    point_coords[0]=center[0];
    point_coords[1]=center[1];
    point_coords[2]=center[2];
   
    int gap_point_count ;
    double *gap_points;
    tag_t feature_obj_eid;
    UF_MODL_create_trimmed_sheet(sel_sheet,edge_count,trim_objects,&projection_method,
                          0,1,point_coords,0.1,&gap_point_count,&gap_points,&feature_obj_eid);
   
}
8,offset偏移
   
char   distance_str[] = {"10.0"};//偏移的距离
      
int  num_curves;
tag_t *offset_curves;
UF_CURVE_offset_distance_data_t  offset_distance;
offset_distance.distance= distance_str;
offset_distance.roUGh_type=1;
UF_STRING_t   input_string;
input_string.id=curve_id;//加入想要偏移的线
input_string.num=1; //偏移矢量方向数量
input_string.string=&string_count;//偏移线的数量
intstring_dir=UF_MODL_CURVE_START_FROM_END;
input_string.dir=&string_dir;
                  
UF_CURVE_offset_data_toffset_data;
+ H. Q& r# i9 B5 s/ C
              
offset_data.offset_def.distance_type1= &offset_distance;
offset_data.input_curves= &input_string;
offset_data.approximation_tolerance= 0.01;
offset_data.string_tolerance=0.001;
offset_data.offset_def.distance_type1= &offset_distance;
offset_data.offset_type= UF_CURVE_OFFSET_DISTANCE_TANGENT;
UF_CALL(UF_CURVE_create_offset_curve(&offset_data,
&num_curves,&offset_curves));
9,创建平面
UF_STRING_tgenerator;
UF_STRING_p_tge = &generator;
   
UF_MODL_init_string_list(ge);
UF_MODL_create_string_list(1,12,ge);
   
ge->string[0]= 1;
ge->dir[0]= 1;//指定线从开始到结束
ge->id[0]= arc_id;//指定边界的id
doubletol[3];
tol[0] =.001;//直线公差
tol[1] = .5* (PI/180);//圆弧公差
tol[2] =.02;//不起作用
UF_CALL(UF_MODL_create_bplane(ge,tol,&bplane));
10,选择
1),点选择
tag_t point_tag;
double point[3];
     UF_UI_POINT_base_method_t  base_method=UF_UI_POINT_INFERRED ;  
     intpoint_res;
     
UF_CALL(UF_UI_point_construct("选择起点",&base_method,&point_tag,
point,&point_res));
if(point_res=UF_UI_OK&&NULL_TAG!=point_tag)
{
3 \# G1 B$ Q. G- u0 \* B! Q
}
2),向量选择
   int  mode = UF_UI_INFERRED ;
   int  disp_flag = UF_UI_DISP_TEMP_VECTOR;
double  vec[3];
double  vec_pnt[3];
int  res_vec = 0;
   UF_initialize();  
   ifail=  UF_UI_specify_vector( "Choose aVector",&mode,disp_flag,
      vec,vec_pnt,&res_vec);
   if( ifail != 0 || res_vec!= UF_UI_OK )   
   {   
      UF_UI_ONT_refresh();
      printf("No vector selected \n" );
   }
   else
   {
      printf("Vect base (%f, %f, %f), direction (%f, %f, %f) \n",
          vec_pnt[0],vec_pnt[1], vec_pnt[2], vec[0], vec[1], vec[2] );
}
3),平面选择
tag_t  plane_eid=NULL_TAG;
double orientation[9] ={0,0,0,0,0,0,0,0,0};
    double origin[3] = {0,0,0};
    double pts[6] = {0,0,0,0,0,0};
    int i, error_code = 0;
    int mode, display, response;
    mode = 1;                     
display = 0;      
UF_initialize();
    error_code = UF_UI_specify_plane(
        "Select Plane", &mode, display,
        &response, orientation, origin,&plane_eid);
   
    if ( !error_code && response != 1&& response != 2)
    {
               for (i=0; i<3; i++)
           pts = origin + orientation;
4 K' \. T* V% a0 D1 u8 Z( v' Y
               for (i=3; i<6; i++)
           pts = origin[i-3] + orientation;
        FTN(uf5374)(origin,pts,&pts[3],&plane_eid);
    }
11,临时点,线
void display_temporary_point_line( double point1[3], double point2[3])
{
   UF_DISP_view_type_twhich_views = UF_DISP_USE_WORK_VIEW;
   UF_OBJ_disp_props_TColor;
   color.layer= 201;
   color.color= 186;
   color.blank_status= UF_OBJ_NOT_BLANKED;
   color.line_width= UF_OBJ_WIDTH_NORMAL;
   color.font=0;
   color.highlight_status= FALSE;
   UF_DISP_poly_marker_tmarker_type = UF_DISP_POINT;
   
UF_DISP_display_temporary_point ( NULL,which_views, point1, &color, marker_type);
UF_DISP_display_temporary_point ( NULL,which_views, point2, &color, marker_type);
UF_DISP_display_temporary_line ( NULL,which_views, point1, point2, &color);
}
12,WCS与绝对坐标转换
              voidcycs_wcs(double point[])
{
    tag_t  wcs_id,matrix_id;
    double matrix[ 9 ];
    //wcs_origin:工作坐标系原点,vec:工作坐标系轴向量,point_origin:点到原点的矢量
    double wcs_origin[3], vec[3][3],point_origin[3];
    //1,得到工作坐标系
    UF_CSYS_ask_wcs(&wcs_id);
    UF_CSYS_ask_csys_info(wcs_id,&matrix_id,wcs_origin);            
    UF_CSYS_ask_matrix_values(matrix_id,matrix);
   
5 M3 {- C) j6 p2 [0 Z% H
    //2
,得到工作坐标系轴向量
    UF_MTX3_x_vec(matrix, vec[0]);
    UF_MTX3_y_vec(matrix, vec[1]);
    UF_MTX3_z_vec(matrix, vec[2]);
   
    for(inti=0;i<3;i++)
    {   
       double tol;
//3,得到点到工作坐标系原点矢量
       UF_VEC3_unitize(vec,0.000001,&tol,vec);
//4,得到点到工作坐标系原点矢量
       point_origin=point-wcs_origin;
    }
    for(intj=0;j<3;j++)
    {
       UF_VEC3_dot(point_origin,vec[j],&point[j]);
    }
}
13,三点求圆心
#include<iostream.h>
# g& j  E% o. V" t  c#include<math.h> ' R" Z. w* Q: `# W! m! Q9 Z5 V

# }1 v2 _. J" c* }0 Mint main()
{
    int x1,y1,x3,y3;
    double a,b,c,d,e,f;
    doubler,k1,k2,x,y,x2,y2;
    cout<<"请输入x1,y1,x2,y2,x3,y3"<<endl;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    if((y1==y2)&&(y2==y3))
    {
       cout<<"三点不构成圆!"<<endl;
       return 0;
    }
    if((y1!=y2)&&(y2!=y3))
    {
       k1=(x2-x1)/(y2-y1);
       k2=(x3-x2)/(y3-y2);
    }
    if(k1==k2)
    {
       cout<<"三点不构成圆!"<<endl;
       return 0;
    }
. V/ c. L  K! m# N5 h
    a=2*(x2-x1);
    b=2*(y2-y1);
    c=x2*x2+y2*y2-x1*x1-y1*y1;
    d=2*(x3-x2);
    e=2*(y3-y2);
    f=x3*x3+y3*y3-x2*x2-y2*y2;
    x=(b*f-e*c)/(b*d-e*a);
    y=(d*c-a*f)/(b*d-e*a);
    cout<<"圆心为("<<x<<","<<y<<")"<<endl;
    r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
    cout<<"半径为"<<r<<endl;
    return 0;
}
14,查找圆心
       UF_EVAL_p_tevaluator ;
       UF_EVAL_arc_tarc ;
       UF_EVAL_initialize(obj_tag,&evaluator);
       UF_EVAL_ask_arc(evaluator,&arc);
       UF_VEC3_copy(arc.center,point);   
15, message_box
void message_box(int *res_mes)
{
    UF_UI_message_buttons_sbuttons;
    buttons.button1=TRUE;
    buttons.button2=FALSE;
    buttons.button3=TRUE;
   
    buttons.label1="OK";
    buttons.label3="CANEL";
            
    buttons.response1=UF_UI_OK;
    buttons.response3=UF_UI_CANCEL;
            
    char *string_msg;
    char*material_msg="ALL selcted objects will be removed";
    string_msg =material_msg;
            
    UF_CALL(UF_UI_message_dialog("",
       UF_UI_MESSAGE_WARNING,
8 ]+ X7 q( [: a: y" m
        &material_msg,
       1,
       TRUE,
       &buttons,
        res_mes ));
}
16,选择过滤
static int init_add_face( UF_UI_selection_p_t select, void *client_data)
{
    int nums = 1;
    UF_UI_mask_tmasks[] = {
       UF_solid_type,0, UF_UI_SEL_FEATURE_ANY_FACE};
   
       if(
           (UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,nums,masks)==0)
           &&(UF_UI_set_sel_procs(select,filter_proc_circle,NULL,client_data)==0)
           )
       {
           return(UF_UI_SEL_SUCCESS);
       }
       else
       {   
           return(UF_UI_SEL_FAILURE);
       }
}
int find_tag(
             void * client_data,//用以传输过滤资料
            tag_t object//现在鼠标所选物体ID
            )
{
    user_data *obj;
    obj=(user_data*)client_data;
    int find_face=true;//接受
    char *string1;

+ D6 X6 I( f4 |; S+ g* [( m9 ~; z    string1=newchar[133];
    string1=UF_TAG_ask_handle_of_tag(object);
    for(int i=0;i<过滤的数目;i++)
    {
   
       char *string2;
       string2=newchar[133];
       string2=UF_TAG_ask_handle_of_tag(物体ID);
       if(strcmp(string1,string2)==0)
       {
           find_face=FALSE;//不接受
           
       }
       delete[]string2;
    }
    delete []string1;
    return find_face;
  v3 N/ g1 |1 o7 v: h+ Y+ Y  |# w
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

全部回复1

潜行者 发表于 2013-11-28 15:44:45

潜行者 沙发

2013-11-28 15:44:45

这大好模板,支持
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了