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

problem Line intersection

17 REPLIES 17
Reply
Message 1 of 18
andresep82
1033 Views, 17 Replies

problem Line intersection

hello again!!!

 

I have a new problem.....

 

how i can select the lines one to one after (setq Conj (ssget "_c"  .....

(vl-load-com)

(setq att (getvar 'ATTREQ))
(setvar 'ATTREQ 1)
(setvar "pdmode" 3)


(defun c:INT2 ( / lineacorte1 lineasacotar1 puntosinterseccion)

(setq ang1 90)
  (setq ang2 0)

(setq line1 (entlast))

(setq lineacorte1 (vlax-ename->vla-object  line1 ))

 (setq pt1 (cdr (assoc 10  (entget line1 ))))

  
 (setq pt2 (cdr (assoc 11  (entget line1 ))))

 (Setq distancia (DISTANCE pt1 pt2))

 (setq ang2 (rad_sexa(angle pt2 pt1)))

 (setq ang3 (+ ang2 90))
 
 (setq pt3 (polar pt1 (/ (* ang3 pi) 180) distancia))


(setq 

cx2 (CAR pt2) 
cy2 (CADR pt2) 
cz2 (CADDR pt2) 

)


(setq 

cx3 (CAR pt3) 
cy3 (CADR pt3) 
cz3 (CADDR pt3) 

)



(if
	(setq Conj (ssget "_c"  (list cx2 cy2) (list cx3 cy3) )) 

 (progn
        (setq i 0 lista nil)   
        (repeat (sslength conj)
          (setq info (entget (ssname conj i))
                    
           lista (append lista (list (list (cdr (assoc -1 info))
                      
               )))
                               
           i (1+ i)))
        lista)
      nil)


(setq lineasacotar1 (vlax-ename->vla-object LISTA))


(setq matriz_puntosinterseccion  (vla-intersectwith lineacorte1 lineasacotar1 0))

(setq puntos_intersec (vlax-safearray->list (vlax-variant-value matriz_puntosinterseccion)))

(command "_point" puntos_intersec "")

(command "_erase" line1 "")


)


(DEFUN rad_sexa (radianes)
  (/  (* radianes 180.0) PI)
)





I am trying to obtain theintersection points Between one line tha i draw and all the line That stay inside rectangle selection.

 

Something of help?

 

thanks¡¡¡¡

 

17 REPLIES 17
Message 2 of 18
Kent1Cooper
in reply to: andresep82


@andresep82 wrote:

.... 

how i can select the lines one to one after (setq Conj (ssget "_c"  .....

....

I am trying to obtain theintersection points Between one line tha i draw and all the line That stay inside rectangle selection.

....


See the attached file with some comments and questions about the code.  I also have a couple of other questions:

 

When you say you want to "obtain" intersection points, does that mean you want them in a list or something, or is drawing Point entities at them [as the code is apparently supposed to do] enough?

 

You talk about intersections of the Line you draw with all intersecting Lines, but the code would find intersections with many different kinds of entity types.  It doesn't filter for Lines only in (ssget), nor does it check for what entity type things are that it finds.  If you want only Lines, you could have it filter for them, and I think it could be done a little more simply with (inters) using their endpoints, rather than by the IntersectWith approach that requires VLA objects, converting from a variant value, etc.  If you don't want to limit it to Lines only, you might still want to filter for viable entity types, because some of your functions will fail if they try to work with, for example, Text, or at the very least you probably don't want to have a Point drawn in relation to certain entity types.  Also, the Line you drew could intersect a variety of entities in more than one place, and I assume you would want to account for that possibility if you're not just looking for Lines.

Kent Cooper, AIA
Message 3 of 18
andresep82
in reply to: andresep82

sorry I have not explained which Accuracy.

 

i need intersection points for insert one block In each one of then and  a lineardim between two points.

 

filter yes,i need only line at one layer and  use (inters)....if If there are inside polylines?

 

 

(vl-load-com)

 (setvar "pdmode" 3)

(defun c:INT3 ( / line1 line1c line2 linec2 linec22)

(command "_line" pause pause "")
(setq
  line1 (entlast)
  linec1 (vlax-ename->vla-object  line1 )
  pt1 (cdr (assoc 10 (entget line1)))
  pt2 (cdr (assoc 11 (entget line1)))
  pt3 (polar pt1 (+ (angle pt2 pt1) (/ pi 2)) (distance pt1 pt2))
); setq

(setq line2 (entsel "\ line? ")

; THIS LINE.....I WANT THAT IT  SELECTED AUTOMATIC AND ALL  THOSE WHO ARE INSIDE of (setq Conj (ssget "_c" pt2 pt3))

); setq

(setq linec2 (car line2)

); setq


(setq
     linec22(vlax-ename->vla-object linec2)

); setq



(setq		
	matriz_point  (vla-intersectwith linec1 linec22 0)
); setq

(setq
	point_intersec (vlax-safearray->list (vlax-variant-value matriz_point))
); setq

 (command "_point" point_intersec "")


(command "_erase" line1 "")
 
); defun

 this lips only work which one line,and i need selected it.I want that it selected automatic and all those are inside of

 (setq Conj (ssget "_c" pt2 pt3)).

 

thanks¡¡¡¡¡¡

Message 4 of 18
Kent1Cooper
in reply to: andresep82


@andresep82 wrote:

.... 

filter yes,i need only line at one layer and  use (inters)....if If there are inside polylines?

 

....
(command "_line" pause pause "")
(setq
  line1 (entlast)
  linec1 (vlax-ename->vla-object  line1 )
  pt1 (cdr (assoc 10 (entget line1)))
  pt2 (cdr (assoc 11 (entget line1)))
  pt3 (polar pt1 (+ (angle pt2 pt1) (/ pi 2)) (distance pt1 pt2))
); setq

(setq line2 (entsel "\ line? ")
; THIS LINE.....I WANT THAT IT  SELECTED AUTOMATIC AND ALL  THOSE WHO ARE INSIDE of (setq Conj (ssget "_c" pt2 pt3))
); setq
....

....


Is the Line you want selected automatically the same one you just drew?  If so, its entity name is already in the line1 variable, and its VLA object version is already in the linec1 variable.  If not, what or where is it, that is, by what characteristics is the routine supposed to find it automatically?
 

To find only Line entities for checking intersections, you can use an entity-type filter in (ssget):

 

(ssget "_c" pt2 pt3 '((0 . "LINE")))

Kent Cooper, AIA
Message 5 of 18
andresep82
in reply to: Kent1Cooper

 the Line that i want selected automatically  is not the same that i just drew. The line  exist at plane,it can be one, two, hundred...and i need the intersection point of the  first one line tha i draw

 

(command "_line" pause pause "")
(setq
  line1 (entlast)
  lineacorte1 (vlax-ename->vla-object  line1 )

 

wich the existing lines

 

(setq sele (ssget "_c" pt1 pt2 (list  '( 0 . "LINE") ( cons 8 "layer1"))))

Message 6 of 18
alanjt_
in reply to: andresep82

This should help you get going...

 

(defun _getIntersectionsWithObject (object listOfObjects / lst ints)
  ;; return list of intersection points of a given list of vla-object with another vla-object
  ;; object - vla-object to test against list for any valid intersections
  ;; listOfObjects - list of vla-objects to test for intersections against 'object'
  ;; Alan J. Thompson, 2013.06.10
  (foreach o listOfObjects
    (if (setq ints (vlax-invoke object 'IntersectWith o acExtendNone))
      (while (caddr ints)
        (setq lst  (cons (list (car ints) (cadr ints) (caddr ints)) lst)
              ints (cdddr ints)
        )
      )
    )
  )
  lst
)

 

Message 7 of 18
Kent1Cooper
in reply to: andresep82


@andresep82 wrote:

.... i need the intersection point of the  first one line tha i draw

 

(command "_line" pause pause "")
.... 

wich the existing lines

 

(setq sele (ssget "_c" pt1 pt2 (list  '( 0 . "LINE") ( cons 8 "layer1"))))


[Should that be using pt2 & pt3 as before, rather than pt1 & pt2?  If you really mean the endpoints of the Line just drawn, I would suggest using Fence rather than Crossing mode, because Fence will find only those Lines in the selection that actually intersect that Line, whereas Crossing mode may find additional Lines that do not.]

 

Since two Lines can intersect in only one place, I would suggest not bothering with VLA object conversions and IntersectWith methods and variant values and so on.  You already have the two endpoints of the Line just drawn saved, which is half of what you need for each intersection.  For instance [there are other ways, too]:

 

(repeat (sslength sele)

  (setq ldata (entget (ssname sele 0))); first [remaining] Line's entity data list

  (if (setq pt (inters pt1 pt2 (cdr (assoc 10 ldata)) (cdr (assoc 11 ldata)) T)); there's an intersection

    (progn ; then

      (...draw Point entity there....)

      (...do something involving a Block...)

      (...whatever...)

    ); progn

  ); if

  (ssdel (ssname sele 0)); take that one out of the selection, go back and look at the next one

); repeat

 

If you use Fence mode in (ssget), then you don't need to test whether there's an intersection, because it will only find Lines that do intersect, so you can collapse it somewhat, eliminating the (if) and (progn):

 

(repeat (sslength sele)

  (setq

    ldata (entget (ssname sele 0)); first [remaining] Line's entity data list

    pt (inters pt1 pt2 (cdr (assoc 10 ldata)) (cdr (assoc 11 ldata)) T); the intersection

  ); setq

  (...draw Point entity there....)

  (...do something involving a Block...)

  (...whatever...)

  (ssdel (ssname sele 0)); take that one out of the selection, go back and look at the next one

); repeat

Kent Cooper, AIA
Message 8 of 18
Hallex
in reply to: alanjt_

My guess is to add
Vl-catch-all-error-p function
to catch if intersection is existed,
just an idea
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 9 of 18
andresep82
in reply to: andresep82

yeah¡¡¡¡ one step to go.....

 

kent11Cooper  your solution work perfect, slightly slow but it works.

 

 

(vl-load-com)

 (setvar "pdmode" 3)

(defun c:INT5 ( )

(command "_line" pause pause "")
(setq
  line1 (entlast)
  
  pt1 (cdr (assoc 10 (entget line1)))
  pt2 (cdr (assoc 11 (entget line1)))
  pt3 (polar pt1 (+ (angle pt2 pt1) (/ pi 2)) (distance pt1 pt2))

); setq



(setq conj (ssget "_c" pt2 pt3 (list  '( 0 . "LINE") ( cons 8  "0"))))

 
(setq i 0 )

      (repeat (sslength conj)

 (setq 


	ldata (entget (ssname conj i))


				); end setq,first [remaining] Line's entity data list

 (setq i (1+ i))




(setq pt (inters pt1 pt2 (cdr (assoc 10 ldata)) (cdr (assoc 11 ldata)) T)); setq there's an intersection
  

(command "_point" pt "")


);repeat
  

(command "_erase" line1 "")

   
); defun

 

and the question of the million.....  To put a a lineardim between all intersections point?

 

alanjt_    I am going to try to resolve which your help.

Message 10 of 18
alanjt_
in reply to: andresep82

Is this what you are trying to accomplish?

 

(defun c:test (/ p1 p2 ss i e d int)
  (if (and (setq p1 (getpoint "\nSpecify first point: "))
           (setq p2 (getpoint p1 "\nSpecify next point: "))
           (setq ss (ssget "_F" (list p1 p2) '((0 . "LINE") (8 . "0"))))
      )
    (repeat (setq i (sslength ss))
      (setq e (ssname ss (setq i (1- i)))
            d (entget e)
      )
      (if (setq int (inters (trans p1 1 e) (trans p2 1 e) (cdr (assoc 10 d)) (cdr (assoc 11 d)) T))
        (entmakex (list '(0 . "POINT") (cons 10 int) (assoc 210 d)))
      )
    )
  )
  (princ)
)

 

Message 11 of 18
andresep82
in reply to: andresep82

ohhhh...... my........ good.........     Smiley Surprised   faster¡¡¡¡¡

 

thanks¡¡¡¡¡¡

 

I am learning......Smiley Tongue

 

and the question of the million.....  To put a a lineardim between all intersections point?

Message 12 of 18
alanjt_
in reply to: andresep82

(defun c:test (/ _mid p1 p2 ss space pi/2 i e d int lst)

  (defun _mid (a b) (/ (+ a b) 2.))

  (if (and (setq p1 (getpoint "\nSpecify first point: "))
           (setq p2 (getpoint p1 "\nSpecify next point: "))
           (setq ss (ssget "_F" (list p1 p2) '((0 . "LINE") (8 . "0"))))
      )
    (progn
      (setq space (vlax-get-property
                    (cond (*AcadDoc*)
                          ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
                    )
                    (if (eq (getvar 'CVPORT) 1)
                      'PaperSpace
                      'ModelSpace
                    )
                  )
            pi/2  (/ pi 2.)
      )
      (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
              d (entget e)
        )
        (if
          (setq int (inters (trans p1 1 e) (trans p2 1 e) (cdr (assoc 10 d)) (cdr (assoc 11 d)) T))
           (progn
             (entmakex (list '(0 . "POINT") (cons 10 (car (setq lst (cons int lst)))) (assoc 210 d)))
             (if (> (length lst) 1)
;;;               (vlax-invoke
;;;                 space
;;;                 'AddDimAligned
;;;                 (cadr lst)
;;;                 (car lst)
;;;                 (mapcar '_mid (cadr lst) (car lst))
;;;               )
               (vlax-invoke
                 space
                 'AddDimRotated
                 (cadr lst)
                 (car lst)
                 (mapcar '_mid (cadr lst) (car lst))
                 pi/2
               )
             )
           )
        )
      )
    )
  )
  (princ)
)
(vl-load-com)
(princ)

 

Message 13 of 18
andresep82
in reply to: andresep82

yeeeeah¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡

 

 

that  is unbelievable¡¡¡¡¡ i change two think and now work great¡¡¡¡¡¡

 

 

i star wich "vla-intersectwith" because you can choose  extends or not extends the object, but at the moment i dont need now.

 

 

 

 

(defun c:test (/ _mid p1 p2 ss space pi/2 i e d int lst)

  (defun _mid (a b) (/ (+ a b) 2.))

;;;;;make layer;;;;;

  (if (not (tblsearch "LAYER" "COTAS"))
    (command "_.-layer" "_make" "COTAS" "_color" 6 "" "")
  )
  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



  (if (and (setq p1 (getpoint "\nSpecify first point:: "))
           (setq p2 (getpoint p1 "\nSpecify second point:: "))
	   (Setq p3(polar p2 (+ (angle p1 p2) (/ pi 2)) 0.1)); new point for offset
           (setq ss (ssget "_F" (list p1 p2) '((0 . "LINE") (8 . "0"))))
      )
    (progn
      (setq space (vlax-get-property
                    (cond (*AcadDoc*)
                          ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
                    )
                    (if (eq (getvar 'CVPORT) 1)
                      'PaperSpace
                      'ModelSpace
                    )
                  )
            pi/2  (/ pi 2.)
      )
      (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
              d (entget e)
        )


(setvar 'clayer "COTAS");change layer


        (if
          (setq int (inters (trans p1 1 e) (trans p2 1 e) (cdr (assoc 10 d)) (cdr (assoc 11 d)) T))
           (progn
             ;(entmakex (list '(0 . "POINT") (cons 10 (car (setq lst (cons int lst)))) (assoc 210 d))); insert point if i like insert one block

 (list '(0 . "POINT") (cons 10 (car (setq lst (cons int lst)))) (assoc 210 d)); list point

             (if (> (length lst) 1)


 (command "_dimaligned" (cadr lst)(car lst) p3 ); new dim
        
             )
           )
        )
      )
    )
  )
  (princ)
)
(vl-load-com)
(princ)

 

thanks¡¡¡¡¡ thanks¡¡¡¡ thanks¡¡¡¡¡¡¡  thanks to all, I am learning very much.

Message 14 of 18
alanjt_
in reply to: andresep82

If you look at the code I posted, you'll see where I commented out an insertion of dimaligned because you said dimlinear. Remove the dimlinear code string and uncomment the dimaligned one. You'll noticed it to be a lot faster.

 

I was wondering why you wanted a point at the intersection and a dimensions. You should really just convey exactly what you are trying to accomplish and not give out tidbits of info as the code progresses.

 

I don't understand your comment about using vla-intersectwith. This could easily be done using vla-intersectwith and would work on all curves (polyline, arc, circle, etc.).

Message 15 of 18
andresep82
in reply to: andresep82

when you use "vla-intersectwith"

 

you can choose mode:  

 

Extends the base object, does not extend either object, extends the object passed as an argument or extends both objects and and would work on all curves (polyline, arc, circle, etc.)...but i dont need at the moment.. but......

 

How would it be? i try but  something  is bad.

 

Message 16 of 18
alanjt_
in reply to: andresep82


@andresep82 wrote:

when you use "vla-intersectwith"

 

you can choose mode:  

 

Extends the base object, does not extend either object, extends the object passed as an argument or extends both objects and and would work on all curves (polyline, arc, circle, etc.)...but i dont need at the moment.. but......

 

How would it be? i try but  something  is bad.

 


It would return a series of points, whcih you'd have to group into pairs of 3. From there, you'd have intersection points. The biggest issue is, vla-intersectwith does not account for two lines being at different elevations. So, since they technically don't intersect, vla-intersectwith won't return a point.

 

BTW, instead of vla-intersectwith (since you'll have to convert it from a variant to a list. Use vlax-invoke.

 

eg. (vlax-invoke object1 'IntersectWith object2 acextendnone)

Works most vla-* style commands and avoids the need for converting to variants, or from.

Message 17 of 18
pbejse
in reply to: alanjt_


@alanjt_ wrote:
It would return a series of points, whcih you'd have to group into pairs of 3. From there, you'd have intersection points. The biggest issue is, vla-intersectwith does not account for two lines being at different elevations. So, since they technically don't intersect, vla-intersectwith won't return a point.

 


Indeed,  "Z" issuchaPITAisn'tit

Message 18 of 18
alanjt_
in reply to: pbejse


@pbejse wrote:

@alanjt_ wrote:
It would return a series of points, whcih you'd have to group into pairs of 3. From there, you'd have intersection points. The biggest issue is, vla-intersectwith does not account for two lines being at different elevations. So, since they technically don't intersect, vla-intersectwith won't return a point.

 


Indeed,  "Z" issuchaPITAisn'tit


It definitely can be. Makes for a lot more legwork.

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

Post to forums  

Autodesk Design & Make Report

”Boost