Checking for interference between 3Dsolids

Checking for interference between 3Dsolids

Anonymous
Not applicable
1,300 Views
1 Reply
Message 1 of 2

Checking for interference between 3Dsolids

Anonymous
Not applicable

I've written a program using Visual Lisp that takes a 3Dsolid and a selection set of other 3Dsolids and finds the intersecting area between the two. I'm using vla-Boolean with this format:

 

(vla-Boolean foo acIntersection bar)

and it works perfectly for objects that are actually intersecting. For objects that don't intersect, vla-Boolean outputs "error: Automation Error. Description was not provided." and immediately ends the program. I thought I would be able to use vla-IntersectWith to check for intersections, but it also throws an exception when trying to compare a 3Dsolid to another 3Dsolid. Is there a way to check if two 3Dsolids interfere? Since I want this to be done without any additional effort from the user, I don't want them to have to run an INTERFERE command every time before they select things.

0 Likes
Accepted solutions (1)
1,301 Views
1 Reply
Reply (1)
Message 2 of 2

marko_ribar
Advisor
Advisor
Accepted solution

Here, try this :

 

(defun c:chk3DSOLint ( / *error* sol_ el sol n newrel sol1 interf sol_interf ss )

    (vl-load-com)

    (defun *error* ( msg )
        (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
        (if msg (prompt msg))
        (princ)
    )

    (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
    (if (and
            (princ "\nSelect 3D SOLIDS")
            (progn
                (while (or (null sol_) (< (sslength sol_) 2))
                    (setq sol_ (ssget "_:L" '((0 . "3DSOLID"))))
                    (cond 
                        ( (null sol_) (prompt "\nEmpty sel. set... Try selecting again...") )
                        ( (< (sslength sol_) 2) (prompt "\nSelected one 3D SOLID, please select more... Try selecting again...") )
                    )
                )
                t
            )
        )
        (progn
            (setq el (entlast))
            (repeat (setq n (sslength sol_))
                (setq sol (cons (ssname sol_ (setq n (1- n))) sol))
            )
            (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-checkinterference (list (vlax-ename->vla-object (car sol)) (vlax-ename->vla-object (cadr sol)) :vlax-true)))
              (setq newrel t)
              (if (not (eq el (entlast)))
                  (entdel (entlast))
              )
            )
            (setq sol1 sol)
            (setq interf 0)
            (if newrel
                (progn
                    (mapcar
                        '(lambda (a)
                             (mapcar
                                 '(lambda (b)
                                      (if (vla-CheckInterference (vlax-ename->vla-object a) (vlax-ename->vla-object b) :vlax-true 'test)
                                          (progn
                                              (setq sol_interf (cons a sol_interf))
                                              (setq sol_interf (cons b sol_interf))
                                              (entdel (entlast))
                                              (setq interf (1+ interf))
                                          )
                                      )
                                 )
                                 (setq sol1 (cdr sol1))
                             )
                        )
                        (reverse (cdr (reverse sol)))
                    )
                )
                (progn
                    (mapcar
                        '(lambda (a)
                             (mapcar
                                 '(lambda (b)
                                      (if (vla-CheckInterference (vlax-ename->vla-object a) (vlax-ename->vla-object b) :vlax-true)
                                          (progn
                                              (setq sol_interf (cons a sol_interf))
                                              (setq sol_interf (cons b sol_interf))
                                              (entdel (entlast))
                                              (setq interf (1+ interf))
                                          )
                                      )
                                 )
                                 (setq sol1 (cdr sol1))
                             )
                        )
                        (reverse (cdr (reverse sol)))
                    )
                )
            )
            (setq ss (ssadd))
            (foreach ent sol_interf (ssadd ent ss))
            (sssetfirst nil ss)
            (princ
                (strcat
                    "\nNumber of 3D SOLIDS : " (itoa (sslength ss))
                    " - Number of interferences : "(itoa interf)
                )
            )
        )
    )
    (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
    (princ)
)

HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes