明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 877|回复: 0

net下cad对象动画问题

[复制链接]
发表于 2015-1-26 18:33:07 | 显示全部楼层 |阅读模式
大家好,我想做一个在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


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

本版积分规则

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

GMT+8, 2024-11-23 07:56 , Processed in 0.186427 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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