标题: vs2010和AUTOCAD2010环境下,的三维实体小球的运动 [打印本页] 作者: suishengyuan 时间: 2012-3-8 22:11 标题: vs2010和AUTOCAD2010环境下,的三维实体小球的运动 我看的一本书vb和AUTOCAD的二次开发,运行的是三维实体小球沿正玄曲线的运动,但是不能出结果,什么原因,环境是vs2010和AUTOCAD2010,能够运行,但是没有结果,只是能够打开AUTOCAD,但是里面没有图,求解,附代码,急啊,大侠们。
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports System.Math
Public Class Form1
Dim AcadApp As New AcadApplication 'AcadApplication是CAD对象接口
Dim acadDoc As AcadDocument 'AcadDocument是CAD文件
Dim moSpace As AcadModelSpace 'AcadModelSpace是模型空间
Dim paSpace As AcadPaperSpace 'AcadPaperSpace是图纸空间
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'On Error Resume Next
'完成AutoCAD的连接与启动
AcadApp = GetObject(, "AutoCAD.Application")
If Err.Number Then 'err.number=0表示没有出错 err.number<>0表示有错
Err.Clear()
AcadApp = CreateObject("AutoCAD.Application")
If Err.Number Then
MsgBox("不能运行AutoCAD 2010,请检查是否安装了AutoCAD2010")
Exit Sub
End If
End If
AcadApp.Visible = True
'Autocad窗口最大化
AcadApp.WindowState = AcWindowState.acMax
'acadDoc = AcadApp.ActiveDocument
'moSpace = acadDoc.ModelSpace
'paSpace = acadDoc.PaperSpace
'设置Gouraud着色
AcadApp.ActiveDocument.SendCommand("_Shademode" + vbCr + "_G" + vbCr)
'时钟初始化
Me.Timer1.Interval = 1 '设置当前定时器的间隔时间
Me.Timer1.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Timer1.Enabled = Not Me.Timer1.Enabled
End Sub
Private Sub Timer1_Timer()
Dim Xmax As Single
Dim Ymax As Single
Xmax = AcadApp.ActiveDocument.Width / 1.2
Ymax = AcadApp.ActiveDocument.Height / 3
'创建spline为轨迹
'---------------------------------------------------
Dim splineObj As AcadSpline '样条曲线
Dim noOfPoints As Integer
Dim startTan(0 To 2) As Double
Dim endTan(0 To 2) As Double
Dim fitPoints(0 To 35 * 3 + 2) As Double
noOfPoints = 36
startTan(0) = 0.5 : startTan(1) = 0.5 : startTan(2) = 0
endTan(0) = 0.5 : endTan(1) = 0.5 : endTan(2) = 0
Dim i As Integer
Dim k As Integer
For i = 0 To 350 Step 10
k = i / 10
fitPoints(3 * k + 0) = i * Xmax / 360
fitPoints(3 * k + 1) = Sin(i * 3.14 / 180) * Ymax + Ymax
fitPoints(3 * k + 2) = 0
Next i
splineObj = AcadApp.ActiveDocument.ModelSpace._AddSpline(fitPoints, startTan, endTan)
splineObj.Update()
'创建球体
Dim SphereObj As Acad3DSolid
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 0.0# : center(1) = Ymax : center(2) = 0
radius = 30
SphereObj = AcadApp.ActiveDocment.ModelSpace.AddSphere_(center, radius)
SphereObj.color = ACAD_COLOR.acRed
SphereObj.Update()
'球体沿正玄曲线运动
'----------------------------------------------------
For i = 0 To 360 Step 10
SphereObj.Move(SphereObj.Centroid, center)
center(0) = i * Xmax / 360 '改变球体X坐标
center(1) = Sin(i * 3.14 / 180) * Ymax + Ymax '改变球体Y坐标
SphereObj.Update() '立即重绘、更新小球
Next i
End Sub
End Class