Blocks to polylines vertex angles

Blocks to polylines vertex angles

alexandra_fulger
Explorer Explorer
510 Views
6 Replies
Message 1 of 7

Blocks to polylines vertex angles

alexandra_fulger
Explorer
Explorer

Hi all,

 

In a drawing l have many polylines, and I need to insert specific blocks at different angles of the polyline segments. So let's say that I have a polyline that has some segment angles between 40-47 degrees. I need to insert in those vertex a block named "c45". Is there a way to do that with a lisp?

 

Do you think it could be possible? do you have any tips for me?

 

Thanks a lot in advance!

0 Likes
Accepted solutions (1)
511 Views
6 Replies
Replies (6)
Message 2 of 7

komondormrex
Mentor
Mentor

hey,

where exactly a certain block should be inserted with regard to a segment?

0 Likes
Message 3 of 7

alexandra_fulger
Explorer
Explorer

Hey! The blocks should be inserted as shown in my dwg. Can it be done to select more than just one polyline at a time?

0 Likes
Message 4 of 7

komondormrex
Mentor
Mentor
Accepted solution

hi,

sure it can. check the following code.  block 'c45' should be defined in the drawing.

(defun c:mark_segment_angle ( / param repeat_count vector_1 vector_2 cos_alpha sin_alpha alpha)
	(if (setq pline_sset (ssget '((0 . "lwpolyline"))))
		(foreach pline (vl-remove-if 'listp (mapcar 'cadr (ssnamex pline_sset)))
			(setq param 0
				  repeat_count (fix (vlax-curve-getendparam pline))
			)
			(repeat (1- repeat_count)
					(setq vector_1 (vlax-curve-getfirstderiv pline param)
						  vector_2 (vlax-curve-getfirstderiv pline (setq param (1+ param)))
						  cos_alpha (/ (apply '+ (mapcar '* vector_1 vector_2)) 
									   (* (sqrt (apply '+ (mapcar 'expt vector_1 '(2 2)))) 
									   	  (sqrt (apply '+ (mapcar 'expt vector_2 '(2 2))))
									   )
									)
					)
					(cond 
						(
							(equal 0 cos_alpha 1e-8)
								(setq alpha (* 0.5 pi))
						)
						(
							(equal 1.0 cos_alpha 1e-8)
								(setq alpha 0)
						)
						(
							t
								(setq sin_alpha (sqrt (- 1 (expt cos_alpha 2)))
						  		      alpha (atan (/ sin_alpha cos_alpha))
								)
						)
					)
					(cond
						(
							(< (/ (* 40 pi) 180) alpha (/ (* 47 pi) 180))
								(vla-insertblock (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
																(vlax-3d-point (vlax-curve-getpointatparam pline param))
																"c45"
																0.0254 0.0254 0.0254 0
								)
						)
						(
							t
						)
					)
;					(print (angtos alpha 1 6))
			)
		)
	)
	(princ)
)

 

Message 5 of 7

alexandra_fulger
Explorer
Explorer

 

 

0 Likes
Message 6 of 7

alexandra_fulger
Explorer
Explorer

Thank you so much! You really helped me a lot! Wow!!!

Message 7 of 7

komondormrex
Mentor
Mentor

your welcome)

0 Likes