PLINE EXTENSION

PLINE EXTENSION

alexandre_benekowski
Advocate Advocate
1,356 Views
15 Replies
Message 1 of 16

PLINE EXTENSION

alexandre_benekowski
Advocate
Advocate

Hi,

good morning,

Someone could help me?

I´m trying to make a code that give me back the extension of a pline till a point that I click. I have no ideia how to continue that:

(defun c:ESTACA ()

;OBTENÇÃO DE INFORMAÇÕES......
(setq PLINE (car (entsel "\nSelect the pline.....")))
(setvar "osmode" 16383)
(setq POINT (getpoint (strcat "\nClick on the interest point.......")))


and now the code give me back the extension of the pline till the point clicked.

thank you!!!

 

0 Likes
Accepted solutions (2)
1,357 Views
15 Replies
Replies (15)
Message 2 of 16

john.uhden
Mentor
Mentor

I'm not sure how you want this to work.  If you want to "extend" the polyline, then the point you pick has to be on the forward path of the polyline.  Instead, do you just want to add a new endpoint where you pick?  Are you expecting to extend either the beginning or the end depending on where you pick?  What if your pick point is not beyond the limits of the polyline but more like next to it?

One way it could work is to compute a point on the polyline path that is perpendicular or radial from the pick point.  In that way there is no need to add a vertex, but just relocate the first or last like extending it.

John F. Uhden

0 Likes
Message 3 of 16

hak_vz
Advisor
Advisor

I don't know if I understood you well but here is the code to start with something. Sample drawing would help us alot.

 

(defun c:ESTACA ( / *error* pick_poly take pointlist2d po point coords side d1 d2)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ (strcat "\nError: " msg))
		)
		(princ)
	)
	(defun pick_poly (msg)
		(setq e (car(entsel msg)))
		(if (and (not e) (= (getvar 'Errno) 7)) (pick_poly msg) e)
	)
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))	
	(defun pointlist2d (lst / ret) (while lst (setq	ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
	
	(setq po (vlax-ename->vla-object (pick_poly "\nSelect the pline..... ")))
	(setvar "osmode" 16383)
	(cond 
		(
			(and
				(= (vlax-get po 'ObjectName) "AcDbPolyline")
				(= (vlax-get po 'Closed) 0)
			)
			(setq POINT (take 2 (getpoint (strcat "\nClick on the interest point......."))))
			(setq coords (pointlist2d(vlax-get po 'Coordinates)))
			(setq side (take 2 (getpoint (strcat "\nClick point on polyline start or end ......."))))
			(setq d1 (distance side (car coords)) d2 (distance side (last coords)))
			(cond
				((< d1 d2)
					(vlax-put po 'Coordinates (append point (vlax-get po 'Coordinates)))
				)
				(T
					(vlax-put po 'Coordinates (append (vlax-get po 'Coordinates) point))
				)
			)

		)
		(T (princ "\nEntity is either not a polyline or polyline is closed!"))
	)
	(princ)
)

 

 

 

1) select polyline

2) pick point

3) select point at polyline start or end

Miljenko Hatlak

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
Message 4 of 16

devitg
Advisor
Advisor

@alexandre_benekowski 

give it a try. 

 

(defun c:ESTACA ()
(VLA-LOAD)
;OBTENÇÃO DE INFORMAÇÕES......
(setq PLINE (car (entsel "\nSelect the pline.....")))
(setvar "osmode" 16383)
(setq POINT (getpoint (strcat "\nClick on the interest point.......")))

(setq dist-from-start( vlax-curve-getDistAtPoint pline point))

)
0 Likes
Message 5 of 16

john.uhden
Mentor
Mentor

@hak_vz 

Not sure if that's what he wants, but it DOES work.

John F. Uhden

0 Likes
Message 6 of 16

hak_vz
Advisor
Advisor

@john.uhden  It has been told many times that picture is worth thousand words.

Miljenko Hatlak

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
Message 7 of 16

devitg
Advisor
Advisor

The main fact, is the bad translation from Brazilian to English,  and always  "THINK SIMPLE,  TO THINK CLEAR "

 

 

0 Likes
Message 8 of 16

alexandre_benekowski
Advocate
Advocate

Hi People,

bellow a example:

 

 

there is a plinethere is a plineand now, when I click in a point of this pline, its give me back the extension of the pline fron the start point till the point of pline that I clickedand now, when I click in a point of this pline, its give me back the extension of the pline fron the start point till the point of pline that I clicked

 

thanks  devitg and  hak_vz for the code but it din´t work in my computer.

0 Likes
Message 9 of 16

john.uhden
Mentor
Mentor

@alexandre_benekowski 

So when you say extension you really mean to shorten the polyline, not lengthen it?

How are you determining where to pick the point?

Normally, I would use the Lengthen command, which will retain the shape of any curved segments as well as its path.
OR, I might draw a circle with a specified radius from a specified base point and trim or extend the polyline.

John F. Uhden

0 Likes
Message 10 of 16

devitg
Advisor
Advisor

@alexandre_benekowski Hola Alexandre, favor de explicar si tu quieres saber que distancia hay desde el punto elegido al punto inicial , o si quieres acortar la pline hasta el punto elegido.

 Otra que acad usas y en windows  mac . 

 

Si es posible sube tu ejemplo.dwg

 

0 Likes
Message 11 of 16

alexandre_benekowski
Advocate
Advocate

Hi 

 

I want just the distance between the start point of pline to the point clicked (distancia hay desde el punto elegido al punto inicial). I use windows.

Spoiler
 
0 Likes
Message 12 of 16

hak_vz
Advisor
Advisor
Accepted solution

@alexandre_benekowski 

Maybe something like this?

 

 

(defun c:gdop ( / pick_poly e eo di pt )
        (vl-load-com)
	(defun pick_poly (msg)
		(setq e (car(entsel msg)))
		(if (and (not e) (= (getvar 'Errno) 7)) (pick_poly msg) e)
	)
        (setvar "osmode" 16383)
	(COND 
		((AND
			(setq 
				e (pick_poly "\nSelect polyline > ")
				pt (getpoint "\nSelect point on polyline > ")
			)
			(setq 
				eo(vlax-ename->vla-object e)
				di (vlax-curve-getDistAtPoint eo (vlax-curve-getClosestPointTo eo pt))
			)
			(princ (strcat "\n" (rtos di 2 4)))
			)
		)
	)
	(princ)
)

 

 

 

 

Miljenko Hatlak

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
Message 13 of 16

devitg
Advisor
Advisor
Accepted solution

@alexandre_benekowski  

 

My fault 

 

the first line shall be 

(VL-LOAD-COM)

(defun c:ESTACA ()
(VL-LOAD-COM)
;OBTENÇÃO DE INFORMAÇÕES......
(setq PLINE (car (entsel "\nSelect the pline.....")))
(setvar "osmode" 16383)
(setq POINT (getpoint (strcat "\nClick on the interest point.......")))

(setq dist-from-start( vlax-curve-getDistAtPoint pline point))

)

 

0 Likes
Message 14 of 16

alexandre_benekowski
Advocate
Advocate

Hi devitg and hak_vz,

Both lisp worked now!!

Thank you so much

God Bless you!!!

Happy new year!

0 Likes
Message 15 of 16

Kent1Cooper
Consultant
Consultant

@devitg wrote:

....

....
(setvar "osmode" 16383)
(setq POINT (getpoint (strcat "\nClick on the interest point.......")))
....

I was going to say you may as well just set OSMODE to 512 [NEArest only], because that will always "win" over all those other modes in picking a location along the Polyline.  But I find by 2020 it will "jump" to some of the others [INT, MID, END, etc.] when you get close enough, if that's what you want.

 

But still, having every available mode turned on is weird -- there's no point in CENter mode, for example, which will never result in a location where you pick on the Polyline.  Likewise there's no point in Geometric Center, Node, Extension, Insertion....

Kent Cooper, AIA
0 Likes
Message 16 of 16

devitg
Advisor
Advisor

@Kent1Cooper 

 

Hi Kent it was the original post 

 

devitg_0-1641415251376.png

Not mine , I just copied . 

Despite it ,  the OP code, it is a good tip about what osnap to choose . the near or 512, is sufficient .

 

0 Likes