Create a spline through the ends of a polyline

Create a spline through the ends of a polyline

malmal02122023
Advocate Advocate
553 Views
5 Replies
Message 1 of 6

Create a spline through the ends of a polyline

malmal02122023
Advocate
Advocate

Hello,

 

I would like to select several polylines and create a spline through the ends of a polylines as shown below.

 

Thank you by advance for the help.

 

malmal02122023_0-1701516203590.png

 

0 Likes
Accepted solutions (1)
554 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Possibly like this

 

(vl-load-com)

(defun c:splinends ( / l)
  
  (if (and (setq l (ssget '((0 . "LWPOLYLINE"))))
	   (setq l (vl-remove-if 'listp (mapcar 'cadr (ssnamex l))))
	   (setq l (mapcar 'vlax-curve-getendpoint l))
	   (setq l (vl-sort l '(lambda (e1 e2) (< (car e1) (car e2)))))
	   )
    (progn
      (initcommandversion)
      (command "_.spline")
      (foreach p l (command "_non" (trans p 0 1)))
      (command "")))
  (princ)
  )
Message 3 of 6

Kent1Cooper
Consultant
Consultant

That may not be too difficult, but questions arise [Message 2 will work only with certain answers assumed]:

Are the Polylines always vertical, or might they run at different angles?  If at different angles, are they always parallel like these, or might they sometimes be at different angles from each other?

This might matter less than some other questions, but are they always straight?

Are they always drawn in the same direction, or might some be drawn from bottom to top and others from top to bottom?  [If not always vertical but always parallel, some in opposite directions from each other?]

Again if always vertical, would you always need the top ends, or sometimes the bottom?  If angles vary, what would be the criteria for which end to use?

What's different about the Polyline on the left, with the pull-down pointer thingie?  Would that difference make any difference to such a routine?

An ordinary SPLINE command with ENDpoint Object Snap running would do this about as quickly as a custom routine [and you could do a lot of them in the time it would take to come up with such a routine] -- can you elaborate on the need?

Kent Cooper, AIA
0 Likes
Message 4 of 6

ВeekeeCZ
Consultant
Consultant

@Kent1Cooper wrote:

... Polyline on the left, with the pull-down pointer thingie? ....

 

That belongs to the spline.

0 Likes
Message 5 of 6

malmal02122023
Advocate
Advocate

Thank you very much.

It works great for my case with vertical polylines.

0 Likes
Message 6 of 6

calderg1000
Mentor
Mentor

Regards @malmal02122023 

Please try this code. I hope it meets everything @Kent1Cooper asks. It also works if the polyline was created from top to bottom or upside down.

;;;___
(defun c:m_sp (/ s i j k l m n px py lpy lpxy)
  (setq	s (ssget '((0 . "lwpolyline")))
  )
  (repeat (setq i (sslength s))
    (setq lp  (mapcar 'cdr
		      (vl-remove-if-not
			'(lambda (x) (= (car x) 10))
			(entget (ssname s (setq i (1- i))))
		      )
	      )
	  py
	      (car (vl-sort lp '(lambda (j k) (> (cadr j) (cadr k)))))
	  lpy
	      (cons py lpy)
    )
  )
  (setq
    lpxy (reverse (vl-sort lpy '(lambda (l m) (< (car l) (car m)))))
  )
  (initcommandversion)
  (command "_.spline")
  (repeat (setq n (length lpxy))
    (command (nth (setq n (1- n)) lpxy))
  )
  (command "")
  (princ)
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes