明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1342|回复: 0

[求助]关于轻便多义线绘制?

[复制链接]
发表于 2010-5-14 16:40:00 | 显示全部楼层 |阅读模式

我要做齿轮造型,程序如下:

  Sub 齿轮刀具()
        Dim R, Rf, Rb, Ra As Single

        R = m * Z / 2 '齿轮分度圆半径
        Rf = (R - 1.25 * m) '齿轮根圆半径
        Rb = R * Cos(Af)  '齿轮基圆半径
        Ra = R + m ' 齿轮顶圆半径

        '根据渐开线公式,计算渐开线上各点坐标
        Dim Sb, th(3)
        Sb = Cos(Af) * (3.14 * m / 2 + m * Z * (Tan(Af) - (Af)))   ' 齿轮基圆齿厚
        th(1) = (3.14 * m * Cos(Af) - Sb) / (2 * Rb)
        th(0) = th(1) / 3
        th(2) = th(1) + Tan(Af) - Af
        th(3) = th(1) + Tan(Acos(Rb / Ra)) - Acos(Rb / Ra)

        Dim curves(5) As AcadEntity
        Dim points0(5) As Double
        Dim points1(8) As Double
        Dim points2(5) As Double

        points0(0) = 0 : points0(1) = Rf '第0点
        points0(2) = Rf * Sin(th(0)) : points0(3) = Rf * Cos(th(0)) '第1点
        points0(4) = Rb * Sin(th(1)) : points0(5) = Rb * Cos(th(1)) '第2点

        Dim startTan(2) As Double
        Dim endTan(2) As Double
        startTan(0) = 0 : startTan(1) = 0 : startTan(2) = 0
        endTan(0) = 0.5 : endTan(1) = 0.5 : endTan(2) = 0

        points1(0) = points0(4) : points1(1) = points0(5) : points1(2) = 0 '第2点
        points1(3) = R * Sin(th(2)) : points1(4) = R * Cos(th(2)) : points1(5) = 0 '第3点
        points1(6) = Ra * Sin(th(3)) : points1(7) = Ra * Cos(th(3)) : points1(8) = 0 '第4点

        points2(0) = points1(6) : points2(1) = points1(7) '第4点
        points2(2) = points1(6) : points2(3) = points1(7) + 2.25 * m '第5点
        points2(4) = 0 : points2(5) = points2(3) '第6点

        '当基圆小于根圆,调整第1,第2点坐标,得到近似值
        If Rb < Rf Then
            points0(2) = points1(3) * 0.2 : points0(3) = points0(1) + 0.25 * m * 0.03 '第1点
            points0(4) = points1(3) * 0.7 : points0(5) = points0(1) + 0.25 * m * 0.8 '第2点
            points1(0) = points0(4) : points1(1) = points0(5) : points1(2) = 0 '第2点
        End If

        '创建右部线段
        curves(0) = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points0)     '由0,1,2点组成
        curves(0).SetBulge(1, 0.2) '第一点凸度为0.2
        curves(1) = AcadApp.ActiveDocument.ModelSpace.AddSpline(points1, startTan, endTan)     '由2,3,4点组成
        curves(2) = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points2)     '由4,5,6点组成

        '镜像右部线段,得到左部线段
        Dim point1(2) As Double
        Dim point2(2) As Double
        point1(0) = 0 : point1(1) = 0 : point1(2) = 0
        point2(0) = 0 : point2(1) = 1 : point2(2) = 0
        curves(3) = curves(2).Mirror(point1, point2)
        curves(4) = curves(1).Mirror(point1, point2)
        curves(5) = curves(0).Mirror(point1, point2)

        '创建面域
        刀具 = AcadApp.ActiveDocument.ModelSpace.AddRegion(curves)
        '创建面域
        Dim taperAngle As Double
        taperAngle = 0
        Dim solidObj As Acad3DSolid
        solidObj = AcadApp.ActiveDocument.ModelSpace.AddExtrudedSolid(刀具(0), B * 1.1, taperAngle)
        Dim center(2) As Double
        center(0) = 0 : center(1) = solidObj.Centroid(1) : center(2) = 0
        solidObj.Move(solidObj.Centroid, center)

        '环形阵列
        Dim basePnt(2) As Double
        basePnt(0) = 0 : basePnt(1) = 0 : basePnt(2) = 0.0#
        刀具 = solidObj.ArrayPolar(Z + 1, 2 * Pi, basePnt)
    End Sub

调试运行时   “红色字体”  语句出现错误,提示“未处理ComException,被呼叫方拒绝接收呼叫”。我是初学,那位高手能帮我看看是什么错误,谢谢!我用的软件AutoCAD2008,vs2008vb.net。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 22:30 , Processed in 0.153699 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表