帮我看看这个程序,怎么出错了?
<p>这是一个VB与CAD二次开发的程序,是关于直齿齿轮切齿的程序,程序如下:</p><p>Option Explicit<br/>Dim 齿轮CAD As acadapplication<br/>Private Sub form_load()<br/> Me.Caption = "齿轮加工三维动画仿真"<br/> Me.Left = (Screen.Width - Me.Width)<br/> Me.Top = 0<br/> Me.label1 = "齿数"<br/> Me.label2 = "模数"<br/> Me.label3 = "压力角"<br/> Me.commandl.Caption = "确定"<br/> Me.Command2.Caption = "取消"<br/> Me.Text1 = 18<br/> Me.Text2 = 5<br/> Me.Text3 = 20<br/> On Error Resume Next<br/> Set 齿轮CAD = GetObject(, "autocad,application")<br/> If Err Then<br/> Err.Clear<br/> Set 齿轮CAD = CreateObject("autocad.application")<br/> If Err Then<br/> MsgBox ("请先安装autocad2007")<br/> Unload Me<br/> Exit Sub<br/> End If<br/> End If<br/> 齿轮CAD.WindowState = acmax<br/>End Sub<br/>Private Sub commandl_click()<br/> On Error Resume Next<br/> 齿轮CAD.activedocument.Close<br/> 齿轮CAD.documents.Add<br/> Dim CZ, CM, CA, CR, CRb, CRa, CR, f, CSb, Umax, U, B<br/> Dim Th(3)<br/> Dim I<br/> CZ = Me.Text1<br/> CM = Me.Text2<br/> CA = Me.Text3 * 3.141 / 180<br/> Dim newdirection(0 To 2) As Double<br/> newdirection(0) = 1: newdirection(1) = 0.5: newdirection(2) = 0.5<br/> 齿轮CAD.activedocument.activeviewport.direction = newdirection<br/> 齿轮CAD.activedocument.activeewport = _<br/> 齿轮CAD.activedocument.layers(0).Color = acred<br/> 齿轮CAD.activedocument.sendcommand "_shademode" + vbCr + "_g" + vbCr<br/> <br/> <br/> <br/> CR = CM * CZ / 2<br/> CRf = (CR - 1.25 * CM)<br/> CRb = CR * Cos(CA)<br/> CRa = CR + CM<br/> <br/> <br/> Dim 齿轮3d As acad3dsolid<br/> Dim centerpoint(0 To 2) As Double<br/> centerpoint(0) = 0#: centerpoint(1) = 0#: centerpoint(2) = 0#<br/> Dim height As Double<br/> height = CRa / 3 / 3<br/> Set 齿轮3d = 齿轮CAD.activedocument.modeispace.addcylinder_(centerpoiny, CRa / 3, height)<br/> 齿轮3d.Boolean acsubtraction, 轴孔<br/> 齿轮3d.Color = acblue<br/> zoomall<br/> Dim plineobj(0) As acadlwpolyline<br/> CSb = Cos(CA) * (3.14 * CM / 2 + CM * CZ * (Tan(CA - (CA))))<br/> Th(1) = (3.14 * CM * Cos(CA) - CSb) / (2 * CRb)<br/> Th(0) = Th(1) / 3<br/> Th(2) = Th(1) + Tan(CA) - CA</p><p> Th(3) = Th(1) + Tan(Acos(CRb / CRa)) - Acos(CRb / CRa)<br/> <br/> Dim curves(0 To 5) As acadentily<br/> Dim points0(0 To 5) As Double<br/> Dim points1(0 To 8) As Double<br/> Dim points2(0 To 5) As Double<br/> <br/> points0(0) = 0: points0(1) = CRf<br/> points0(2) = CRf * Sin(Th(0)): points0(3) = CRf * Cos(Th(0))<br/> points0(4) = CRb * Sin(Th(1)): points0(5) = CRb * Cos(Th(1))<br/> <br/> Dim startTan(0 To 2) As Double<br/> Dim endtan(0 To 2) As Double<br/> start Tan(0) = 0: startTan(1) = 0: startTan(2) = 0<br/> endtan(0) = 0.5: endtan(1) = 0.5: endtan(2) = 0<br/> <br/> points1(0) = points0(4): points1(1) = points0(5): points1(2) = 0<br/> points1(3) = CR * Sin(Th(2)): points1(4) = CR * Cos(Th(2)): points1(5) = 0<br/> points1(6) = CRa * Sin(Th(3)): points1(7) = CRa * Cos(Th(3)): points1(8) = 0<br/> points2(0) = points1(6): points2(1) = points1(7)<br/> points2(2) = points1(6): points2(3) = points1(7) + 2.25 * CM<br/> points2(4) = 0: points2(5) = points2(3)<br/> <br/> <br/> If CRb < CRf Then<br/> points0(2) = points1(3) * 0.2: points0(3) = points0(1) + 0.25 * CM * 0.03<br/> points0(4) = points1(3) * 0.7: points0(5) = points0(1) + 0.25 * CM * 0.8<br/> points1(0) = points0(4): points1(1) = points0(5): points1(2) = 0<br/> End If<br/> <br/> Set curves(0) = 齿轮CAD.activedoument.modelspace.addlightweightpolyline(points0)<br/> curves(0).sotbulge1 , 0.2<br/> Set curves(1) = 齿轮CAD.activedocument.modelspace.addspline(points1, startTan, endtan)<br/> Set curves(2) = 齿轮CAD.activedocumentmodelspace.addlightweighpolyline(points2)<br/> <br/> Dim point1(0 To 2) As Double<br/> Dim point2(0 To 2) As Double<br/> point1(0) = 0: point1(1) = 0: point1(2) = 0<br/> point2(0) = 0: point2(1) = 1: point2(2) = 0<br/> <br/> Set curves(3) = curves(2).mirror(point1, point2)<br/> Set curves(4) = curves(1).mirror(point1, point2)<br/> Set curves(5) = curves(0).mirror(point1, point2)<br/> <br/> Dim 刀具 As Variant<br/> 刀具 = 齿轮CAD.activedocument.modelspace.addregion(curves)<br/> Dim axispt(0 To 2) As Double<br/> Dim axisdir(0 To 2) As Double<br/> Dim angle As Double<br/> axispt(0) = 0: axispt(1) = points2(5) + 2 * CM: axispt(2) = 0<br/> axisdir(0) = 1: axisdir(1) = 0: axisdir(2) = 0<br/> angle = 6.29<br/> <br/> Dim 刀具3d As acad3dsolid<br/> Set 刀具3d = 齿轮CAD.activedocument.modelspace.addrevolvedsolid(刀具(0), axispt, axisdir, angle)<br/> <br/> zoomall<br/> <br/> Dim boxobj As acad3dsolid<br/> Dim center(0 To 2) As Double<br/> Dim taperangle As Double<br/> taperangle = 0<br/> <br/> <br/> center(0) = 0: center(1) = CRf: center(2) = 0<br/> Set boxobj = 齿轮CAD.activedocument.modelspace.addbox(center, CM / 2, 4 * CM, pints(0) * 2)<br/> <br/> Dim retobj As Variant<br/> retobj = boxobj.arraypolar(20, 6.28, 刀具3d.centroid)<br/> For I = 0 To 20 - 2<br/> retobj(I).rotate3dcenter , centerpoint, 3.14 / 2<br/> retobj(I).Update<br/> 刀具3d.Boolean acsubtraction, retobj(I)<br/> Next I<br/> Dim 刀具bool As acad3dsolid<br/> Set 刀具bool = 齿轮CAD.activedocument.modelspaceaddextrudedsolid(刀具(0), height, taperangle)<br/> axispt(0) = 刀具bool.centroid(0)<br/> axispt(1) = 刀具bool.centroid(1)<br/> axispt(2) = 0<br/> <br/> 刀具bool.move刀具bool.centroid , axispt<br/> <br/> 刀具bool.Move.Visible = False<br/> axispt(0) = 刀具3d.centroid(0) + 10<br/> axispt(1) = 刀具3d.centroid(1)<br/> axispt(2) = 刀具3d.centroid(2)<br/> point1(0) = 刀具3d.centroid(0)<br/> point1(1) = 刀具3d.centroid(1)<br/> point1(2) = 刀具3d.centroid(2) + height<br/> <br/> 刀具3d.move刀具3d.centroid , point1<br/> Dim entry As acadentity<br/> For Each entry In 齿轮CAD.activedocument.modelspace<br/> If entry.objectID <> 齿轮3d.objectID And entry.objectID <> 刀具3d.objectID And entry.objectID <> 刀具bool.objectID Then entry.Delete<br/> End If<br/> Next<br/> Dim 刀具复制 As acad3dsolid<br/> Dim k<br/> I = 0<br/> Dim 刀具3dz坐标 As Double<br/> 刀具3dz坐标 = 刀具3d.centroid(2)<br/> <br/> Do Until I > 360<br/> <br/> For k = 刀具3dz坐标 To 刀具3dz坐标 - height Step -height / 3<br/> point1(2) = k<br/> 刀具3d.move刀具3d.centroid , point1<br/> 刀具3d.Update<br/> <br/> axispt(2) = 刀具3d.centroid(2)<br/> 刀具3d.rotate3d刀具3d.centroid , axispt, 360 / 30 * 3.141 / 180<br/> 刀具3d.Update<br/> Next k<br/> <br/> Set 刀具复制 = 刀具bool.Copy<br/> 齿轮3d.Boolean acsubtraction, 刀具复制<br/> 齿轮3d.Update<br/> <br/> point1(2) = point1(2) + height<br/> <br/> 刀具3d.move刀具3d.centroid , point1<br/> 刀具3d.Update<br/> <br/> 齿轮3d.rotate centerpoint, -360 / CZ * 3.141 / 180<br/> 齿轮3d.Color = acblue<br/> 齿轮3d.Update<br/> I = 360 / CZ + I<br/> Loop</p><p></p><p>End Sub</p><p>Private Sub command2_click()<br/>Me.Text1 = 18<br/>Me.Text2 = 5<br/>Me.Text3 = 20<br/>End Sub</p><p></p><p>公共模块代码<br/>option explicit<br/>public function Acos(x)<br/>dim sinx,cosx,tanx<br/> if x=0 then Acos=3.14159/2#<br/> if x>0 then<br/> sinx=sqr(1#-x^2)<br/> cosx=x<br/> tanx=sinx/cosx<br/> Acos=Atn(tanx)<br/> if x<0 then<br/> sinx=-sqr(1#-x^2)<br/> cosx=x<br/> tanx=sinx/cosx<br/> Acos=Atn(tanx)+3.14159<br/> end if<br/>end function<br/>但调试时出现:未找到方法或数据成员,这是怎么回事?</p>
页:
[1]