找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 648|回复: 0

[分享]:用VBA实现ACAD的 Lengthen 命令的方法...

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-9-18 13:22:17 | 显示全部楼层 |阅读模式

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

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

×
AutoCAD VBA example that implements a function similar to the Lengthen command  
ID    73114  
Applies to:    AutoCAD 2000
AutoCAD 2000I
AutoCAD 2002

Date    6/2/2002  




Question
Is there an example that uses GetEntity and GetPoint to implement a function
that will work like the Lengthen command on a line?
Answer
Here is an example procedure that is similar to the LENGTHEN command with the
DY parameter. There is not any error checking for clarity and would work on
LINE entities only.




Public Sub lengthenExample()
    Dim oLine As AcadLine
    Dim angle1 As Double
    Dim dist1 As Double, dist2 As Double, distStPntPickPnt As Double, halfLenOfLine As Double
    Dim pickedPnt2 As Variant, returnPnt As Variant
    Dim basePnt(0 To 2) As Double
    Dim lineObj As AcadLine
    Dim intPoints As Variant
    Dim myRay As AcadRay
   
    ThisDrawing.Utility.GetEntity oLine, pickedPnt2, "select object to lengthen"
     
    ' distance between the startpoint and
    ' the picked point
    dist1 = Abs((oLine.StartPoint(0) - pickedPnt2(0)) * (oLine.StartPoint(0) - pickedPnt2(0)))
    dist2 = Abs((oLine.StartPoint(1) - pickedPnt2(1)) * (oLine.StartPoint(1) - pickedPnt2(1)))
    distStPntPickPnt = Sqr(dist1 + dist2)
   
   ' Debug.Print "Distance between stPnt and pickedPnt " & dist3 ' for testing
   
    ' Use to determine which point should be modified
    halfLenOfLine = oLine.Length / 2
   
    ' this is 90 degrees
    angle1 = oLine.Angle - 1.57
   
    ' basePnt needs to be either the StartPoint or EndPoint
    ' of the selected line
     If distStPntPickPnt < halfLenOfLine Then
        basePnt(0) = oLine.StartPoint(0)
        basePnt(1) = oLine.StartPoint(1)
        basePnt(2) = oLine.StartPoint(2)


     Else
        basePnt(0) = oLine.EndPoint(0)
        basePnt(1) = oLine.EndPoint(1)
        basePnt(2) = oLine.EndPoint(2)
     End If
   
    returnPnt = ThisDrawing.Utility.GetPoint(basePnt, "Enter a point: ")
   
    Dim polarPnt As Variant
    Dim distance As Double
   
    ' the distance value is not important
    ' this line is going to be erased, it is just
    ' need for the IntersectWith function below
    distance = 5
    polarPnt = ThisDrawing.Utility.PolarPoint(returnPnt, angle1, distance)


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


    ' Change the StartPoint or EndPoint of the line
    If distStPntPickPnt < halfLenOfLine Then
        basePnt(0) = intPoints(0)
        basePnt(1) = intPoints(1)
        basePnt(2) = intPoints(2)
        oLine.StartPoint = basePnt
     Else
        basePnt(0) = intPoints(0)
        basePnt(1) = intPoints(1)
        basePnt(2) = intPoints(2)
        oLine.EndPoint = basePnt
     End If
        
     myRay.Delete
     
     ThisDrawing.Regen acActiveViewport


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

本版积分规则

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

GMT+8, 2024-6-9 04:56 , Processed in 0.165352 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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