Jump to content

lisp that converts intersections of polylines into vertices of a polyline.


Zoltan
 Share

Recommended Posts

I need a lisp that draws a polyline at the intersections of other polylines and where these intersections will be verticies. 

 

On the picture below, where the blue lines cross the red line, i want the lisp to draw a polyline where the crossing points will be vertices. 

 

Could someone help me with this? I have no clue how to do it.

 

Thanks,

Zoltan

 

https://ibb.co/443gYg5

 

 

Link to comment
Share on other sites

Pulled mostly from here

 

(defun c:interset (/ spm sel lst)
  (vl-load-com)
  (if (setq sel (ssget))
    (setq lst (LM:intersectionsinset sel))
    ;Sort points left to right
    (setq tlst (mapcar 'cadr
                       (vl-sort tlst
                                '(lambda (a b)
                                   (if (equal (caar a) (caar b) 1e-6)
                                     (< (car (car a)) (car (car b)))
                                   )
                                 )
                       )
               )
    )
  )
  (entmake
    (append
      (list
        (cons 0 "LWPOLYLINE")
        (cons 100 "AcDbEntity")
        (cons 100 "AcDbPolyline")
        (cons 90 (length lst))
        (cons 70 0)
      )
      (mapcar (function (lambda (p) (cons 10 p))) lst)
    )
  )
  (princ)
)
;; Intersections in Set  -  Lee Mac
;; Returns a list of all points of intersection between all objects in a supplied selection set.
;; sel - [sel] Selection Set
(defun LM:intersectionsinset (sel / id1 id2 ob1 ob2 rtn)
  (repeat (setq id1 (sslength sel))
    (setq ob1 (vlax-ename->vla-object (ssname sel (setq id1 (1- id1)))))
    (repeat (setq id2 id1)
      (setq ob2 (vlax-ename->vla-object (ssname sel (setq id2 (1- id2))))
            rtn (cons (LM:intersections ob1 ob2 acextendnone) rtn)
      )
    )
  )
  (apply 'append (reverse rtn))
)
;; Intersections  -  Lee Mac
;; Returns a list of all points of intersection between two objects
;; for the given intersection mode.
;; ob1,ob2 - [vla] VLA-Objects
;;     mod - [int] acextendoption enum of intersectwith method
(defun LM:intersections (ob1 ob2 mod / lst rtn)
  (if (and (vlax-method-applicable-p ob1 'intersectwith)
           (vlax-method-applicable-p ob2 'intersectwith)
           (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
      )
    (repeat (/ (length lst) 3)
      (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
            lst (cdddr lst)
      )
    )
  )
  (reverse rtn)
)

 

Edited by mhupp
added prompts
Link to comment
Share on other sites

Turn off Blue lines, add end lines to the 2 plines, do Bpoly, delete the 2 end lines, turn on blues lines. No complicated code needed. Could be done in a lisp. So if this is for hatch can do selecting bpoly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...