CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

IntersectWith 方法 (ActiveX)

2024-5-18 19:07| 发布者: admin| 查看: 111| 评论: 0|原作者: admin|来自: AutoCAD

IntersectWith 方法 (ActiveX)

获取绘图中一个对象与另一个对象相交的点。

支持的平台:仅限 Windows

签名

VBA:

RetVal = object.IntersectWith(IntersectObject, ExtendOption)
对象

类型:所有绘图对象(除 和 )、AttributeReferencePViewportPolygonMesh

此方法应用到的对象。

IntersectObject

访问:仅输入

类型:对象

该对象可以是受支持的图形对象之一,也可以是 .AttributeReference

扩展选项

访问:仅输入

类型:枚举AcExtendOption

此选项指定是否要扩展任何对象、一个对象或两个对象以尝试相交。

  • acExtendNone:不扩展任何一个对象。
  • acExtendThisEntity:扩展基本对象。
  • acExtendOtherEntity:扩展作为参数传递的对象。
  • acExtendBoth:扩展两个对象。

返回值 (RetVal)

类型:变体(双打数组)

图形中一个对象与另一个对象相交的点数组。

言论

如果两个对象不相交,则不返回任何数据。您可以请求在将一个或两个对象扩展为与另一个对象相遇时将发生的交点。例如,在下图中,Line1 是调用此方法的基对象,line3 是作为参数传递的对象。如果传递的 ExtendOption 为 ,则返回点 A,作为扩展 line1 时 line1 与 line3 相交的点。如果 ExtendOption 为 ,则不返回任何数据,因为即使扩展了 line3,它也不会与 line1 相交。acExtendThisEntityacExtendOtherEntity

如果交集类型为 并且 line2 作为参数实体传递,则返回点 B。如果 ExtendOption 为 且 line2 为参数实体,则不返回任何数据。acExtendBothEntitiesacExtendNone



例子

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

可视化 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))
        )
    )
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2024-12-15 22:26

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部