用 API 方式一
 - (defun c:tt (/ ss lst first pts p1 p2 slst bs plane )
- (if (setq ss (ssget '((0 . "dimension"))))
- (progn
- (setq lst (xdrx_pickset->ents ss)
- first (car lst)
- pts (xdrx_entity_getstretchpoint first)
- p1 (nth 3 pts)
- p2 (nth 4 pts)
- slst (mapcar '(lambda (x / v)
- (list
- (xdrx_point_dist2line
- (nth 2 (xdrx_entity_getstretchpoint x))
- p1
- p2
- )
- x
- )
- )
- lst
- ) ;_其它标注相对于第一个标注的位置
- slst (mapcar
- 'cadr
- (vl-sort slst '(lambda (x1 x2) (< (car x1) (car x2))))
- ) ;_按距离排序
- )
- (if (minusp (xdrx_point_dist2line (car pts) p1 p2))
- (setq bs (last slst)
- slst (cdr (reverse slst))
- )
- (setq bs (car slst)
- slst (cdr slst)
- )
- ) ;_根据标注方向确定基准标注
- (setq pts (xdrx_entity_getstretchpoint bs)
- plane (list (nth 3 pts) (mapcar '- (nth 3 pts) (cadr pts)))
- )
- (mapcar
- '(lambda (x / p)
- (setq p (xdrx_point_orthoproject
- (xdrx_getpropertyvalue x "dimlinepoint")
- plane
- )
- )
- (xdrx_setpropertyvalue x "dimlinepoint" p)
- )
- slst
- )
- )
- )
- (princ)
- )
|