Lisp to place handle ID in centroid of selected polylines

Lisp to place handle ID in centroid of selected polylines

nathan.benchYTD9M
Explorer Explorer
526 Views
4 Replies
Message 1 of 5

Lisp to place handle ID in centroid of selected polylines

nathan.benchYTD9M
Explorer
Explorer

Looking for a lisp that basically does the same thing that is available in Maps 3D with annotation templates.  I want to select multiple closed polylines and then place text in each centroid with the handleID. Let me know if I need to include anything else. thanks.

0 Likes
Accepted solutions (1)
527 Views
4 Replies
Replies (4)
Message 2 of 5

hosneyalaa
Advisor
Advisor

Can you attached example drawing 

0 Likes
Message 3 of 5

Sea-Haven
Mentor
Mentor

Its not a hard task, but like hosneyalaa need info like text style and text height. 

 

(setq cpt (osnap (vlax-curve-getStartPoint obj) "gcen")) ; vl obj say pline

(setq hand (vlax-get obj 'handle))
0 Likes
Message 4 of 5

komondormrex
Mentor
Mentor
Accepted solution

check the following

(defun c:handle_cenroid (/ pline_sset region handle_text textalignmentpoint)
	(if (setq pline_sset (ssget '((0 . "lwpolyline") (-4 . "&=") (70 . 1))))
		(foreach pline (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex pline_sset))))
			(setq region (vla-addregion (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
						 				(vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0)) (list pline))
						 )
			)
			(setq handle_text (vla-addtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))              
										   (vla-get-handle pline)
										   (setq text_alignment_point (vlax-3d-point (vlax-get (setq region (car (vlax-safearray->list (vlax-variant-value region)))) 'centroid)))
										   (getvar 'textsize)
							  )
			)
			(vla-put-alignment handle_text 10)
			(vla-put-textalignmentpoint handle_text text_alignment_point)
			(vla-erase region)
		)
	)
	(princ)
)
0 Likes
Message 5 of 5

nathan.benchYTD9M
Explorer
Explorer

@komondormrex, the code works perfectly. Thank you!

0 Likes