Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

to get intersection between a line and a 3dface

47 REPLIES 47
Reply
Message 1 of 48
devitg
6534 Views, 47 Replies

to get intersection between a line and a 3dface

In this dwg it is clear that the line intersect with the 3dface . Both the line and the 3dface have as method INTERSECTWITH So I use VLA-INTERSECTWITH and get this error message ; error: ActiveX Server returned an error: El índice no es válido Or index not valid Why do it happens so?? Thanks in advance
47 REPLIES 47
Message 41 of 48
MikeSee
in reply to: Kent1Cooper

Cooper:

 

The problem with your routine is the error where inters() returns nil, but no in your code as is,  but in some of the 3dfaces where presents this situation, why? i dont know, ur routine must consider this case to do not abort its running...

The command LIF functions correctly, but i suit it to traverse all 3dfaces and finds which of them intersect with the line and get the z coordinate in that point, and is here where the problem appears...it will be some 3dface whose properties cause this situation that do not is seen in ur code...dont know maybe much changes of UCS has to do...

 

Greetings

 

Message 42 of 48
MikeSee
in reply to: marko_ribar

Thanks so much by ur help! Problem fixed with Marko's routine. Close this case...

 

Message 43 of 48
MikeSee
in reply to: MikeSee

hi guys! if you are still around here i would reopen the issue because I have the detail that when looking for the intersection I have to go all 3DFaces and this is where it takes too a long time, anyone has any idea how to reduce this time?

 

Thanks for advanced!

 

Message 44 of 48
gpcattaneo
in reply to: MikeSee


@MikeSee wrote:

...I have to go all 3DFaces and this is where it takes too a long time, anyone has any idea how to reduce this time? 


Try this

