Example Intersectwidth

Example Intersectwidth

nucliabrasil
Advocate Advocate
1,124 Views
1 Reply
Message 1 of 2

Example Intersectwidth

nucliabrasil
Advocate
Advocate

Hello!
How do I capture the intersections in a straight line?
thankful

0 Likes
1,125 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor

You can easily find sample code of how to use IntersectWith() in VBA's documentation. With AutoCAD running:

1. Go to VBA editor (command "VBAIDE")

2. open Object Browser window

3. Select any object that has IntersectionWith method, such as AcadEntity, AcadLine, AcadCircle..., on the left side

4. Select IntersectionWith method on the right side

5. Click "?" on top of the Object Browser window. At this point, AutoCAD VBA help document window opens.

Here is the code copied from the VBA HELP document:

Sub Example_IntersectWith()
    ' This example creates a line and circle and finds the points at
    ' which they intersect.
    
    ' Create the line
    Dim lineObj As AcadLine
    Dim startPt(0 To 2) As Double
    Dim endPt(0 To 2) As Double
    startPt(0) = 1: startPt(1) = 1: startPt(2) = 0
    endPt(0) = 5: endPt(1) = 5: endPt(2) = 0
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)
        
    ' Create the circle
    Dim circleObj As AcadCircle
    Dim centerPt(0 To 2) As Double
    Dim radius As Double
    centerPt(0) = 3: centerPt(1) = 3: centerPt(2) = 0
    radius = 1
    Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)
    ZoomAll
      
    ' Find the intersection points between the line and the circle
    Dim intPoints As Variant
    intPoints = lineObj.IntersectWith(circleObj, acExtendNone)
    
    ' Print all the intersection points
    Dim I As Integer, j As Integer, k As Integer
    Dim str As String
    If VarType(intPoints) <> vbEmpty Then
        For I = LBound(intPoints) To UBound(intPoints)
            str = "Intersection Point[" & k & "] is: " & intPoints(j) & "," & intPoints(j + 1) & "," & intPoints(j + 2)
            MsgBox str, , "IntersectWith Example"
            str = ""
            I = I + 2
            j = j + 3
            k = k + 1
        Next
    End If
End Sub

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes