Get Vertices

Get Vertices

adaptacad
Advocate Advocate
1,314 Views
9 Replies
Message 1 of 10

Get Vertices

adaptacad
Advocate
Advocate

Hello again everyone.
Do any of you have a command that inserts the angle on the polyline vertices ??

Something like:

adaptacad_0-1637258560719.png

I believe this has been answered before but I didn't find it in my surveys.

0 Likes
Accepted solutions (1)
1,315 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

Does something like >this< do what you want?  It's just the first result I got from putting "Dimension Polyline Angles" into the Search window, but there are many others.

Kent Cooper, AIA
0 Likes
Message 3 of 10

adaptacad
Advocate
Advocate

hello @Kent1Cooper  I saw this post but it doesn't process with open polylines, it takes a long time and doesn't finish. and in closed polylines he places the dimensions and there is no need

0 Likes
Message 4 of 10

Kent1Cooper
Consultant
Consultant

I wasn't advocating for a specific one [and didn't try that one], but mostly indicating that there a lot of routines already out there.  Maybe you've already looked at all those found by my Search wording, but other wordings may find more.

Kent Cooper, AIA
0 Likes
Message 5 of 10

hak_vz
Advisor
Advisor
Accepted solution

@adaptacad  Try this. Not fully tested but I hope it will work for you.

 

