找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 809|回复: 0

[教学]:用VBA实现ACAD的lengthen命令

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-6-17 02:30:00 | 显示全部楼层 |阅读模式

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

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

×
下面的代码实现ACAD的lengthen命令的DY选项。

  1. [FONT=courier new]

  2. Public Sub lengthenExample()
  3.     Dim oLine As AcadLine
  4.     Dim angle1 As Double
  5.     Dim dist1 As Double, dist2 As Double, distStPntPickPnt As Double, halfLenOfLine As Double
  6.     Dim pickedPnt2 As Variant, returnPnt As Variant
  7.     Dim basePnt(0 To 2) As Double
  8.     Dim lineObj As AcadLine
  9.     Dim intPoints As Variant
  10.     Dim myRay As AcadRay
  11.    
  12.     ThisDrawing.Utility.GetEntity oLine, pickedPnt2, "select object to lengthen"
  13.      
  14.     ' distance between the startpoint and
  15.     ' the picked point
  16.     dist1 = Abs((oLine.StartPoint(0) - pickedPnt2(0)) * (oLine.StartPoint(0) - pickedPnt2(0)))
  17.     dist2 = Abs((oLine.StartPoint(1) - pickedPnt2(1)) * (oLine.StartPoint(1) - pickedPnt2(1)))
  18.     distStPntPickPnt = Sqr(dist1 + dist2)
  19.    
  20.    ' Debug.Print "Distance between stPnt and pickedPnt " & dist3 ' for testing
  21.    
  22.     ' Use to determine which point should be modified
  23.     halfLenOfLine = oLine.Length / 2
  24.    
  25.     ' this is 90 degrees
  26.     angle1 = oLine.Angle - 1.57
  27.    
  28.     ' basePnt needs to be either the StartPoint or EndPoint
  29.     ' of the selected line
  30.      If distStPntPickPnt < halfLenOfLine Then
  31.         basePnt(0) = oLine.StartPoint(0)
  32.         basePnt(1) = oLine.StartPoint(1)
  33.         basePnt(2) = oLine.StartPoint(2)


  34.      Else
  35.         basePnt(0) = oLine.EndPoint(0)
  36.         basePnt(1) = oLine.EndPoint(1)
  37.         basePnt(2) = oLine.EndPoint(2)
  38.      End If
  39.    
  40.     returnPnt = ThisDrawing.Utility.GetPoint(basePnt, "Enter a point: ")
  41.    
  42.     Dim polarPnt As Variant
  43.     Dim distance As Double
  44.    
  45.     ' the distance value is not important
  46.     ' this line is going to be erased, it is just
  47.     ' need for the IntersectWith function below
  48.     distance = 5
  49.     polarPnt = ThisDrawing.Utility.PolarPoint(returnPnt, angle1, distance)


  50.     ' Create a ray from the base point to the polar point
  51.      Set myRay = ThisDrawing.ModelSpace.AddRay(returnPnt, polarPnt)
  52.    
  53.     ' Find the intersection points
  54.     ' intPoints = oLine.IntersectWith(lineObj, acExtendBoth)
  55.      intPoints = oLine.IntersectWith(myRay, acExtendBoth)


  56.     ' Change the StartPoint or EndPoint of the line
  57.     If distStPntPickPnt < halfLenOfLine Then
  58.         basePnt(0) = intPoints(0)
  59.         basePnt(1) = intPoints(1)
  60.         basePnt(2) = intPoints(2)
  61.         oLine.StartPoint = basePnt
  62.      Else
  63.         basePnt(0) = intPoints(0)
  64.         basePnt(1) = intPoints(1)
  65.         basePnt(2) = intPoints(2)
  66.         oLine.EndPoint = basePnt
  67.      End If
  68.         
  69.      myRay.Delete
  70.      
  71.      ThisDrawing.Regen acActiveViewport


  72. End Sub


  73. [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-12-23 05:51 , Processed in 0.384707 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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