Public Sub TEST_ Break()
Call Break
End Sub
Public Function Break() As Variant
Dim objLine As AcadLine
Dim objOne As AcadLine
Dim objTwo As AcadLine
Dim objSpace As AcadBlock
Dim dblAng As Double
Dim varPnt As Variant
Dim varNear As Variant
Dim varFirst As Variant
Dim varSecond As Variant
Dim strPrmt As String
On Error GoTo Err_Control
If ThisDrawing.ActiveSpace = acModelSpace Then
Set objSpace = ThisDrawing.ModelSpace
Else
Set objSpace = ThisDrawing.PaperSpace
End If
strPrmt = vbCr & "Select Line to break: "
ThisDrawing.Utility.GetEntity objLine, varPnt, strPrmt
strPrmt = vbCr & "Select First Point: "
varPnt = ThisDrawing.Utility.GetPoint(Prompt:=strPrmt)
varFirst = NearestTo(objLine, varPnt)
strPrmt = vbCr & "Select Second Point: "
varPnt = ThisDrawing.Utility.GetPoint(Prompt:=strPrmt)
varSecond = NearestTo(objLine, varPnt)
dblAng = ThisDrawing.Utility.AngleFromXAxis(varFirst, varSecond)
If dblAng >= 3.14159265358979 Then
If objLine.Angle <= 3.14159265358979 Then
Set objOne = objSpace.AddLine(objLine.EndPoint, varFirst)
Set objTwo = objSpace.AddLine(varSecond, objLine.StartPoint)
Else
Set objOne = objSpace.AddLine(objLine.StartPoint, varFirst)
Set objTwo = objSpace.AddLine(varSecond, objLine.EndPoint)
End If
Else
If objLine.Angle >= 3.14159265358979 Then
Set objOne = objSpace.AddLine(objLine.EndPoint, varFirst)
Set objTwo = objSpace.AddLine(varSecond, objLine.StartPoint)
Else
Set objOne = objSpace.AddLine(objLine.StartPoint, varFirst)
Set objTwo = objSpace.AddLine(varSecond, objLine.EndPoint)
End If
End If
objLine.Delete
Break = Array(objOne, objTwo)
Exit_Here:
Exit Function
Err_Control:
MsgBox Err.Description
Resume Exit_Here
End Function
Public Function NearestTo(objLine As AcadLine, _
varPoint As Variant) As Variant
Dim objUtil As Object
Dim varTemp As Variant
Dim dblSlope As Double
Dim dblInvSlope As Double
Dim dblTemp(0 To 2) As Double
Dim dblAng As Double
Dim vStart As Variant
Dim vEnd As Variant
Dim x1 As Double
Dim y1 As Double
Dim x2 As Double
Dim y2 As Double
Dim x3 As Double
Dim y3 As Double
Dim Y1Intercept As Double
Dim Y2Intercept As Double
On Error GoTo Err_Control
vStart = objLine.StartPoint
vEnd = objLine.EndPoint
x1 = vStart(0)
y1 = vStart(1)
x2 = vEnd(0)
y2 = vEnd(1)
x3 = varPoint(0)
y3 = varPoint(1)
dblSlope = (y2 - y1) / (x2 - x1)
If dblSlope <> 0 Then
dblInvSlope = -1 / dblSlope
Else
dblInvSlope = 0
End If
Y1Intercept = y1 - (dblSlope * x1)
Y2Intercept = y3 - (dblInvSlope * x3)
If dblSlope <> 0 Then
dblTemp(0) = (Y1Intercept - Y2Intercept) / _
(dblInvSlope - dblSlope)
Else
dblTemp(0) = x3
End If
dblTemp(1) = (dblSlope * dblTemp(0)) + Y1Intercept
Set objUtil = ThisDrawing.Utility
objUtil.CreateTypedArray varTemp, vbDouble, _
dblTemp(0), dblTemp(1), dblTemp(2)
NearestTo = varTemp
Exit_Here:
Exit Function
Err_Control:
MsgBox Err.Description
Resume Exit_Here
End Function
|