図面内で、あるオブジェクトが他のオブジェクトと交差する点を取得します。
サポートされているプラットフォーム: Windows のみ
VBA:
RetVal = object.IntersectWith(IntersectObject, ExtendOption)
タイプ: すべての図形オブジェクト(Pviewport と PolygonMesh を除く)、AttributeReference
このメソッドが適用されるオブジェクト。
アクセス: 入力のみ
タイプ: Object
オブジェクトは、サポートされている図形オブジェクトのいずれか、または AttributeReference とすることができます。
アクセス: 入力のみ
タイプ: AcExtendOption 列挙型
交差させるために延長する図形を指定します。基本オブジェクトと他のオブジェクトのいずれか 1 つまたは両方を指定する、またはどちらも指定しないことができます。
タイプ: バリアント型(倍精度浮動小数点数型配列)
ExtendOption を設定しても、オブジェクトが交差しなければデータは返りません。
2 つのオブジェクトが交差しない場合は、データは返されません。一方または両方のオブジェクトを延長した場合に交差点となる点を要求することができます。たとえば、下図では、線分 1 はこのメソッドを呼び出す基本オブジェクト、線分 3 はパラメータとして渡されるオブジェクトです。渡された ExtendOption が acExtendThisEntity の場合、線分 1 を延長した場合に線分 3 と交差する点として、点 A が返されます。ExtendOption が acExtendOtherEntity の場合、線分 3 が延長されても、線分 1 とは交差しないためデータは返されません。
交点の種類が acExtendBothEntities で、パラメータの図形として線分 2 が渡された場合には、点 B が返されます。ExtendOption が acExtendNone で、パラメータの図形が線分 2 の場合、データは返されません。

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))
)
)
)