Sub Example_IntersectWith() ' 本範例會先在圖面上畫一條線及一個圓,然後顯示出兩個元件的交叉點 '宣告線所需的變數 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) = 10: endPt(1) = 10: endPt(2) = 0 '在圖面上畫線 Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt) '宣告圓所需的變數 Dim circleObj As AcadCircle Dim centerPt(0 To 2) As Double Dim radius As Double '指定圓的中心點 centerPt(0) = 5: centerPt(1) = 5: centerPt(2) = 0 '指定圓的半徑 radius = 1 '在圖面上畫圓 Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius) '縮放實際範圍 ZoomExtents Dim intPoints As Variant '找出線與圓的交叉點 'acExtendNone 意思為是不延伸元件 intPoints = lineObj.IntersectWith(circleObj, acExtendNone) Dim I As Integer, j As Integer, k As Integer Dim str As String '如果兩個元件沒有交叉則變數 intPoints 將會未被初始化 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 |
本網誌將提供一些 AutoCad 的物件、屬性、方法、事件的說明,並會提供一些範例,所有的文章來源將會參考到 AutoCad 說明或網路上的文章,如有侵權事宜請寄 E-Mail 告知或留言在文章的意見內告知,本人知悉後將會立刻刪除該篇文章。
2008年11月21日 星期五
方法 IntersectWith 範例
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言