Extend lines to intersection

Extend lines to intersection

erhan.lale
Contributor Contributor
2,087 Views
4 Replies
Message 1 of 5

Extend lines to intersection

erhan.lale
Contributor
Contributor

I have a drawing like on left side:

a closed rectangle as polyline and 4 lines. I want to strech all lines to poyline, like the drawing on the right side.

Is it possible?

strech.png

0 Likes
Accepted solutions (2)
2,088 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor
Accepted solution

for each line inside the rectangle polyline, you can call:

 

Dim insPoints As Variant

insPoints = OneOfTheLine.IntersectWith(TheRectanglePoly, acExtendThis)

 

This is supposed to return you back an array of Double numbers (6 elements), representing 2 points., then you can set the line's Start/End points to these 2 points, thus extends it.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 5

erhan.lale
Contributor
Contributor

How can i select a line, which created by explode?

 

I send an example code:

Sub extend_lines()
' Create polyline
Dim plineObj As AcadLWPolyline
Dim points(0 To 7) As Double
points(0) = 1: points(1) = 1
points(2) = 1: points(3) = 3
points(4) = 3: points(5) = 3
points(6) = 5: points(7) = 1

Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
plineObj.Closed = True

'create border
Dim plineBorder As AcadPolyline
Dim pntArr(0 To 11) As Double
Dim borderMin As Variant
Dim borderMax As Variant
Dim borderOffset As Double
plineObj.GetBoundingBox borderMin, borderMax

borderOffset = 1
borderMin(0) = borderMin(0) - borderOffset
borderMin(1) = borderMin(1) - borderOffset
borderMax(0) = borderMax(0) + borderOffset
borderMax(1) = borderMax(1) + borderOffset

pntArr(0) = borderMin(0): pntArr(1) = borderMin(1): pntArr(2) = borderMin(2):
pntArr(3) = borderMax(0): pntArr(4) = borderMin(1): pntArr(5) = borderMin(2):
pntArr(6) = borderMax(0): pntArr(7) = borderMax(1): pntArr(8) = borderMax(2):
pntArr(9) = borderMin(0): pntArr(10) = borderMax(1): pntArr(11) = borderMax(2)

Set plineBorder = ThisDrawing.ModelSpace.AddPolyline(pntArr)
plineBorder.Closed = True
plineBorder.Layer = "0"

'mirror plineObj
If MsgBox("Mirror?", vbYesNo) = vbYes Then
Dim mirrorPoint1(2) As Double
Dim mirrorPoint2(2) As Double
mirrorPoint1(0) = (borderMin(0) + borderMax(0)) / 2: mirrorPoint1(1) = borderMax(1): mirrorPoint1(2) = 0
mirrorPoint2(0) = (borderMin(0) + borderMax(0)) / 2: mirrorPoint2(1) = 0: mirrorPoint2(2) = 0
Set plineMirrored = plineObj.mirror(mirrorPoint1, mirrorPoint2)
plineMirrored.Explode
plineObj.Erase

Else
plineObj.Explode
End If
'extend lines to plineBorder

'how can i select lines, which created with explode?
End Sub
0 Likes
Message 4 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

The return value of the Explode method is an array of objects. From the help chm:

 

' Explode the polyline
    MsgBox "Explode the polyline?", , "Explode Example"
    Dim explodedObjects As Variant
    explodedObjects = plineObj.Explode
    
    ' Loop through the exploded objects
    Dim I As Integer
    For I = 0 To UBound(explodedObjects)
        explodedObjects(I).Update
        MsgBox "Exploded Object " & I & ": " & explodedObjects(I).ObjectName, , "Explode Example"
        explodedObjects(I).Color = acByLayer
        explodedObjects(I).Update
    Next

 

You can then iterate the array to access the entities. Keep in mind that the Explode method does not explode the original pline. I give you a copy. You will probably want to delete the original.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 5 of 5

erhan.lale
Contributor
Contributor

Thank you, you are the best!

0 Likes