我是在用VB编写的凸轮机构的参数化设计的程序,然后调用CAD出图。VB的程序运行都没有问题,也在picturebox里看到了静态的凸轮。但CAD里却没有任何的图形和线段。
不知道问题出在那里了,各位大侠给我那个主吧!
我程序是参考别人编的。
Private Sub Command5_Click()
'首先引用 acad 2008 Object Library类型库
Dim myAcadApp As autocad.AcadApplication
Dim activeDoc As autocad.AcadDocument
Dim acMS As autocad.AcadModelSpace
On Error Resume Next
Set myAcadApp = GetObject(, "Autocad.Application") '检查AutoCAD是否已经打开
If Err Then '没有打开
Err.Clear
Set myAcadApp = CreateObject("Autocad.Application") '打开CAD
If Err Then
MsgBox ("不能运行AUTOCAD,请检查")
Unload Me
Exit Sub
End If
End If
myAcadApp.WindowState = autocad.acMin
'1.创建样条曲线
Dim curves As autocad.AcadSpline
Dim fitPoints(0 To 360 * 3) As Variant
Dim startTangent(0 To 2) As Double
Dim endTangent(0 To 2) As Double
Dim noOfpoints As Single
For i = 0 To 360
fitPoints(3 * i) = X(i): fitPoints(3 * i + 1) = Y(i):fitPoints(3 * i + 2) = 0 'X(i),Y(i)是尖顶凸轮的廓线上点的坐标
Next i
startTangent(0) = 0.5: startTangent(1) = 0.5: startTangent(2) = 0
endTangent(0) = 0.5: endTangent(1) = 0.5: endTangent(2) = 0
noOfpoints = 3
Set curves = myAcadApp.ActiveDocument.ModelSpace.AddSpline(fitPoints, startTangent, endTangent)
'2.创建面域
Dim regionObj As Variant
regionObj = myAcadApp.ActiveDocument.ModelSpace.AddRegion(curves)
Dim tulun3D As autocad.Acad3DSolid
Dim height As Double
Dim taperAngle As Double
height = 100: taperAngle = 45
Set tulun3D = myAcadApp.ActiveDocument.ModelSpace.AddExtrudedSolid(regionObj(0), height, taperAngle)
End Sub
当然用的2008版本的