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

Is a point inside or outside a wall ?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
stelios16
665 Views, 6 Replies

Is a point inside or outside a wall ?

Hello!

 

I'm trying to find out if a point is in or out of a wall.
I have to use the command Ray and there is a code I have to use.

I'm new with Auto Lisp, and don't know how to use it well

(I hope you understood what i'm trying to do, I'm french so i'm not sure if i use the correct words 😉 )

 

(defun c:inorout ()    
            (setq ptopo (car(entsel "Select a point pls")))
    (if (= ptopo nil)
        (princ "\nYou havent selected a point")
    
        (progn
            (setq defptopo (entget ptopo))
            (setq entype (cdr(assoc 0 defptopo)))
            (if (= entype "INSERT")
                (progn
                    (setq entype1 (cdr(assoc 2 defptopo)))
                        (if (= entype1 "TCPOINT")
                            (progn
                                (setq entype2 (cdr(assoc 10 defptopo)))
                                (prompt "\nThe coordonnates of the point are :")
                                (princ entype2)
                                (setq X (car entype2))
                                (setq Y (cadr entype2))
                                (print X)
                                (print Y)
                            );fin progn    
        

                        );endif
    
        (setq polyligne (car(entsel "\nSelect a polylign")))
        (setq defpolyligne (entget polyligne))    
        
        (if (/= (cdr (assoc 8 defpolyligne)) "Polyligne_Concrete")
            (prompt "\nYou havent selected a polylign")
        );endif
    
    (setq demi_droite ((entlast ( command "_RAY" (list X Y)  (list (+ X 1) Y )   "" )"")))
    (print "ok")

        
        ;calcul des points d'intersection réels entre 2 entités passées en paramètres
        ;et retourne une liste des coordonnées des points (X1 Y1 Z1 X2 Y2 Z2 X3..)
        ;utilisation de la fonction VisualLisp
        
        (setq inter_poly (Calcul_Intersction demi_droite polyligne 0))
        (print entlast)
        
        (defun c:Calcul_Intersection (demi_droite defpolyligne 1 / VlaEntite1 ListecoordXYZ)
        
            (vl-load-com)
            (setq VlaEntite1 (vlax-ename->vla-object demi_droite))
            (setq VlaEntite2 (vlax-ename->vla-object defpolyligne))
        
            (setq ListecoordXYZ (vlax-invoke VlaEntite1 'IntersectWith VlaEntite2 1))
            
            (if (= (evenp ListecoordXYZ) T)
                (progn
                    (prompt "\n The point is outside")
                    (prompt "\n The point is inside")
                )
            ) ;endif
        );fin defun
        
        

            
(setvar "OSMODE" accrochage)
(princ)

);fin progn
);fin if
);fin progn
);fin if
); fin defun

 

 

If somebody can help, greatly appreciated ^^

Thank u !!

6 REPLIES 6
Message 2 of 7
Kent1Cooper
in reply to: stelios16

[Your English is infinitely better than my French.]

 

A couple of things I notice quickly [there may be others]:

 

I think this:


(setq demi_droite ((entlast ( command "_RAY" (list X Y)  (list (+ X 1) Y )   "" )"")))

 

should be more like this, drawing it first and saving it afterwards:

 

(command "_.RAY" (list X Y) (list (+ X 1) Y) "")

(setq demi_droite (entlast))

 

If Calcul_Intersection is a function that takes arguments when used [the things before the / ], it cannot have the c: prefix:

 

(defun Calcul_Intersection (demi_droite defpolyligne 1 / VlaEntite1 ListecoordXYZ)

 

This:

 

(setq VlaEntite2 (vlax-ename->vla-object defpolyligne))

 

will not be able to make a VLA object out of defpolyligne, which is an entity data list, but will want an entity name:


(setq VlaEntite2 (vlax-ename->vla-object polyligne))

Kent Cooper, AIA
Message 3 of 7
stelios16
in reply to: Kent1Cooper

Thank you very much for your help!

I corrected the things you pointed out but it is still not working 😕

Do you see any other mistakes ?
Once more, thank you very much!!

 

 

    ( command "_RAY" (list X Y)  (list (+ X 1) Y ) "" ) ;création d'une demi droite
    (setq demi_droite (entlast))

        
        ;calcul des points d'intersection réels entre 2 entités passées en paramètres
        ;et retourne une liste des coordonnées des points (X1 Y1 Z1 X2 Y2 Z2 X3..)
        ;utilisation de la fonction VisualLisp
        
        (setq inter_poly (Calcul_Intersction demi_droite polyligne 0))
        (print entlast)
        
        (defun Calcul_Intersection (demi_droite defpolyligne 1 / VlaEntite1 VlaEntite2 ListecoordXYZ)
        
            (vl-load-com)
            (setq VlaEntite1 (vlax-ename->vla-object demi_droite))
            (setq VlaEntite2 (vlax-ename->vla-object polyligne))
        
            (setq ListecoordXYZ (vlax-invoke VlaEntite1 'IntersectWith VlaEntite2 1))
            
            (setq nb_intersect (sslength inter_poly))
            (if (= (evenp nb_intersect) T)
                (progn
                    (prompt "\n Le point est à l'extérieur du voile")
                    (prompt "\n Le point est à l'intérieur du voile")
                )
            ) ;endif
        );fin defun

Message 4 of 7
Kent1Cooper
in reply to: stelios16


@stelios16 wrote:

Thank you very much for your help!

I corrected the things you pointed out but it is still not working 😕

Do you see any other mistakes ?
....        
        (setq inter_poly (Calcul_Intersction demi_droite polyligne 0))
....        
        (defun Calcul_Intersection (demi_droite defpolyligne 1 / VlaEntite1 VlaEntite2 ListecoordXYZ)
....        
            (setq ListecoordXYZ (vlax-invoke VlaEntite1 'IntersectWith VlaEntite2 1))
....


I was suspicious about it before, but didn't investigate, and now I have checked -- you can't use a number as an argument place-holder in a function.  You could either use something else [such as ext] in place of the 1's above, or if 0 is always the value you want for entity extension in the 'IntersectWith function, you could omit that as an argument and build it into the sub-routine:
....

        (setq inter_poly (Calcul_Intersction demi_droite polyligne)) ; no 0 at end
....        
        (defun Calcul_Intersection (demi_droite defpolyligne / VlaEntite1 VlaEntite2 ListecoordXYZ) ; no 1 argument designation
....        
            (setq ListecoordXYZ (vlax-invoke VlaEntite1 'IntersectWith VlaEntite2 0)) ; value built in permanently rather than fed in as argument
....

Kent Cooper, AIA
Message 5 of 7
stelios16
in reply to: Kent1Cooper

It works!!!!
Thanks a lot 😄
Message 6 of 7
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
....

        (setq inter_poly (Calcul_Intersction demi_droite polyligne)) ; no 0 at end
....        
        (defun Calcul_Intersection (demi_droite defpolyligne / VlaEntite1 VlaEntite2 ListecoordXYZ) ; no 1 argument designation


Oh, and you would need to spell the function name the same way where it's used as where it's defined:
....

        (setq inter_poly (Calcul_Intersection demi_droite polyligne)) ; no 0 at end

....

Kent Cooper, AIA
Message 7 of 7
stelios16
in reply to: Kent1Cooper

Yep, I had seen that and corrected it 😉

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

Post to forums  

Autodesk Design & Make Report

”Boost