本帖最后由 自贡黄明儒 于 2013-6-28 12:07 编辑
我是想一次框选,差不多在一条线的尺寸均对齐
对于尺寸,我只进行了一次预处理(vlax-put x 'TextMovement 0),应该还有别的,等各位高手完善一下
- ;;2.1 首先假定一张图上标注字体是同样大小,小于字高2X认为在同一行(列)
- ;;2.2 以选择或者生成的第一个对象作为基准对象
- ;;2.3 (100 . "AcDbAlignedDimension")才能用以对齐
- (defun DimensionDimDQ (/ SS TXTHT)
- ;;1 错误处理
- (defun *error* (s)
- (if (= 8 (logand (getvar "undoctl") 8))
- (command "_.undo" "_e")
- )
- (setvar "nomutt" 0)
- )
- ;;2 旋转一个点pnt
- (defun rotate_pnt (pnt p1 ang)
- (polar p1 (+ (angle p1 pnt) ang) (distance p1 pnt))
- )
- ;;3 对齐
- (defun HH:dimAliDo (SS / ANGL0 ANGLN DIS EN0 ENTLIS I
- OB0 P10 P10A P10N P10T P11 P11A P11N
- P11P P11PT P14 P14N SS1
- )
- (setq en0 (ssname ss 0)
- ob0 (vlax-ename->vla-object en0)
- entlis (entget en0)
- p10 (cdr (assoc 10 entlis))
- P14 (cdr (assoc 14 entlis))
- P11 (cdr (assoc 11 entlis))
- )
- (ssdel en0 ss)
- (setq p10a (rotate_pnt p14 p10 (/ pi 2.0))) ;p14绕p10转90度
- (setq p11a (mapcar '+ (mapcar '- p11 p10) p10a)) ;文字方向另一点
- (setq angl0 (abs (angle p10 p14))) ;角度
- (if (> angl0 Pi)
- (setq angl0 (rem angl0 Pi))
- )
- (if TxtHT
- nil
- (setq TxtHT
- (* (vlax-get ob0 'ScaleFactor) (vlax-get ob0 'TextHeight))
- )
- ;组码10误差在此内是同行(列)
- )
- (setq ss1 (ssadd))
- (repeat (setq i (sslength ss))
- (setq en0 (ssname ss (setq i (1- i)))
- entlis (entget en0)
- p10N (cdr (assoc 10 entlis))
- P14N (cdr (assoc 14 entlis))
- P11N (cdr (assoc 11 entlis))
- )
- ;;但愿基准对象的p10 p14是不等的
- (if (equal p10N P14N 0.001)
- (setq p10N p10
- P14N P14
- )
- )
- (setq anglN (abs (angle p10N p14N)))
- (if (> anglN pi)
- (setq anglN (rem anglN pi))
- )
- (setq P10T (inters p10 p10a p10N p14N nil))
- (setq dis (distance P10T p10N))
- ;;如果标注角度相同,高度小于字高一倍
- (if (and (equal anglN angl0 0.001) (< dis TxtHT))
- (progn
- (setq entlis (subst (cons 10 P10T) (assoc 10 entlis) entlis))
- (setq p11P (mapcar '+ (mapcar '- p11N p10N) p14N))
- (setq P11PT (inters p11P P11N p11 P11a nil))
- (entmod (subst (cons 11 P11PT) (assoc 11 entlis) entlis))
- )
- (setq ss1 (ssadd en0 ss1))
- )
- )
- (if (and ss1 (> (sslength ss1) 1))
- (HH:dimAliDo ss1)
- )
- )
- ;;4 主程序
- (princ "\n 第一选择或者生成的尺寸为对齐基准,请框选尺寸:")
- (setvar "nomutt" 1)
- (setq ss (ssget '((0 . "DIMENSION") (100 . "AcDbAlignedDimension"))))
- (setvar "nomutt" 0)
- (command "_.undo" "be")
- (if (and ss (> (sslength ss) 1))
- (progn
- (vlax-for x
- (vla-get-ActiveSelectionSet
- (vla-get-ActiveDocument (vlax-get-acad-object))
- )
- (vlax-put x 'TextMovement 0)
- )
- (HH:dimAliDo ss)
- )
- )
- (command "_.undo" "e")
- (gc)
- (princ)
- )
|