明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1637|回复: 1

[求助]关于刷新实现动态效果的求救!

[复制链接]
发表于 2010-5-28 11:02:00 | 显示全部楼层 |阅读模式
第一次执行命令,圆可以动态显示,第二次执行命令的时候,圆就不能动态显示了,这段代码有什么问题呢,请大家指点迷津。
  1. Imports Autodesk.AutoCAD.ApplicationServices
  2. Imports Autodesk.AutoCAD.Colors
  3. Imports Autodesk.AutoCAD.DatabaseServices
  4. Imports Autodesk.AutoCAD.EditorInput
  5. Imports Autodesk.AutoCAD.Geometry
  6. Imports Autodesk.AutoCAD.Runtime
  7. Imports Autodesk.AutoCAD.GraphicsSystem
  8. Imports Autodesk.AutoCAD.GraphicsInterface
  9. Imports Autodesk.AutoCAD.Windows
  10. Imports Autodesk.AutoCAD.Publishing
  11. Imports Autodesk.AutoCAD.PlottingServices
  12. Imports Autodesk.AutoCAD.ComponentModel
  13. Imports Autodesk.AutoCAD.LayerManager
  14. Public Class Class1
  15.     Private MousePoint As Point3d = New Point3d(0, 0, 0) '保存当前鼠标位置
  16.     Shared Cr As Circle
  17.     <CommandMethod("mp")> Public Sub test()
  18.         Dim Db As Database = HostApplicationServices.WorkingDatabase
  19.         Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
  20.         Dim Doc As Document = Application.DocumentManager.MdiActiveDocument
  21.         Using LckDoc As DocumentLock = Doc.LockDocument
  22.             Using Trans As Transaction = Db.TransactionManager.StartTransaction()
  23.                 Try
  24.                     Dim Bt As BlockTable = Trans.GetObject(Db.BlockTableId, OpenMode.ForRead)
  25.                     Dim Btr As BlockTableRecord = Trans.GetObject(Bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
  26.                     
  27.                     Cr = New Circle
  28.                     Cr.SetDatabaseDefaults()
  29.                     Cr.Radius = 10
  30.                     Cr.Center = New Point3d(0, 0, 0)
  31.                     Btr.AppendEntity(Cr)
  32.                     Trans.AddNewlyCreatedDBObject(Cr, True)
  33.                     ed.WriteMessage("new后圆id:" + Cr.ObjectId.ToString)
  34.                     Dim pro As PromptPointOptions = New PromptPointOptions("按左键退出...")
  35.                     AddHandler ed.PointFilter, AddressOf GetMousePoint
  36.                     Dim res As PromptPointResult = ed.GetPoint(pro)
  37.                     Dim Po1 As Point3d = res.Value
  38.                     RemoveHandler ed.PointFilter, AddressOf GetMousePoint
  39.                     Cr.ColorIndex = 1
  40.                     Trans.Commit()
  41.                 Catch ex As System.Exception
  42.                     MsgBox("Error : " + ex.Message)
  43.                 Finally
  44.                 End Try
  45.             End Using
  46.         End Using
  47.     End Sub
  48.     ''动态获取鼠标位置  
  49.     Private Sub GetMousePoint(ByVal sender As Object, ByVal e As PointFilterEventArgs)
  50.         MousePoint = e.Context.ComputedPoint
  51.         Dim Db As Database = HostApplicationServices.WorkingDatabase
  52.         Dim Ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  53.         Dim Doc As Document = Application.DocumentManager.MdiActiveDocument
  54.         Using LckDoc As DocumentLock = Doc.LockDocument
  55.             Using Trans As Transaction = Db.TransactionManager.StartTransaction()
  56.                 Try
  57.                     Dim Pt1 As Point3d = New Point3d(0, 0, 0)
  58.                     Cr.Radius = New Line(MousePoint, Pt1).Length / 2
  59.                     Cr.Center = MousePoint
  60.                     Doc.Editor.Regen()
  61.                     Ed.WriteMessage("圆id:" + Cr.ObjectId.ToString)
  62.                     Trans.Commit()
  63.                 Catch ex As System.Exception
  64.                     MsgBox("Error : " + ex.Message)
  65.                 Finally
  66.                 End Try
  67.             End Using
  68.         End Using
  69.     End Sub
  70. End Class
发表于 2010-5-28 19:30:00 | 显示全部楼层
用Jig实现,看看Kean专题中关于Jig的部分
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 23:20 , Processed in 0.166099 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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