Gets the points where one object intersects another object in the drawing.
Supported platforms: Windows only
VBA:
RetVal = object.IntersectWith(IntersectObject, ExtendOption)
Type: All drawing objects (except PViewport and PolygonMesh), AttributeReference
The objects this method applies to.
Access: Input-only
Type: Object
The object can be one of the supported drawing objects or an AttributeReference.
Access: Input-only
Type: AcExtendOption enum
This option specifies if none, one or both, of the objects are to be extended in order to attempt an intersection.
Type: Variant (array of doubles)
The array of points where one object intersects another object in the drawing.
If the two objects do not intersect, no data is returned. You can request the point of intersection that would occur if one or both of the objects were extended to meet the other. For example, in the following illustration, Line1 is the base object from which this method was called and line3 is the object passed as a parameter. If the ExtendOption passed is acExtendThisEntity, point A is returned as the point where line1 would intersect line3 if line1 were extended. If the ExtendOption is acExtendOtherEntity, no data is returned because even if line3 were extended, it would not intersect line1.
If the intersection type is acExtendBothEntities and line2 is passed as the parameter entity, point B is returned. If the ExtendOption is acExtendNone and line2 is the parameter entity, no data is returned.
VBA:
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
Visual LISP:
(vl-load-com) (defun c:Example_IntersectWith() ;; This example creates a line and circle and finds the points at ;; which they intersect. (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) ;; Create the line (setq startPt (vlax-3d-point 1 1 0) endPt (vlax-3d-point 5 5 0)) (setq modelSpace (vla-get-ModelSpace doc)) (setq lineObj (vla-AddLine modelSpace startPt endPt)) ;; Create the circle (setq centerPt (vlax-3d-point 1 1 0) radius 1) (setq circleObj (vla-AddCircle modelSpace centerPt radius)) (vla-ZoomAll acadObj) ;; Find the intersection points between the line and the circle (setq intPoints (vla-IntersectWith lineObj circleObj acExtendNone)) ;; Print all the intersection points (setq I 0 j 0 k 0) (if (/= (type intPoints) vlax-vbEmpty) (while (>= (vlax-safearray-get-u-bound (vlax-variant-value intPoints) 1) I) (setq tempPoint (vlax-safearray->list (vlax-variant-value intPoints))) (setq str (strcat "Intersection Point[" (itoa k) "] is: " (rtos (nth j tempPoint) 2) "," (rtos (nth (1+ j) tempPoint) 2) "," (rtos (nth (+ j 2) tempPoint) 2))) (alert str) (setq str "" I (+ I 2) j (+ j 3) k (1+ k)) ) ) )