(defun c:dim_poly_segment_angles ( / 
	LM:intersections take take2 pick_poly adoc e plo coords 
	cir co intlist pt p1 p2 p3 arcent ao side
	)
	;Author:  hak_vz 
	;Friday, November 19, 2021 
	;https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5530556
	;Posted at 
	;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-vertices/td-p/10766795
	;Creates angular dimensions between polyline segments
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(setvar 'cmdecho 0)
		(princ)
	)
	(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)
	)
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun take2 (lst) (take 2 lst))
	(defun pointlist2d (lst / ret) (while lst (setq	ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
	(defun pick_poly ( / e eo)
		(setq e (car(entsel "\n\nSelect polyline >")))
		(cond 
			((and (not e) (= (getvar 'Errno) 7))
			(princ "\nNothing selected. Try again!")
			(pick_poly))
			((and e (not (= (vla-get-ObjectName (vlax-ename->vla-object e)) "AcDbPolyline")))
			  (princ "\nSelected entity is not a polyline!")
			  (pick_poly)
			)
			((and e (= (vla-get-ObjectName (vlax-ename->vla-object e)) "AcDbPolyline"))
				e
			)
		)
	)
(setq adoc (vla-get-ActiveDocument (vlax-get-acad-object)) blocks (vla-get-blocks adoc))
(setq e (pick_poly) plo (vlax-ename->vla-object e))
(setq coords (pointlist2d(vlax-get plo 'Coordinates)))
(if (= (vlax-get plo 'Closed) 0)
	(setq coords (cdr(take (1- (length coords))coords)))
	(setq coords (append coords (list (cadr coords))))
)
(if (null radius)(setq radius (getreal "\nEnter arc dimension internal radius > ")))
(if (null radius)(setq radius 50))
(initget "L R")
(setq side(getkword "\nSelect side left or right <L R> >> ")) 				
(vla-endundomark adoc)
(vla-startundomark adoc)	
(setvar 'cmdecho 0)
(foreach pt coords
	(setq cir(entmakex (list (cons 0 "CIRCLE") (cons 10 pt) (cons 40 radius))))
	(setq co (vlax-ename->vla-object cir))
	(setq intlist (mapcar 'take2 (LM:intersections co plo acextendboth)))
	(mapcar 'set '(p1 p2) (vl-sort intlist '(lambda (x y) (> (vlax-curve-getdistatpoint plo x)(vlax-curve-getdistatpoint plo y)))))
	(command "_.arc" "c" pt p1 p2)
	(setq arcent (entlast) ao (vlax-ename->vla-object arcent))
    (setq p3 (vlax-curve-getpointatdist ao(* 0.5(vlax-get ao 'ArcLength))))
	(if (= side "R")(setq p3 (polar p3 (angle P3 PT)(* 2.0 radius))))
	(vlax-release-object co)
	(vlax-release-object ao)
	(entdel cir)
	(entdel arcent)
	(command "_.dimangular" "" "_none" pt "_none" p1 "_none" p2 "_none" p3)
)
(vla-endundomark adoc)
(setvar 'cmdecho 1)
(princ "\Done!")
(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 6 of 10

adaptacad
Advocate
Advocate

@hak_vz You are a legend!! Thank you very much.

Message 7 of 10

adaptacad
Advocate
Advocate

@hak_vz 
One last question, why not process when the polyline has many vertices ??

adaptacad_0-1637691416889.png

 

0 Likes
Message 8 of 10

hak_vz
Advisor
Advisor

I just noticed this error, but will check it out tomorrow.

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 9 of 10

adaptacad
Advocate
Advocate

@hak_vz Thank you very much in advance.

0 Likes
Message 10 of 10

hak_vz
Advisor
Advisor

@adaptacad wrote:

@hak_vz Thank you very much in advance.


It should now work OK

(defun c:dim_poly_segment_angles ( / 
	LM:intersections take take2 pick_poly adoc e plo coords 
	cir co intlist pt p1 p2 p3 arcent ao side radius
	)
	;Author:  hak_vz 
	;Friday, November 26, 2021 
	;https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5530556
	;Posted at 
	;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-vertices/td-p/10766795
	;Creates angular dimensions between polyline segments
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(setvar 'cmdecho 0)
		(princ)
	)
	(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)
	)
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun take2 (lst) (take 2 lst))
	(defun pointlist2d (lst / ret) (while lst (setq	ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
	(defun pick_poly ( / e eo)
		(setq e (car(entsel "\n\nSelect polyline >")))
		(cond 
			((and (not e) (= (getvar 'Errno) 7))
			(princ "\nNothing selected. Try again!")
			(pick_poly)
			)
			((and e)
			 (setq eo (vlax-ename->vla-object e))
			  (cond 
				((not (= (vlax-get eo 'ObjectName) "AcDbPolyline"))
					(princ "\nSelected entity is not a polyline!")
					(pick_poly)
				)
				(T e)
			  )
			)
		)
	)
	(setq adoc (vla-get-ActiveDocument (vlax-get-acad-object)))
	(setq plo (vlax-ename->vla-object (pick_poly)))
	(setq coords (vlax-get plo 'Coordinates))
	(if (and coords)
		(progn
			(setq coords (pointlist2d(vlax-get plo 'Coordinates)))
			(setq n (-(length coords)1))
			(if (= (vlax-get plo 'Closed) 0)
			(setq coords (cdr(reverse(cdr(reverse coords)))))
			(setq coords (append coords (list (cadr coords))))
			)
			(if (null radius)(setq radius (getreal "\nEnter arc dimension internal radius > ")))
			(if (null radius)(setq radius 20))
			(initget "L R")
			(setq side(getkword "\nSelect side left or right <L R> >> ")) 				
			(vla-endundomark adoc)
			(vla-startundomark adoc)	
			(setvar 'cmdecho 0)
			(foreach pt coords
			(setq cir(entmakex (list (cons 0 "CIRCLE") (cons 10 pt) (cons 40 radius))))
			(setq co (vlax-ename->vla-object cir))
			(setq intlist (mapcar 'take2 (LM:intersections co plo acextendnone)))
			(mapcar 'set '(p1 p2) (vl-sort intlist '(lambda (x y) (> (vlax-curve-getdistatpoint plo x)(vlax-curve-getdistatpoint plo y)))))
			(command "_.arc" "c" pt p1 p2)
			(setq arcent (entlast) ao (vlax-ename->vla-object arcent))
			(setq p3 (vlax-curve-getpointatdist ao(* 0.5(vlax-get ao 'ArcLength))))
			(if (= side "R")(setq p3 (polar p3 (angle P3 PT)(* 2.0 radius))))
			(vlax-release-object co)
			(vlax-release-object ao)
			(entdel cir)
			(entdel arcent)
			(command "_.dimangular" "" "_none" pt "_none" p1 "_none" p2 "_none" p3)
			)
			(vla-endundomark adoc)
			(setvar 'cmdecho 1)
			(princ "\Done!")
		)
	)
 (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.