第一章渐开线直齿轮的二次开发Word文档格式.docx
《第一章渐开线直齿轮的二次开发Word文档格式.docx》由会员分享,可在线阅读,更多相关《第一章渐开线直齿轮的二次开发Word文档格式.docx(21页珍藏版)》请在冰豆网上搜索。
do/l20:
ak,0,36
rk=0.5*db/cosf(ak)
ok=sinf(ak)/cosf(ak)-ak*&
pi/180
xk=rk*cosf(ok*180/&
pi)
yk=rk*sinf(ok*180/&
pp(ak+1)=point/xk,yk
l20:
(2)渐开线直齿轮的参数
d=m*z
db=d*cosf(a)
da=d+2*ha*m
df=d-2*(ha+c)*m
s=&
pi*m/2
ra=da/2
rd=d/2
rf=df/2
rb=db/2
其中是m模数,z是齿数,a是压力角,ha是齿顶高系数,c是径向间隙系数,d是分度圆直径,db是基圆直径,da是齿顶圆直径,df是齿根圆直径,s是分度圆上齿轮的厚度。
(3)Grip程序的实现
number/m,z,a,w,ha,c
number/mat(12),mat1(12),mat2(12),mat3(12),mat4(12)
data/ha,1,c,0.25
entity/involute,gda,gdb,gdf,gd,invo_rot,pt_mir,ln_mir,invo_mir,ln1,invo_ln
entity/pp(37),pt,pt1,pt2,pt3,pt4,pt5,pt6,pt7(1000),curda,curdf,pp2,ptori
entity/solid,shape(1000),shape1(1000),shape2(1000)
entity/shape3(1000),shape4(1000),shape5(1000)
ufargs/m,z,a,w
ifthen/z>
120
messg/'
输入齿数超过‘120’!
'
jump/stop:
endif
d=m*z
do/l20:
gda=circle/0,0,0,ra
gd=circle/0,0,0,rd
gdf=circle/0,0,0,rf
gdb=circle/0,0,0,rb
involute=spline/pp
crvtrm/involute,ref,pp(37),first,gda,notrim,status,stus
view/7
pt=point/intof,gd,involute
mat=matrix/xyrot,(s/rd)*(180/&
pi)/2
pt_mir=transf/mat,pt
ptori=point/0,0,0
ln_mir=line/ptori,pt_mir,perpto,gda
blank/gda,gdf
ifthen/df<
db
ln1=line/pp
(1),pp
(1),tanto,involute
pp2=point/xlarge,intof,ln1,gdf
delete/ln1
ln1=line/pp
(1),pp2
mat1=matrix/mirror,ln_mir
invo_mir=transf/mat1,involute
invo_ln=transf/mat1,ln1
pt4=point/intof,gda,ln_mir
pt5=point/intof,gda,involute
pt6=point/intof,gda,invo_mir
curda=circle/pt5,pt4,pt6
pt1=point/intof,gdf,ln1
mat4=matrix/xyrot,360/z
pt1=transf/mat4,pt1
pt2=point/intof,gdf,invo_ln
pt3=point/intof,gdf,ln_mir
pt7
(1)=pt3
j=1
do/l30:
i,1,2*z-1
mat3=matrix/xyrot,i*180/z
ifthen/modf(i,2)<
>
pt7(j+1)=transf/mat3,pt7
(1)
j=j+1
l30:
curdf=circle/pt2,pt7
(2),pt1
shape
(1)=involute
shape1
(1)=ln1
shape2
(1)=curdf
shape3
(1)=invo_ln
shape4
(1)=invo_mir
shape5
(1)=curda
do/l40:
i,1,z-1
mat2=matrix/xyrot,i*360/z
shape(i+1)=transf/mat2,shape
(1)
shape1(i+1)=transf/mat2,shape1
(1)
shape2(i+1)=transf/mat2,shape2
(1)
shape3(i+1)=transf/mat2,shape3
(1)
shape4(i+1)=transf/mat2,shape4
(1)
shape5(i+1)=transf/mat2,shape5
(1)
l40:
mask/2
delete/all
mask/3
blank/all
mask/5
mask/9
solid=solext/shape(1..z),shape1(1..z),shape2(1..z),$
shape3(1..z),shape4(1..z),shape5(1..z),$
height,w,axis,0,0,1
else
crvtrm/involute,ref,pp
(1),first,gdf,notrim,status,stus
pt1=point/intof,gdf,involute
pt2=point/intof,gdf,invo_mir
do/l50:
l50:
shape1
(1)=curdf
shape2
(1)=invo_mir
shape3
(1)=curda
do/l60:
l60:
shape3(1..z),height,w,axis,0,0,1
stop:
halt
(4)编译和连接
对UG/OpenGrip程序通过UG自身带的NXOpenGrip进行编译和连接,生成*.grx文件,之后就能在启动UG之后进行调用,进行自动建模了。
三、用户界面设计
编译完成的Grip程序在使用时需要用户进行手动调用,在实际运用时可能会存在麻烦,所以可以进行对用户友好的界面设计,从而更进一步简化设计过程。
1.UG应用开发环境设计
(1)新建文件夹,并在该文件夹下建立startup和application连个文件夹,startup子文件夹用于放置菜单以及dll文件,application子文件夹用于放置对话框文件*.dlg。
(2)注册环境变量,新建变量名“UGII_USER_DIR”,变量值为上述文件夹的地址。
这样,以便UG在进行程序调用时成功能进行动态链接。
如图1所示。
图1环境变量设置
2.菜单设计
在startup文件夹下,新建菜单文件(.men),内容如下:
VERSION120
EDITUG_GATEWAY_MAIN_MENUBAR
AFTERUG_APPLICATION
CASCADE_BUTTONgear_menu
LABEL齿轮参数化设计系统
END_OF_AFTER
MENUgear_menu
BUTTONzgear
LABEL渐开线直齿轮
ACTIONSzgear.dlg
END_OF_MENU
上面的脚本程序将添加菜单栏项目如图2所示:
图2菜单栏
3.UIStyler对话框设计
启动UG的UIStyler制作对话框界面,完成后的对话框界面如图3所示。
图3对话框界面
在此对话框中有5个文本框,【确定】按钮和【取消】按钮,对话框及对话框中各控件的属性如图4和图5所示。
图4 对话框属性
图5对话框属性的定义
在此对话框中,定义了4个回调函数。
Cancel按钮回调函数cancel_zgear,构造回调函数constructor_zgear,析构回调函数destructor_zgear,OK按钮回调函数ok_zgear,如图6所示。
图6 回调函数的定义
最后,将制作完成的对话框另存至上述建立的application文件夹中。
4.使用VisualC++建立应用程序框架
编写相应的回调函数,代码如下:
(1)框架源程序:
#ifndefZGEAR_H_INCLUDED
#defineZGEAR_H_INCLUDED
#include<
uf.h>
#include<
uf_defs.h>
uf_styler.h>
#ifdef__cplusplus
extern"
C"
{
#endif
#defineZGEAR_NUM("
NUM"
)
#defineZGEAR_M("
M"
#defineZGEAR_Z("
Z"
#defineZGEAR_A("
A"
#defineZGEAR_W("
W"
#defineZGEAR_DIALOG_OBJECT_COUNT(5)
intZGEAR_constructor_zgear(intdialog_id,
void*client_data,
UF_STYLER_item_value_type_p_tcallback_data);
intZGEAR_donstructor_zgear(intdialog_id,
intZGEAR_ok_zgear(intdialog_id,
intZGEAR_cancel_zgear(intdialog_id,
voidwrite_para(intdialog_id);
}
#endif/*ZGEAR_H_INCLUDED*/
(2)对话框源程序:
stdlib.h>
stdio.h>
uf_exit.h>
uf_ui.h>
uf_mb.h>
math.h>
#include"
zgear.h"
#defineZGEAR_CB_COUNT(4+1)
UF_STYLER_item_value_type_tdata[5];
staticUF_STYLER_callback_info_tZGEAR_cbs[ZGEAR_CB_COUNT]=
{
{UF_STYLER_DIALOG_INDEX,UF_STYLER_CONSTRUCTOR_CB,0,ZGEAR_constructor_zgear},
{UF_STYLER_DIALOG_INDEX,UF_STYLER_DESTRUCTOR_CB,0,ZGEAR_donstructor_zgear},
{UF_STYLER_DIALOG_INDEX,UF_STYLER_OK_CB,0,ZGEAR_ok_zgear},
{UF_STYLER_DIALOG_INDEX,UF_STYLER_CANCEL_CB,0,ZGEAR_cancel_zgear},
{UF_STYLER_NULL_OBJECT,UF_STYLER_NO_CB,0,0}
};
staticUF_MB_styler_actions_tactions[]={
{"
zgear.dlg"
NULL,ZGEAR_cbs,UF_MB_STYLER_IS_NOT_TOP},
{NULL,NULL,NULL,0}
//#ifdefMENUBAR_COMMENTED_OUT
externvoidufsta(char*param,int*retcode,intrlen)
interror_code;
if((UF_initialize())!
=0)
return;
if((error_code=UF_MB_add_styler_actions(actions))!
=0)
charfail_message[133];
UF_get_fail_message(error_code,fail_message);
printf("
%s\n"
fail_message);
}
UF_terminate();
//#endif
#ifdefDISPLAY_FROM_CALLBACK
externint<
enterthenameofyourfunction>
(int*response)
interror_code=0;
if((error_code=UF_initialize())!
=0)
return(0);
if((error_code=UF_STYLER_create_dialog("
ZGEAR_cbs,
ZGEAR_CB_COUNT,
NULL,/
response))!
UF_UI_set_status(fail_message);
return(error_code);
#endif
#ifdefDISPLAY_FROM_USER_EXIT
externvoid<
enteravaliduserexithere>
(char*param,int*retcode,intrlen)
intresponse=0;
if((UF_initialize())!
ZGEAR_cbs,/*Callbacksfromdialog*/
ZGEAR_CB_COUNT,/*numberofcallbacks*/
NULL,/*Thisisyourclientdata*/
&
response))!
externintufusr_ask_unload(void)
return(UF_UNLOAD_IMMEDIATELY);
externvoidufusr_cleanup(void)
UF_STYLER_item_value_type_p_tcallback_data)
if(UF_initialize()!
return(UF_UI_CB_CONTINUE_DIALOG);
UF_terminate();
return(UF_UI_CB_CONTINUE_DIALOG);
UF_STYLER_item_value_type_tnum;
num.item_attr=UF_STYLER_VALUE;
num.item_id=ZGEAR_NUM;
UF_STYLER_ask_value(dialog_id,&
num);
if((num.value.string)=="
"
uc1601("
齿轮号不能为空!
1);
return(UF_UI_CB_CONTINUE_D