cag 发表于 2003-7-8 12:33:00

这是我去年刚学VBA是写的一个三维螺旋线程序

ningyong58 发表于 2009-3-20 09:23:00

<p>好好学习这段程序,在工作中比较有用.</p><p>还有MJTD的VBA函数</p><p>函数名:<b>AddHelix</b></p><p>&nbsp;<a href="http://www.mjtd.com/function/list.asp?id=76&amp;ordertype=byletter">http://www.mjtd.com/function/list.asp?id=76&amp;ordertype=byletter</a></p><p>Public Function AddHelix(varCentPnt As Variant, _<br/>dblRadius As Double, dblStartAng As Double, _<br/>dblPitch As Double, dblRot As Double) As Acad3DPolyline<br/>&nbsp;&nbsp;Dim objPoly As Acad3DPolyline<br/>&nbsp;&nbsp;Dim objSpace As AcadBlock<br/>&nbsp;&nbsp;Dim objUtil As AcadUtility<br/>&nbsp;&nbsp;Dim varSegments As Variant<br/>&nbsp;&nbsp;Dim dblSegInclAng As Double<br/>&nbsp;&nbsp;Dim dblSegPitch As Double<br/>&nbsp;&nbsp;Dim dblSegAng As Double<br/>&nbsp;&nbsp;Dim varPitchPnt As Variant<br/>&nbsp;&nbsp;Dim intCnt As Integer<br/>&nbsp;&nbsp;Dim dblPnts() As Double<br/>&nbsp;&nbsp;Dim intLoopCnt As Integer<br/>&nbsp;&nbsp;Dim intVertCnt As Integer<br/>&nbsp;&nbsp;Dim intCoordCnt As Integer<br/>&nbsp;&nbsp;On Error GoTo Err_Control<br/>&nbsp;&nbsp;If ThisDrawing.ActiveSpace = acModelSpace Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;Set objSpace = ThisDrawing.ModelSpace<br/>&nbsp;&nbsp;Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;Set objSpace = ThisDrawing.PaperSpace<br/>&nbsp;&nbsp;End If<br/>&nbsp;&nbsp;Set objUtil = ThisDrawing.Utility<br/>&nbsp;&nbsp;varSegments = ThisDrawing.GetVariable("SURFTAB1")<br/>&nbsp;&nbsp;dblSegInclAng = (2 * (Atn(1) * 4)) / varSegments<br/>&nbsp;&nbsp;dblSegPitch = dblPitch / varSegments<br/>&nbsp;&nbsp;dblSegAng = dblStartAng - dblSegInclAng<br/>&nbsp;&nbsp;intLoopCnt = CInt(1 + (varSegments * dblRot))<br/>&nbsp;&nbsp;ReDim dblPnts((intLoopCnt * 3) - 1)<br/>&nbsp;&nbsp;For intCnt = 1 To intLoopCnt<br/>&nbsp;&nbsp;&nbsp;&nbsp;dblSegAng = dblSegInclAng + dblSegAng<br/>&nbsp;&nbsp;&nbsp;&nbsp;varPitchPnt = objUtil.PolarPoint(varCentPnt, _<br/>&nbsp;&nbsp;&nbsp;&nbsp;dblSegAng, dblRadius)<br/>&nbsp;&nbsp;&nbsp;&nbsp;varCentPnt(2) = varCentPnt(2) + dblSegPitch<br/>&nbsp;&nbsp;&nbsp;&nbsp;For intVertCnt = 0 To 2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dblPnts(intCoordCnt) = varPitchPnt(intVertCnt)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intCoordCnt = intCoordCnt + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;Next<br/>&nbsp;&nbsp;Next intCnt<br/>&nbsp;&nbsp;Set objPoly = objSpace.Add3DPoly(dblPnts)<br/>&nbsp;&nbsp;Set AddHelix = objPoly<br/>Exit_Here:<br/>&nbsp;&nbsp;Exit Function<br/>Err_Control:<br/>&nbsp;&nbsp;Select Case Err.Number<br/>&nbsp;&nbsp;'Cases here<br/>&nbsp;&nbsp;Case Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox Err.Description<br/>&nbsp;&nbsp;&nbsp;&nbsp;Err.Clear<br/>&nbsp;&nbsp;&nbsp;&nbsp;Resume Exit_Here<br/>&nbsp;&nbsp;End Select<br/>End Function <td></td></p>
页: [1]
查看完整版本: 这是我去年刚学VBA是写的一个三维螺旋线程序