明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1963|回复: 2

好版主,我在开发autocad的时候有出现小问题了!帮帮我了!

[复制链接]
发表于 2003-4-28 14:41:00 | 显示全部楼层 |阅读模式
好心的版主,您好!又来麻烦您了,我真不好意思!   
具体情况如下:我已经将visualbasic与AutoCAD2000通讯上了,为了画一个刀具的图,可画出来只有半边,怎么都不能使右边的这段2维多义线镜象到左边去(autocad画完右边的多义线就停了下来了)我查了好多质料,发现语法没有问题。希望您能告诉我问题的所在,在这里先谢谢您了!还有就是我这段程序如何在2维平面中创建一个面域(左右多义线合并为一个封闭的线框)啊?
    程序:
Private Sub Command1_Click()
On Error Resume Next
Dim wg As Double
wg = 10
Dim wd As Double
wd = 10
Dim wm As Double
wm = 10
cad.Document.Add
'转换视点
Dim newdirection(0 To 2) As Double
newdirection(0) = 1: newdirection(1) = 0.5: newdirection(2) = 0.5

cad.ActiveDocument.ActiveViewport.Direction = newdirection
cad.ActiveDocument.ActiveViewport = cad.ActiveDocument.ActiveViewport
cad.ActiveDocument.Layers(0).Color = acRed
cad.ActiveDocument.SendCommand "_shademode" + vbCr + "_g" + vbCr

'拉伸cad
'由于ZA型蜗杆轴向压力角为20度,得蜗杆齿高
Dim thdg As Double
Dim th1 As Double
Dim th2 As Double
thdg = 20 'thdg=(wd-wg)/2
th1 = 2 'th1=wm*3.14159/4-(wf-wd)*tan(20)/2
th2 = 5 'th2=wm*3.14159/2+.72794*wm

Dim curves(1) As AcadLWPolyline
Dim points(0 To 9) As Double

points(0) = wg / 2: points(1) = 0 '第1点
points(2) = wg / 2: points(3) = th1 '第2点
points(4) = wd / 2: points(5) = th2 '第3点
points(6) = wd / 2 + wm: points(7) = th2 '第4点
points(8) = wd / 2 + wm: points(9) = 0 '第5点

'创建刀具右部线段
Set curves(0) = cad.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)
curves(0).SetBulge 1, -0.3

Dim point1(0 To 1) As Double
Dim point2(0 To 2) As Double
point1(1) = -2: point1(1) = 0: point1(2) = 0
point2(1) = 2: point2(1) = 0: point2(2) = 0
'镜像刀具右部线段,得到左部线段
Set curves(1) = curves(0).Mirror(point1, point2)
Dim 刀具 As Variant
刀具 = cad.ActiveDocument.ModelSpace.AddRegion(curves)

'创建刀具面域(?不会了)
'拉伸刀具(面域)得到三维刀具实体
Dim height As Double
Dim angle As Double
height = 3
angle = 0 '弧度
'创建面域拉伸实体
Dim solidobj As Acad3DSolid
Set solidobj = cad.ActiveDocument.ModelSpace.AddExtrudedSolid(刀具, height, angle)
               
ZoomAll

End Sub
发表于 2003-4-28 20:12:00 | 显示全部楼层

程序有两个问题

1.以下语句:
Dim point1(0 To 1) As Double
Dim point2(0 To 2) As Double
point1(1) = -2: point1(1) = 0: point1(2) = 0
point2(1) = 2: point2(1) = 0: point2(2) = 0
中有两个问题:
point1(0 to 1)定义的数组只有两个元素,怎能容纳三个元素?所以要改为2
point1(1)=-2这里就错了,重复定义point1(1)以及point2(1),而point1(0)和point2(0)却没有定义。这样就造成了点重复的问题了。

2.在以下语句中:
Set solidobj = cad.ActiveDocument.ModelSpace.AddExtrudedSolid(刀具, height, angle)
注意,“刀具”变体数组保存着所生成的面域的数组,这里刀具有可能不只包含一个面域,具体要看给定曲线一共能生成多少个面域,所以该值为不定,所以在引用刀具值来生成实体时应用使用“刀具(0)”来引用其中的第一个面域,而不是引用刀具变体。

改完后,程序应该可以正常运行。
 楼主| 发表于 2003-4-28 20:43:00 | 显示全部楼层

好感激,好感激您,谢谢了!

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

本版积分规则

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

GMT+8, 2024-11-28 16:47 , Processed in 0.173257 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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