CATIA齿轮.docx
- 文档编号:5382881
- 上传时间:2022-12-15
- 格式:DOCX
- 页数:24
- 大小:121.14KB
CATIA齿轮.docx
《CATIA齿轮.docx》由会员分享,可在线阅读,更多相关《CATIA齿轮.docx(24页珍藏版)》请在冰豆网上搜索。
CATIA齿轮
利用CATIA宏编写的VB程序,选择不同参数,在CATIA中生成相应参数齿轮。
工作界面
OptionBase1
DimrAsDouble'齿轮分度圆半径
DimrfAsDouble'齿根圆半径
DimrbAsDouble'基圆半径
DimraAsDouble'齿顶圆半径
DimxtAsDouble'设置临时坐标变量
DimytAsDouble
DimindexAsDouble'循环变量
DimpitchTAsDouble
DimdataT()AsDouble'齿轮模数数据
DimdataT2()AsDouble
ConstPI=3.14159265358979
PrivateSubSpinButton1_Change()
Form1.TextBox1.Text=CStr(Form1.SpinButton1.Value)
EndSub
PrivateSubForm_Initialize()
Form1.Label1.Caption="齿数z"
Form1.Label2.Caption="模数m"
Form1.TextBox1.Text="25"
Form1.Label3.Caption="齿厚B"
Form1.TextBox2.Text="20"
Form1.Label4.Caption="压力角α"
Form1.TextBox3.Text="20"
Form1.TextBox3.Enabled=False
Form1.Frame1.Caption="渐开线圆柱齿轮选项(&O)"
Form1.Label5.Caption="螺旋升角β"
Form1.TextBox4.Text="0"
Form1.Command1.Caption="创建"
Form1.Command2.Caption="取消"
Form1.SpinButton1.Value=Form1.TextBox1.Text
Form1.Label6.Caption="齿轮旋向"
Form1.ComboBox2.AddItem"直齿"
Form1.ComboBox2.AddItem"左旋"
Form1.ComboBox2.AddItem"右旋"
Form1.ComboBox2.ListIndex=0
Form1.TextBox4.Enabled=IIf(Form1.ComboBox2.Text="直齿",False,True)
ReDimdataT(22)'定义齿轮模数数据
dataT
(1)=4
dataT
(2)=4.5
dataT(3)=5
dataT(4)=5.5
Forindex=6To10
dataT(index-1)=index
Nextindex
Forindex=10To14
dataT(index)=dataT(index-1)+2
Nextindex
dataT(15)=22
dataT(16)=25
dataT(17)=28
dataT(18)=32
dataT(19)=36
dataT(20)=40
dataT(21)=45
dataT(22)=50
ReDimdataT2(22)
dataT2
(1)=0.1
dataT2
(2)=0.12
dataT2(3)=0.15
dataT2(4)=0.2
dataT2(5)=0.25
dataT2(6)=0.3
dataT2(7)=0.35
dataT2(8)=0.4
Forindex=9To14
dataT2(index)=dataT2(index-1)+0.1
Nextindex
Forindex=15To22
dataT2(index)=dataT2(index-1)+0.25
Nextindex
Forindex=LBound(dataT2)ToUBound(dataT2)
Form1.ComboBox1.AddItemdataT2(index)
Nextindex
Forindex=LBound(dataT)ToUBound(dataT)
Form1.ComboBox1.AddItemdataT(index)
Nextindex
Form1.ComboBox1.ListIndex=21'设置初始显示位置
EndSub
'purpose:
'Inputs:
mT:
'zT:
'aT:
'bT:
'B:
'LOrR:
PrivateSubComboBox2_Click()
DimpAsString
Form1.TextBox4.Enabled=IIf(Form1.ComboBox2.Text="直齿",False,True)
Form1.TextBox4.Text=IIf(Form1.TextBox4.Enabled,Form1.TextBox4.Text,"0")
IfVal(Form1.ComboBox2.ListIndex)=0Then
p=App.Path&"\直齿轮.jpg"
Picture1.Picture=LoadPicture(p)
EndIf
IfVal(Form1.ComboBox2.ListIndex)=1Then
p=App.Path&"\左旋齿轮.jpg"
Picture1.Picture=LoadPicture(p)
EndIf
IfVal(Form1.ComboBox2.ListIndex)=2Then
p=App.Path&"\右旋齿轮.jpg"
Picture1.Picture=LoadPicture(p)
EndIf
EndSub
PrivateSubCommand1_Click()
IfVal(Form1.TextBox1.Text)<14ThenMsgBox"为避免根切,齿轮最小齿数应大于等于14。
请重新输入齿数数据。
",vbExclamation+vbOKOnly:
ExitSub
CreateGeneralGearVal(Form1.ComboBox1.Text),Val(Form1.TextBox1.Text),Val(Form1.TextBox3.Text),Val(Form1.TextBox4.Text),Val(Form1.TextBox2.Text),Val(Form1.ComboBox2.ListIndex)
End
EndSub
PrivateSubCommand2_Click()
End
EndSub
PublicFunctionEvaluateX(ByValrbTAsDouble,ByValtAsDouble)AsDouble'注意这里的参数方程的取值范围为0~1
EvaluateX=rbT*Sin(t*PI/2)-rbT*t*PI/2*Cos(t*PI/2)
EndFunction
PublicFunctionEvaluateY(ByValrbTAsDouble,ByValtAsDouble)AsDouble'这里的参数t取值也为0~1
EvaluateY=rbT*Cos(t*PI/2)+rbT*PI*t/2*Sin(t*PI/2)
EndFunction
SubCreateGeneralGear(ByValmTAsDouble,ByValzTAsDouble,ByValaTAsDouble,ByValbTAsDouble,ByValBAsDouble,ByValLOrRAsInteger)
'个参数意义分别为模数m,齿数z,压力角alpha,螺旋升角beta,齿厚B(角度单位均为deg),直齿,左旋或右旋0,1,2
aT=aT/180*PI'转换角度单位deg到rad
r=zT*mT/2'计算齿轮各参数的值
rb=r*Cos(aT)
rf=r-1.25*mT
ra=r+1*mT
IfNot(Abs(bT)<0.0001OrLOrR=0)ThenpitchT=2*PI*ra*Tan((90-bT)*PI/180)
OnErrorResumeNext
SetCATIA=GetObject(,"CATIA.Application")
IfErr.Number<>0Then
SetCATIA=CreateObject("CATIA.Application")
CATIA.Visible=True
EndIf
OnErrorGoTo0
Setdocuments1=CATIA.Documents
SetpartDocument1=documents1.Add("Part")
Setpart1=partDocument1.Part
SetoriginElements1=part1.OriginElements
DimhybridBodies1AsObject
SethybridBodies1=part1.HybridBodies
DimhybridBody1AsObject
SethybridBody1=hybridBodies1.Add()
hybridBody1.Name="渐开线齿轮图形数据"
DimhybridShapeFactory1AsObject
SethybridShapeFactory1=part1.HybridShapeFactory
DimhybridShapePointCoord1AsObject
SethybridShapePointCoord1=hybridShapeFactory1.AddNewPointCoord(0#,0#,0#)
hybridShapePointCoord1.Name="原点"
hybridBody1.AppendHybridShapehybridShapePointCoord1'添加所添加的原点
part1.Update
Dimreference1AsObject
Setreference1=part1.CreateReferenceFromObject(hybridShapePointCoord1)'新建一个参考点(圆心)
DimhybridShapePlaneExplicit1AsObject
SethybridShapePlaneExplicit1=originElements1.PlaneXY
Dimreference2AsObject
Setreference2=part1.CreateReferenceFromObject(hybridShapePlaneExplicit1)'新建一个参考平面,定义在originElements类中决定
DimhybridShapeCircleCtrRad1AsObject
SethybridShapeCircleCtrRad1=hybridShapeFactory1.AddNewCircleCtrRad(reference1,reference2,False,r)'据中心点和参考面,半径画分度圆
hybridShapeCircleCtrRad1.Name="分度圆"
hybridBody1.AppendHybridShapehybridShapeCircleCtrRad1'在当前模型中显示已在数据层面添加的模型
SethybridShapeCircleCtrRad1=hybridShapeFactory1.AddNewCircleCtrRad(reference1,reference2,False,rb)'画基圆
hybridShapeCircleCtrRad1.Name="基圆"
hybridBody1.AppendHybridShapehybridShapeCircleCtrRad1
SethybridShapeCircleCtrRad1=hybridShapeFactory1.AddNewCircleCtrRad(reference1,reference2,False,rf)'画齿根圆
hybridShapeCircleCtrRad1.Name="齿根圆"
hybridBody1.AppendHybridShapehybridShapeCircleCtrRad1
SethybridShapeCircleCtrRad1=hybridShapeFactory1.AddNewCircleCtrRad(reference1,reference2,False,ra)'画齿顶圆
hybridShapeCircleCtrRad1.Name="齿顶圆"
hybridBody1.AppendHybridShapehybridShapeCircleCtrRad1
part1.Update
SethybridShapePlaneExplicit1=originElements1.PlaneXY
Setreference1=part1.CreateReferenceFromObject(hybridShapePlaneExplicit1)
DimhybridShapePointOnPlane1AsObject'通过循环的方法画由15个点组成的渐开线
Forindex=0To14
SethybridShapePointOnPlane1=hybridShapeFactory1.AddNewPointOnPlane(reference1,EvaluateX(rb,index*0.03),EvaluateY(rb,index*0.03))'用曲面库类(hybridshapefactory)的方法在所选参考平面上新建各渐开线点
hybridShapePointOnPlane1.Name="Point_"&CStr(index+1)
hybridBody1.AppendHybridShapehybridShapePointOnPlane1
Nextindex
part1.Update'更新当前零部件几何体
DimhybridShapeSpline1AsObject
SethybridShapeSpline1=hybridShapeFactory1.AddNewSpline()
hybridShapeSpline1.SetClosing0'设置样条曲线封闭样式为0(0为不封闭)
hybridShapeSpline1.SetSplineType0'设置样条曲线投影样式0为不投影,否则应额外设置相应的reference平面变量
DimhybridShapes1AsObject
SethybridShapes1=hybridBody1.HybridShapes
Forindex=2To16
SethybridShapePointOnPlane1=hybridShapes1.Item("Point_"&CStr(index-1))
Setreference1=part1.CreateReferenceFromObject(hybridShapePointOnPlane1)
hybridShapeSpline1.AddPointWithConstraintExplicitreference1,Nothing,-1#,1,Nothing,0#'顺序添加参考约束点以绘制样条曲线spline
Nextindex
hybridShapeSpline1.Name="渐开线曲线"
hybridBody1.AppendHybridShapehybridShapeSpline1'向现有模型中添加已经生成的样条曲线
part1.InWorkObject=hybridShapeSpline1
part1.Update
SethybridShapeCircleCtrRad1=hybridShapes1.Item("分度圆")'本段代码完成渐开线与分度圆相交点的绘制
Setreference1=part1.CreateReferenceFromObject(hybridShapeCircleCtrRad1)'建立相交命令的第一个参数
Setreference2=part1.CreateReferenceFromObject(hybridShapeSpline1)
DimhybridShapeIntersection1AsObject
SethybridShapeIntersection1=hybridShapeFactory1.AddNewIntersection(reference1,reference2)
hybridShapeIntersection1.Name="分度圆交点"
hybridBody1.AppendHybridShapehybridShapeIntersection1'添加所生成的相交线
part1.InWorkObject=hybridShapeIntersection1
part1.Update
'本段代码完成由原点到分度圆与渐开线交点的直线绘制
SethybridShapePointCoord1=hybridShapes1.Item("原点")
Setreference1=part1.CreateReferenceFromObject(hybridShapePointCoord1)
Setreference2=part1.CreateReferenceFromObject(hybridShapeIntersection1)
DimhybridShapeLinePtPt1AsObject
SethybridShapeLinePtPt1=hybridShapeFactory1.AddNewLinePtPt(reference1,reference2)
hybridShapeLinePtPt1.Name="定位直线1"
hybridBody1.AppendHybridShapehybridShapeLinePtPt1
part1.InWorkObject=hybridShapeLinePtPt1
part1.Update
'本段代码完成由定位直线1和定角弧所做出的定位直线2及其二者的角平分线
SethybridShapePointCoord1=hybridShapes1.Item("原点")'画定位圆弧1
Setreference1=part1.CreateReferenceFromObject(hybridShapePointCoord1)
SethybridShapeIntersection1=hybridShapes1.Item("分度圆交点")
Setreference2=part1.CreateReferenceFromObject(hybridShapeIntersection1)
Dimreference3AsObject
SethybridShapePlaneExplicit1=originElements1.PlaneXY
Setreference3=part1.CreateReferenceFromObject(hybridShapePlaneExplicit1)
DimhybridShapeCircleCtrPt1AsObject
SethybridShapeCircleCtrPt1=hybridShapeFactory1.AddNewCircleCtrPtWithAngles(reference1,reference2,reference3,False,0#,360/zT/2)
hybridShapeCircleCtrPt1.Name="圆弧1"
hybridBody1.AppendHybridShapehybridShapeCircleCtrPt1
part1.Update
SethybridShapePointCoord1=hybridShapes1.Item("原点")'画定位直线2
Setreference1=part1.CreateReferenceFromObject(hybridShapePointCoord1)
Setreference2=part1.CreateReferenceFromBRepName("BorderFVertex:
(BEdge:
(Brp:
(GSMCircle.5;2);None:
(Limits1:
();Limits2:
();-1);Cf11:
());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)",hybridShapeCircleCtrPt1)
SethybridShapeLinePtPt1=hybridShapeFactory1.AddNewLinePtPt(reference1,reference2)
hybridShapeLinePtPt1.Name="定位直线2"
hybridBody1.AppendHybridShapehybridShapeLinePtPt1
part1.Update
SethybridShapeLinePtPt1=hybridShapes1.Item("定位直线1")
Setreference1=part1.CreateReferenceFromObject(hybri
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CATIA 齿轮