本帖最后由 ZZXXQQ 于 2014-7-27 07:40 编辑
- (vl-load-com)
- (defun c:ddr (/ n x ent entL p2 p3 px1 px2 py1 py2 ptdd xl sa pt0 ppt ptdd ss1)
- (setvar "cmdecho" 0)
- (command "undo" "be")
- (setq entL '() ss1 (ssadd))
- (if (setq ent (centsel "\n选择标注 或 <退出>:" "DIMENSION")) (progn
- (ssadd ent ss1);+1
- (setq x (entget ent)
- entL (cons ent entL)
- p2 (dxf 13 x)
- p3 (dxf 14 x)
- px1 (list (car p2) (/ (+ (cadr p2)(cadr p3)) 2))
- px2 (list (car p3) (/ (+ (cadr p2)(cadr p3)) 2))
- py1 (list (/ (+ (car p2)(car p3)) 2) (cadr p2))
- py2 (list (/ (+ (car p2)(car p3)) 2) (cadr p3))
- ptdd (list p2 p3)
- XL (entget (dxf -2 (tblsearch "block" (dxf 2 x))))
- SA (abs (sin (angle (dxf 10 xl) (dxf 11 xl)))))
- (while (setq pt0 (getpoint "\n取点 或 <退出>:"))
- (command ".copy" ent "" "0,0" "@")
- (setq entL (cons (entlast) entL))
- (ssadd (entlast) ss1);+2
- (cond
- ((equal SA 1 1e-6) ;;水平
- (setq ptdd (cons (ptper pt0 px1 px2) ptdd)
- ppt (Lsort ptdd 0))
- )
- ((equal SA 0 1e-6) ;;垂直
- (setq ptdd (cons (ptper pt0 py1 py2) ptdd)
- ppt (Lsort ptdd 1))
- )
- (t
- (setq ptdd (cons (ptper pt0 p2 p3) ptdd)
- ppt (Lsort ptdd 2))
- )
- )
- (setq ppL (mapcar 'list ppt (cdr ppt))
- n 0)
- (repeat (length ppL)
- (setq xf (entget (nth n entL))
- nxf (subst (cons 13 (car (nth n ppL)))(assoc 13 xf) xf)
- wxf (subst (cons 14 (cadr (nth n ppL)))(assoc 14 nxf) nxf)
- n (1+ n))
- (entmod wxf)
- )
- )
- )
- (princ "\n退出")
- )
- (yad_dimad1 ss1);+3
- (command "undo" "e") (setvar "cmdecho" 1)
- (princ)
- )
- (defun centsel (msg f)
- (while (if (setq el (car (entsel msg))) (if (= (cdr (assoc 0 (entget el))) f) nil t) nil))
- el
- )
- ;;取值dxf
- (defun dxf (x e)(cdr (assoc x e)))
- ;;求垂足
- (defun ptper (pt0 pt1 pt2)
- (inters pt0 (polar pt0 (+ (angle pt1 pt2) (/ pi 2)) 1.0) pt1 pt2 nil)
- )
- ;;排序 0 水平 1 垂直 2 倾斜
- (defun Lsort (LT i)
- (cond
- ((or (= i 0)(= i 2))(setq Lt (vl-sort LT '(lambda (e1 e2)(< (car e1) (car e2))))))
- ((or (= i 1)(= i 2))(setq Lt (vl-sort LT '(lambda (e1 e2)(< (cadr e1) (cadr e2))))))
- )
- )
- (princ)
|