- 积分
- 660
- 明经币
- 个
- 注册时间
- 2009-11-9
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
大家好,我想做一个在cad里的动态演示,用的timer控制时间,5秒间隔还行,1秒以下cad就挂了为什么?源码如下,求高手帮忙,多谢。
Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
Dim str As String = "The Elapsed event was raised at {0}" & e.SignalTime
Dim str2 As String = str
Dim i As Integer = 0
Dim id As ObjectId
For Each id In mBodyId
intEnd = Now.Ticks
tsnResult = New TimeSpan(intEnd - intStart)
Dim tt As Double = Val(tsnResult.TotalMilliseconds.ToString) / 1000
Dim v As Double = 1
Dim x As Double = v * tt
Dim angle As Single = 0
ChangeBlockRefInsPointAndAngle(id, New Point3d(x, 2 * x + 1, 0), angle)
Next
End Sub
Public Shared Sub ChangeBlockRefInsPointAndAngle(ByVal BlockRefId As ObjectId, ByVal Newposition As Point3d, ByVal angle As Single)
Dim acCurDb As Database = HostApplicationServices.WorkingDatabase
''启动一个事务 Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim ent As BlockReference = acTrans.GetObject(BlockRefId, OpenMode.ForWrite)
'' 创建一个矩阵并利用一个矢量将圆从点(0,0,0)移动到点(2,0,0) Create a matrix and move the circle using a vector from (0,0,0) to (2,0,0)
Dim acPt3d As Point3d = New Point3d(ent.Position.X, ent.Position.Y, 0)
Dim acVec3d As Vector3d = acPt3d.GetVectorTo(New Point3d(Newposition.X, Newposition.Y, 0))
ent.TransformBy(Matrix3d.Displacement(acVec3d))
'' 保存新对象到数据库中 Save the new objects to the database
acTrans.Commit()
Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()
End Using
End Sub
|
|