标注断开 和标注合并都 可以用,只是不能先选择再执行,请教明经ER帮忙一下,万分感谢
;;========================================;; 标注断开+连续标注程序
;; by明经通道QQ: 9034598 2009年8月15日
;;========================================
(vl-load-com)
(defun c:ddr (/ n x ent entL p2 p3 px1 px2 py1 py2 ptdd xl sa pt0 ppt ptdd)
(setvar "cmdecho" 0)
(command "undo" "be")
(setq entL '())
(if (setq ent (centsel "\n选择标注 或 <退出>:" "DIMENSION"))
(progn
(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.0))
px2 (list (car p3) (/ (+ (cadr p2)(cadr p3)) 2.0))
py1 (list (/ (+ (car p2)(car p3)) 2.0) (cadr p2))
py2 (list (/ (+ (car p2)(car p3)) 2.0) (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))
(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退出")
)
(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 (function (lambda (e1 e2)(< (car e1) (car e2)))))))
((or (= i 1)(= i 2))(setq Lt (vl-sort LT (function (lambda (e1 e2)(< (cadr e1) (cadr e2)))))))
))
(princ)
;;标注合并
(defun c:ddc( / d13 d14 dxf dxfn e1 e2 n p13 p14 plst ss)
(command "ucs" "w")
(setvar "cmdecho" 0)
(princ "\n选择标注尺寸...")
(setq ss (ssget '((0 . "DIMENSION"))))
(setq n -1 plst '())
(repeat (sslength ss)
(setq dxf (entget (ssname ss (setq n (1+ n)))))
(setq d13 (cdr (assoc 13 dxf))
d14 (cdr (assoc 14 dxf)))
(setq plst (cons d13 (cons d14 plst)))
)
(setq plst (vl-sort plst (function (lambda (e1 e2) (< (car e1) (car e2))))))
(setq plst (vl-sort plst (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))))
(setq p13 (car plst) p14 (last plst))
(setq dxfn (subst (cons 13 p13) (assoc 13 dxf) dxf)
dxfn (subst (cons 14 p14) (assoc 14 dxfn) dxfn))
(entmake dxfn)
(command ".erase" ss "")
(command "ucs" "p")
(princ)
)
标注断开 和标注合并都 可以用,只是不能先选择再执行,请教明经ER帮忙一下,万分感谢
主要修改了centsel函数,可以先选择了
(vl-load-com)
(defun c:ddr (/ n x ent entl p2 p3 px1 px2 py1 py2 ptdd xl sa pt0 ppt ptdd)
(setvar "cmdecho" 0)
(if (setq ent (centsel "\n选择标注 或 <退出>:" "DIMENSION"))
(progn
(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.0))
px2 (list (car p3) (/ (+ (cadr p2) (cadr p3)) 2.0))
py1 (list (/ (+ (car p2) (car p3)) 2.0) (cadr p2))
py2 (list (/ (+ (car p2) (car p3)) 2.0) (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 "undo" "be")
(command ".copy" ent "" "0,0" "@")
(setq entl (cons (entlast) entl))
(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)
)
(command "undo" "e")
)
)
(princ "\n退出")
)
(setvar "cmdecho" 1)
(princ)
)
(defun centsel (msg f / ent ss)
(princ msg)
(while (null ent)
(setq ss (ssget(list (cons 0 f))))
(if ss
(setq ent (ssname ss 0))
)
)
(redraw ent 3)
ent
)
;;取值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 (function (lambda (e1 e2) (< (car e1) (car e2)))))))
((or (= i 1) (= i 2))
(setq lt (vl-sort lt (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))))
)
)
)
(princ) 合并只要把ucs的那行去掉就可以了,断开因为是使用entsel的,也没法改先选后执行。
(defun c:ddc (/ d13 d14 dxf dxfn e1 e2 n p13 p14 plst ss)
(setvar "cmdecho" 0)
(princ "\n选择标注尺寸...")
(setq ss (ssget '((0 . "DIMENSION"))))
(setq n -1)
(repeat (sslength ss)
(setq dxf (entget (ssname ss (setq n (1+ n)))))
(setq d13 (cdr (assoc 13 dxf))
d14 (cdr (assoc 14 dxf))
)
(setq plst (cons d13 (cons d14 plst)))
)
(setq plst (vl-sort plst
(function (lambda (e1 e2) (< (car e1) (car e2))))
)
plst (vl-sort plst
(function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
)
p13(car plst)
p14(last plst)
dxfn (subst (cons 13 p13) (assoc 13 dxf) dxf)
dxfn (subst (cons 14 p14) (assoc 14 dxfn) dxfn)
)
(command "undo" "be")
(entmake dxfn)
(command ".erase" ss "")
(command "undo" "e")
(setvar "cmdecho" 1)
(princ)
)
谢谢楼上的,本人一点也不懂LSP,所以...
还有个一断开有大神帮忙解决一下么? 这分不足以表示我对你的感谢,对你的热心鼓掌10分钟,真心感谢~ 谢谢分享
~~~~
谢谢分享!!! vectra 发表于 2014-10-25 11:12
主要修改了centsel函数,可以先选择了
不错不错,这是我想要的效果。 高手,受教了
页:
[1]