About "IntersectWith" Method

Discussion in 'AutoCAD' started by anttam, Mar 28, 2005.

  1. anttam

    anttam Guest

    Dim ckIntersect As Boolean
    ckIntersect = cktest(objSS.Item(0), objSS.Item(1))
    ---------------------------------------------------------------------
    Function cktest(objEnt1 As AcadEntity, objEnt2 As AcadEntity) As Boolean
    Dim iPt As Variant
    Dim intersect As Boolean
    On Error Resume Next
    With ThisDrawing.Utility

    intersect = False

    If Not IsNull(objEnt1.IntersectWith(objEnt2, acExtendNone)) Then intersect = True

    If intersect = True Then
    iPt = objEnt1.IntersectWith(objEnt2, acExtendNone)
    .Prompt vbCrLf & "intersect point = " & iPt(0) & "," & iPt(1)
    Else: .promt vbCrLf & "No intersect!"
    End If

    If Err Then .Prompt vbCrLf & "Error as " & Err.Description

    cktest = intersect

    End With
    End Function
    --------------------------------------------------------------------------
    * When there is intersect.......
    the intersect point can shown and cktest = True

    * When there is no intersect....
    no intersect point is shown but cktest = True
    "Command: Error as Subscript out of range" is shown
     
    anttam, Mar 28, 2005
    #1
  2. anttam

    TomD Guest

    From what I understand, you have to check for a UBound of less than 0. I
    don't at all understand why this works this way, but that's what I've
    gathered, so far. (I only recently tried this out, and do not have it in
    production, yet, so I could certainly be mistaken.)
     
    TomD, Mar 28, 2005
    #2
  3. anttam

    anttam Guest

    Hi~ TomD
    Thanks for help, but how to check for a UBound?
    Can you show me by examples?
    Thanks a lot!
     
    anttam, Mar 28, 2005
    #3
  4. anttam

    Norman Yuan Guest

    There is a bug in AutoCAD VBA Help's sample code for IntersectWith() method:

    From sample code:

    ' 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 '' ========HERE IS THE
    BUG===========
    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

    The bug is that: IntersectWith() never returns a Variant of vbEmpty, it
    returns an empty array of Double (that is UBound(returnVariant)=-1) if there
    is no intersection, and returns an array of Double
    (UBound(returnVariant)>=2), if there is 1 or more intersections.

    So you need to check UBound() of returned variant to tell whether there is
    intersection or not, as the other post suggested.
     
    Norman Yuan, Mar 28, 2005
    #4
  5. anttam

    TomD Guest

    If Norman's post doesn't explain it enough, repost and I'll post a piece of
    code I was using.
     
    TomD, Mar 28, 2005
    #5
  6. anttam

    anttam Guest

    Norman

    Thank you again~

    anttam @w@
     
    anttam, Mar 29, 2005
    #6
  7. anttam

    anttam Guest

    Hi! TomD

    It's Ok, thanks!

    anttam
     
    anttam, Mar 29, 2005
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.