(setq SectionLine (car (entsel)))
(setq p1 (cdr (assoc 10 (entget SectionLine))))
(setq p2 (cdr (assoc 11 (entget SectionLine))))
(command "_zoom" "_obj" SectionLine "")
(setq 3DF (ssget "_F" (list p1 p2) '((0 . "3DFACE"))))
(command "_zoom" "_p")

 

 

Message 45 of 48
MikeSee
in reply to: gpcattaneo

So much thanks gpcattaneo, why i did think it before?, take only the 3dfaces that intersects with the xlines, time is significantly reduced this way...

Message 46 of 48
marko_ribar
in reply to: MikeSee

I think GP thought ab lines and not xlines, and selection method "Fence" applied from elevation view of that line... So you'll probably need to align UCS with line and then perform zoom - object (line)... And if xlines are the entities you're working with, you should choose "Fence" option of (ssget) but with points that are very distant (setq p11 (polar (trans p1 0 1) (angle (trans p2 0 1) (trans p1 0 1)) 1e+100)) and (setq p22 (polar (trans p2 0 1) (angle (trans p1 0 1) (trans p2 0 1)) 1e+100)), and then zoom "w" p11 p22... I've modified my code little for a case if line doesn't intersect triangle (is shorter) - this is one more case that can be in general purpose be used as exactly what it stays for "intersection between line and triangle"...

 

(defun _ilt ( p1 p2 t1 t2 t3 / v^v unit Coplanar-p ptinsidetriangle-p ptontriangle-p ptonline-p _ilp nor o )

  (defun v^v ( u v )
    (list
      (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
      (- (* (car  v) (caddr u)) (* (car  u) (caddr v)))
      (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
    )
  )

  (defun unit ( v )
    (mapcar '(lambda ( x ) (/ x (distance '(0.0 0.0 0.0) v))) v)
  )
  
  (defun Coplanar-p ( p1 p2 p3 p4 )
    (
      (lambda ( n1 n2 )
        (equal (v^v n1 n2) '(0.0 0.0 0.0) 1e-8)
      )
      (v^v (mapcar '- p1 p2) (mapcar '- p1 p3))
      (v^v (mapcar '- p1 p2) (mapcar '- p1 p4))
    )
  )

  (defun ptinsidetriangle-p ( pt p1 p2 p3 )
    (if
      (and
        (Coplanar-p pt p1 p2 p3)
        (not
          (or
            (inters pt p1 p2 p3)
            (inters pt p2 p1 p3)
            (inters pt p3 p1 p2)
          )
        )
        (not
          (or
            (> (+ (distance pt p1) (distance pt p2)) (+ (distance p3 p1) (distance p3 p2)))
            (> (+ (distance pt p2) (distance pt p3)) (+ (distance p1 p2) (distance p1 p3)))
            (> (+ (distance pt p3) (distance pt p1)) (+ (distance p2 p3) (distance p2 p1)))
          )
        )
      )
      T
      nil
    )
  )

  (defun ptontriangle-p ( pt p1 p2 p3 )
    (if
      (or
        (equal (distance p1 p2) (+ (distance pt p1) (distance pt p2)) 1e-7)
        (equal (distance p2 p3) (+ (distance pt p2) (distance pt p3)) 1e-7)
        (equal (distance p1 p3) (+ (distance pt p1) (distance pt p3)) 1e-7)
      )
      T
      nil
    )
  )

  (defun ptonline-p ( pt p1 p2 )
    (equal (distance p1 p2) (+ (distance pt p1) (distance pt p2)) 1e-7)
  )

  (defun _ilp ( p1 p2 o nor / p1p p2p op tp pp p )
    (if (not (equal (v^v nor (unit (mapcar '- p2 p1))) '(0.0 0.0 0.0) 1e-7))
      (progn
        (setq p1p (trans p1 0 (v^v nor (unit (mapcar '- p2 p1))))
              p2p (trans p2 0 (v^v nor (unit (mapcar '- p2 p1))))
              op  (trans o 0 (v^v nor (unit (mapcar '- p2 p1))))
              op  (list (car op) (cadr op) (caddr p1p))
              tp  (polar op (+ (* 0.5 pi) (angle '(0.0 0.0 0.0) (trans nor 0 (v^v nor (unit (mapcar '- p2 p1)))))) 1.0)
        )
        (if (inters p1p p2p op tp nil)
          (progn
            (setq p (trans (inters p1p p2p op tp nil) (v^v nor (unit (mapcar '- p2 p1))) 0))
            p
          )
          nil
        )
      )
      (progn
        (setq pp (list (car (trans p1 0 nor)) (cadr (trans p1 0 nor)) (caddr (trans o 0 nor))))
        (setq p (trans pp nor 0))
        p
      )
    )
  )

  (setq nor (unit (v^v (mapcar '- t3 t1) (mapcar '- t2 t1))))
  (setq o t1)
  
  (if (_ilp p1 p2 o nor)
    (if 
      (and
        (or
          (ptinsidetriangle-p (_ilp p1 p2 o nor) t1 t2 t3)
          (ptontriangle-p (_ilp p1 p2 o nor) t1 t2 t3)
        )
        (ptonline-p (_ilp p1 p2 o nor) p1 p2)
      )
      (_ilp p1 p2 o nor)
      nil
    )
    nil
  )
)

 For CAL method, you can see this lisp posted on www.cadtutor.net...
http://www.cadtutor.net/forum/showthread.php?89154-Solids-intersection-and-something-else...&s=f2672...

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 47 of 48
marko_ribar
in reply to: marko_ribar

Sorry for late reply, but only now when I checked it, I realized that I should report it... So, if you want to filter only possible 3DFACES, you should align UCS Zaxis with XLINE, then use PLAN command, then turn on SHADEMODE to CONCEPTIONAL (it worked for me this way), and then use (ssget '(0.0 0.0 0.0) '((0 . "3DFACE")))... Only with shademode FACES will be selected, check this out... Then you have only 2 options : back faces or front faces to operate on, so I think you may have more than 1 intersections - it depends how many 3DFACES are selected...

 

HTH, M.R.

I think that this what I've explained solves your case, so I would mark this topic as solution...

Regards...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 48 of 48
marko_ribar
in reply to: marko_ribar

I've checked it one again... Only top most face that is in front of view and that is sorrounding ucs icon will be selected... So only 1 intersection... For other posibillities, I suggest that you remove that selected face and repeat procedure... All unitl empty sel. set... As many faces (ssget) will detect during this procedure, as many intersections you'll have... So mark this as solution and remember to return back (entdel ename) where ename is 3DFACE with the same statements (entdel ename), just remember to store their enames into list so you can process them at the end...

 

M.R.

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost