如何在多段线最长的那段标注
求助各位大神,有没有办法选中多段线后,获取最长的那一段的中点和角度,然后在旁边标注。(效果如图)小弟编程能力有限,只能勉强获得中点坐标。(defun c:ss (en / n s1 ent ent_data vertex_data vertex_coords maxi)
(setq ent_data (entget en))
; 获得多段线全部顶点坐标
(setq vertex_data (vl-remove-if '(lambda (X) (/= 10 (car x))) ent_data))
(setq vertex_coords (mapcar 'cdr vertex_data))
; 两两之间遍历长度,获得最长那段的两个端点
(setq n 0)
(setq maxi 0)
(setq len (length vertex_coords))
(repeat (- len 1)
(setq long (distance (nth n vertex_coords) (nth (+ 1 n) vertex_coords)))
(if (> long maxi) (setq p1 (nth n vertex_coords) p2 (nth (+ 1 n) vertex_coords)))
(setq n (+ 1 n))
)
(princ p1)
(princ p2)
(prin1)
)这是获得中点的部分,如何获得角度,以及生成标注求助各位高手 (setq w1 (angle zb1 zb2))
(setq w2 (* w2 57.29577951))
(setqpt_list (strcat "DN50-" cd ))
(command "text" "TL"pt 0.3 ww2 pt_list)
未考虑角度规则化
(defun c:tt(/ ang en lst m n pt1 pt2 ptm ss)
(setq ss (ssget '((0 . "lwpolyline"))))
(repeat (setq n (sslength ss))
(setq en(ssname ss (setq n (1- n)))
lst nil)
(repeat(setq m (fix (vlax-curve-getendparam en)))
(setq lst
(cons (- (vlax-curve-getdistatparam en m)
(vlax-curve-getdistatparam
en
(setq m (1- m))))
lst)))
(setq m (vl-position (apply 'max lst) lst)
pt1 (vlax-curve-getpointatparam en m)
pt2 (vlax-curve-getpointatparam en (1+ m))
ptm (mapcar '(lambda (x y) (* 0.5 (+ x y))) pt1 pt2)
ang (angtos (angle pt1 pt2) 0 5))
(vl-cmdf "dtext" "j" "c" "non" ptm 300 ang "DN150-100")))
bonny 发表于 2024-4-16 02:50
bonny一出手,就知有没有。
页:
[1]