Results 1 to 4 of 4

Thread: Problems with IntersectWith

  1. #1
    I could stop if I wanted to Lee Mac's Avatar
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Problems with IntersectWith

    I am trying to determine the maximum and minimum points on a curve by using a combination of the BoudingBox method and the IntersectWith method, however I am consistently receiving nil results, and I cannot work out why.

    Below is my code - I have even added a "fuzz factor" to make sure that the objects intersect - but still with no luck:

    Code:
    (defun getExt  (cObj / fuzz doc spc cObj Minp Maxp tmp1 tmp2 Maxpt Minpt)
      (vl-load-com)
    
      (setq fuzz 0.001)
    
      (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))
            spc (if (zerop (vla-get-activespace doc))
                  (if (= (vla-get-mspace doc) :vlax-true)
                    (vla-get-modelspace doc)
                    (vla-get-paperspace doc))
                  (vla-get-modelspace doc)))
    
      (or (eq 'VLA-OBJECT (type cObj))
          (setq cObj (vlax-ename->vla-object cObj)))
    
      (vla-getBoundingBox cObj 'Minp 'Maxp)
      (setq Minp (vlax-safearray->list Minp)
            Maxp (vlax-safearray->list Maxp))
    
      (setq Maxpt (car
                    (vlax-list->3D-point
                      (vlax-invoke
                        (setq tmp1
                          (vla-addline spc
                            (vlax-3D-point
                              (list (car Minp) (- (cadr Maxp) fuzz) 0.0))
                                (vlax-3D-point Maxp)))
                                  'IntersectWith cObj
                                     acExtendNone))))
    
      (setq Minpt (car
                    (vlax-list->3D-point
                      (vlax-invoke
                        (setq tmp2
                          (vla-addline spc
                            (vlax-3D-point
                              (list (car Maxp) (+ (cadr Minp) fuzz) 0.0))
                                (vlax-3D-point Minp)))
                                  'IntersectWith cObj
                                    acExtendNone))))
    
      (list Minpt Maxpt))
    
    (defun vlax-list->3D-point  (lst)
      (if lst
        (cons (list (car lst) (cadr lst) (caddr lst))
              (vlax-list->3D-point (cdddr lst)))))
    
    (defun c:test ()
      (getExt (car (entsel))))
    Last edited by Lee Mac; 2009-05-17 at 02:16 PM.

  2. #2
    I could stop if I wanted to kpblc2000's Avatar
    Join Date
    2006-09
    Posts
    212
    Login to Give a bone
    0

    Default Re: Problems with IntersectWith

    Try to check this code:
    Code:
    (defun get-exts (obj fuzz / minp maxp)
      (if (not fuzz)
        (setq fuzz 1e-3)
        ) ;_ end of if
      (if (setq obj (cond
                      ((= (type obj) 'ename) (vlax-ename->vla-object obj))
                      ((= (type obj) 'vla-object) obj)
                      ) ;_ end of cond
                ) ;_ end of setq
        (progn
          (vla-getboundingbox obj 'minp 'maxp)
          (setq minp (vlax-safearray->list minp)
                maxp (vlax-safearray->list maxp)
                ) ;_ end of setq
          (list (mapcar (function (lambda (x) (- x fuzz))) minp)
                (mapcar (function (lambda (x) (+ x fuzz))) maxp)
                ) ;_ end of list
          ) ;_ end of progn
        ) ;_ end of if
      ) ;_ end of defun
    Use AUTOCAD / ADT / AA 2006 / 2008 / 2010
    All i say is only my opinion
    I'm watching you! Your

  3. #3
    I could stop if I wanted to Lee Mac's Avatar
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Problems with IntersectWith

    Thanks for your code kpblc2000, that better adds the fuzz factor to the measurements of the bounding box, but its the intersectWith part that is causing me grief.

    I cannot get it to register an intersection at all - when clearly there is.

  4. #4
    I could stop if I wanted to Lee Mac's Avatar
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Problems with IntersectWith

    Finally sorted the problem - thanks to Sean Tessier from over at the Swamp -

    Turns out that the GetBoundingBox method adds a small Z component to the resulting points, which needed to be ignored.

    Thanks for helping with the fuzz factor adjustment, here is the final code:

    Code:
    (defun getExt  (cObj / fuzz doc spc cObj Minp Maxp tmp1 tmp2 Maxpt Minpt)
      (vl-load-com)
    
      (setq fuzz 0.00001)
    
      (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))
            spc (if (zerop (vla-get-activespace doc))
                  (if (= (vla-get-mspace doc) :vlax-true)
                    (vla-get-modelspace doc)
                    (vla-get-paperspace doc))
                  (vla-get-modelspace doc)))
    
      (or (eq 'VLA-OBJECT (type cObj))
          (setq cObj (vlax-ename->vla-object cObj)))
    
      (vla-getBoundingBox cObj 'Minp 'Maxp)
      (setq Minp (mapcar
                   (function
                     (lambda (x) (+ x fuzz))) (vlax-safearray->list Minp))
            Maxp (mapcar
                   (function
                     (lambda (x) (- x fuzz))) (vlax-safearray->list Maxp)))
    
      (setq Maxpt (car
                    (vlax-list->3D-point
                      (vlax-invoke
                        (setq tmp1
                          (vla-addline spc
                            (vlax-3D-point
                              (list (car Minp) (cadr Maxp) 0.0))
                                (vlax-3D-point
                                  (list (car Maxp) (cadr Maxp) 0.0))))
                                  'IntersectWith cObj
                                     acExtendNone))))
    
      (setq Minpt (car
                    (vlax-list->3D-point
                      (vlax-invoke
                        (setq tmp2
                          (vla-addline spc
                            (vlax-3D-point
                              (list (car Maxp) (cadr Minp) 0.0))
                                (vlax-3D-point
                                  (list (car Minp) (cadr Minp) 0.0))))
                                  'IntersectWith cObj
                                    acExtendNone))))
    
      (list Minpt Maxpt))
    
    (defun vlax-list->3D-point  (lst)
      (if lst
        (cons (list (car lst) (cadr lst) (caddr lst))
              (vlax-list->3D-point (cdddr lst)))))
    
    
    (defun c:test ()
      (setvar "PDMODE" 3)
      (foreach pt (getExt (car (entsel)))
        (command "_point" "_non" pt))
      (princ))

Similar Threads

  1. IntersectWith motod problem VBA
    By 4gokay372489 in forum VBA/COM Interop
    Replies: 1
    Last Post: 2013-02-06, 11:22 AM
  2. IntersectWith Problems
    By srperrier in forum Dot Net API
    Replies: 0
    Last Post: 2011-08-05, 08:07 PM
  3. IntersectWith says lines don't intersect
    By bsardeson in forum VBA/COM Interop
    Replies: 3
    Last Post: 2010-08-23, 08:09 PM
  4. Intersectwith issue
    By kerbocad in forum VBA/COM Interop
    Replies: 2
    Last Post: 2009-02-19, 03: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
  •