找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 642|回复: 0

[分享]:用VB做的反应器

[复制链接]
发表于 2004-12-10 21:24:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
注册压缩包里的Dll(AutoCad版本为2005),并在VBA里引用
在ThisDrawing模块加入下列示例代码


  1. Public TlsApp As New TlsApplication
  2. Private WithEvents m_XhqReactor As TlsReactor

  3. Public Sub TlsCadInit()
  4.     TlsApp.Application = Application
  5.     Set m_XhqReactor = TlsApp.Reactors("TlsXHQ")
  6. End Sub

  7. Private Sub m_XhqReactor_DoubleClick(ByVal pObject As IAcadObject, ByVal Value As Variant)
  8. On Error GoTo ErrHandle
  9.     Dim oBlock As AcadBlock
  10.     Dim oText As AcadText
  11.     Set oBlock = ThisDrawing.Blocks(pObject.Name)
  12.     Set oText = oBlock(1)
  13.     oText.TextString = InputBox("请输入序号", "TlsCad", oText.TextString)
  14.     pObject.Update
  15. ErrHandle:
  16. End Sub

  17. Private Sub m_XhqReactor_Erased(ByVal Value As Variant)
  18.     MsgBox "Delete"
  19. End Sub

  20. Private Sub m_XhqReactor_Modified(ByVal pObject As IAcadObject, ByVal Value As Variant)
  21. On Error GoTo ErrHandle

  22.     Dim oLine As AcadLine
  23.     Dim pStart, pEnd, pAngle, pDis
  24.    
  25.     Set oLine = ThisDrawing.HandleToObject(Value(0))

  26.     pStart = oLine.StartPoint
  27.     pEnd = pObject.InsertionPoint
  28.     pEnd = ThisDrawing.Utility.PolarPoint(pEnd, Atn(1) * 6, 5 * pObject.XScaleFactor)
  29.     pAngle = ThisDrawing.Utility.AngleFromXAxis(pStart, pEnd)
  30.     pDis = ((pStart(0) - pEnd(0)) ^ 2 + (pStart(1) - pEnd(1)) ^ 2) ^ 0.5 - 5 * pObject.XScaleFactor
  31.     oLine.EndPoint = ThisDrawing.Utility.PolarPoint(pStart, pAngle, pDis)

  32. ErrHandle:
  33. End Sub


  34. Sub TlsXHQ()
  35. On Error GoTo ErrHandle
  36.     Dim oLine As AcadLine
  37.     Dim oBlock As AcadBlock
  38.     Dim oText As AcadText
  39.    
  40.     s = ThisDrawing.Utility.GetString(False, "输入序号:")
  41.     p1 = ThisDrawing.Utility.getpoint(, "输入第一点:")
  42.     p2 = ThisDrawing.Utility.getpoint(p1, "输入第二点:")
  43.     Set oLine = ThisDrawing.ModelSpace.AddLine(p1, p2)
  44.    
  45.     p1 = TlsApp.Utility.CreatePoint
  46.     Set oBlock = ThisDrawing.Blocks.Add(p1, "*U")
  47.     p1 = ThisDrawing.Utility.PolarPoint(p1, Atn(1) * 6, 5)
  48.     oBlock.AddCircle p1, 5
  49.     Set oText = oBlock.AddText(s, p1, 5)
  50.     oText.Alignment = acAlignmentMiddleCenter
  51.     oText.TextAlignmentPoint = p1
  52.    
  53.     m_XhqReactor.Add ThisDrawing.ModelSpace.InsertBlock(ThisDrawing.Utility.PolarPoint(p2, Atn(1) * 2, 5), oBlock.Name, 1, 1, 1, 0), Array(oLine.Handle)

  54. ErrHandle:
  55. End Sub

Acad2005Doc.lsp文件加入:

  1. (vla-RunMacro (vlax-get-acad-object) "tlscadinit")
复制代码

上面的示例是一个简单的序号球原型,TlsXHQ宏创建序号球实体
移动球体,直线会跟随,双击球体,可以改变序号球的值
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-23 13:35 , Processed in 0.168495 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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