🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[^_^]:http://bbs.mjtd.com/forum.php?mod=viewthread&tid=108062&extra=page%3D2%26filter%3Dtypeid%26typeid%3D107 操作步骤: 1、输入命令 ng:dim 2、指定文字偏移,默认为20 3、绘制标注 4、指定文字偏移方向 效果图 ![](https://box.kancloud.cn/05d7b5278841a0618358f3c80e86a2a5_752x366.gif) 源码 ``` (DEFUN C:ng:dim () (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq docObj (vla-get-ActiveDocument acadObj)) (setq dis(getreal "标注文字的偏移距离:")) (if (null dis) (setq dis 20) ) (COMMAND "_dimaligned" pause pause pause) ;(princ "eeeee") (SETQ dimEnt (entlast)) (setq dimObj (vlax-ename->vla-object dimEnt)) (setq p1Obj (vla-get-ExtLine1Point dimObj)) (setq p2Obj (vla-get-ExtLine2Point dimObj)) (setq textPosition (vlax-safearray->list (vlax-variant-value (vla-get-textPosition dimObj)))) (setq p1 (vlax-safearray->list (vlax-variant-value p1Obj))) (setq p2 (vlax-safearray->list (vlax-variant-value p2Obj))) (setq angleP1P2 (angle p1 p2)) (setq midPoint (polar p1 angleP1P2 (/ (distance p1 p2) 2))) (setq textDir (textDirection p1 p2 textPosition)) ;(princ (strcat "textDir:" (rtos textDir))) (setq textPoint (polar midPoint (+ angleP1P2 textDir) dis) ) (vla-put-textPosition dimObj (vlax-3d-point textPoint)) (print textPoint) ; ; (setq myresult ; (vla-AngleFromXAxis ; (vla-get-utility docObj) p1 p2)) ) ;用于判断标注文字在标注基线的顺时针方向还是逆时针方向 (DEFUN textDirection (startP endP textP / angle1 angle2 _temp) (DEFUN _temp(angle1 angle2) (and (>= angle2 angle1) (<= (- angle2 angle1) (/ pi 2))) ) (setq angle1 (angle startP endP)) (setq angle2 (angle startP textP)) (cond ( (_temp angle1 angle2) (/ pi 2) ) ( (progn (setq angle2 (+ angle2 (* 2 pi))) (_temp angle1 angle2) ) ( / pi 2)) (t (- (/ pi 2))) ) ) ```