Results 1 to 2 of 2

Thread: IntersectWith motod problem VBA

  1. #1
    Member
    Join Date
    2012-03
    Posts
    3

    Default IntersectWith motod problem VBA

    I got to the point of intersection of two polylines. The process will be repeated many times. However, according to the VBA codes trying different UCS coordinates. Codes in area 1 is working correctly. Working in the wrong area 2.

    Similarly, there is also the problem trim. You can see the link below.

    http://forums.augi.com/showthread.ph...80#post1212980



    • /////////
      Sub IPNT()
      Dim objSS As AcadSelectionSet
      Dim objSS2 As AcadSelectionSet
      Dim Poly1 As AcadLWPolyline
      Dim Poly2 As AcadLWPolyline
      On Error Resume Next
      ThisDrawing.SelectionSets("TempSSet1").Delete
      On Error Resume Next
      Set objSS = ThisDrawing.SelectionSets.Add("TempSSet1")
      If Err Then Exit Sub
      MsgBox "Select Poly 1"
      objSS.SelectOnScreen
      For Each Poly1 In objSS
      Exit For: Next
      On Error Resume Next
      ThisDrawing.SelectionSets("TempSSet2").Delete
      On Error Resume Next
      Set objSS2 = ThisDrawing.SelectionSets.Add("TempSSet2")
      If Err Then Exit Sub
      MsgBox "Select Poly 2"
      objSS2.SelectOnScreen
      For Each Poly2 In objSS2
      Exit For: Next
      pts = Poly1.IntersectWith(Poly2, acExtendNone)
      MsgBox "X= " & pts(0) & vbCr & "Y= " & pts(1), vbInformation, "Intersection Point"
      End Sub
      /////////



    Thanks for help.
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    All AUGI, all the time arshiel88's Avatar
    Join Date
    2005-02
    Location
    Off the Grid
    Posts
    548

    Default Re: IntersectWith motod problem VBA

    After testing the vba code, I confirmed that there is an issue in the IntersectWith statement in Area 2. I don't know how and why this is happening but IntersectWith detects 2 intersections in Area 2. We can discard the other intersection (via Redim - see code) if you will use the code on polylines with only one real intersection, hoping/assuming that vba finds the real intersection first.

    here's the modified code.
    Code:
    Sub IPNT()
    
    Dim Poly1 As AcadLWPolyline
    Dim Poly2 As AcadLWPolyline
    Dim pts As Variant
    
    
    On Error Resume Next
    
    ThisDrawing.Utility.GetEntity Poly1, pickPt, "Pick Poly1:"
    If Err Then Exit Sub
    ThisDrawing.Utility.GetEntity Poly2, pickPt, "Pick Poly2:"
    If Err Then Exit Sub
    
    pts = Poly1.IntersectWith(Poly2, acExtendNone)
    MsgBox "Found " & (UBound(pts) + 1) / 3 & " intersection/s."
    
    '-----------------------------------use this to use only the first intersection
    ReDim Preserve pts(2)
    ThisDrawing.ModelSpace.AddPoint pts
    '-----------------------------------use this to use only the first intersection
    
    
    
    '-----------------------------------------use this to display all intersections
    'Dim ptCoord(0 To 2) As Double
    'For i = 0 To UBound(pts) Step 3
        'ptCoord(0) = pts(i): ptCoord(1) = pts(i + 1): ptCoord(2) = pts(i + 2)
        'Debug.Print ptCoord(0); ptCoord(1); ptCoord(2)
        'ThisDrawing.ModelSpace.AddPoint ptCoord
    'Next
    '-----------------------------------------use this to display all intersections
    
    End Sub

    ...and please use [code] tags for easy code reading. Good luck.

    Shielbern Bolalin
    Architectural 3D Renderer
    ----------------------------------------------------------------------
    “A clever person solves a problem. A wise person avoids it.”

    1879-1955

Similar Threads

  1. IntersectWith Problems
    By srperrier in forum Dot Net API
    Replies: 0
    Last Post: 2011-08-05, 08:07 PM
  2. IntersectWith says lines don't intersect
    By bsardeson in forum VBA/COM Interop
    Replies: 3
    Last Post: 2010-08-23, 08:09 PM
  3. Problems with IntersectWith
    By Lee Mac in forum AutoLISP
    Replies: 3
    Last Post: 2009-05-17, 11:20 PM
  4. Intersectwith issue
    By kerbocad in forum VBA/COM Interop
    Replies: 2
    Last Post: 2009-02-19, 02:27 PM
  5. IntersectWith Question
    By david.brissenden in forum VBA/COM Interop
    Replies: 3
    Last Post: 2008-10-13, 01:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •