;我计算楼梯过程中,核对踏步宽度高度是否正确,做的一个小程序,选中带符号的文字,将计算结果放置在右下角,图层为当前图层。
;感谢高飞大神
- (defun c:CAt (/ box Els ent i lst nls num p1 p2 p3 p4 sel strlst wcs wz_jd wz_obj wz_zg)
-
- (if
- (or
- (setq wcs (vlax-create-object "Aec32BitAppServer.AecScriptControl.1"))
- (setq wcs (vlax-create-object "ScriptControl"))
- )
- (vlax-put-property wcs "language" "VBScript")
- )
- (setq i 0)
- (setq sel (ssget '((0 . "text"))))
- (repeat (sslength sel)
- (setq ent (ssname sel i))
- (command "ucs" "e" ent)
- (setq wz_obj (vlax-ename->vla-object ent))
- (setq wz_jd (vlax-get-property wz_obj 'Rotation)) ;取得角度
- (setq wz_zg (vlax-get-property wz_obj 'Height)) ;取得字高
- (setq lst (entget ent))
- (setq box (textbox lst)) ;取得文字的外框坐标
- (setq p1 (car box))
- (setq p3 (cadr box))
- (setq p2 (list (car p3) (cadr p1)));p2为文字插入坐标
- (setq p2 (trans p2 1 0))
- (setq p4 (list (car p1) (cadr p3)))
-
- (setq num (cdr (assoc 1 lst)))
- (if (wcmatch (cdr (assoc 0 lst)) "*_TEXT")
- (setq num (atof num))
- (progn
- (foreach s '("㎡" "平方米" "米")
- (while (/= num (setq num (vl-string-subst "" s num))))
- )
- (while (/= num (setq num (vl-string-subst "*" "×" num))))
- (setq num (vl-string-translate "xX" "**" num))
- ;;优先使用CAD的cal函数计算.
- (if CAL
- (setq num (float (cal (strcat num "+0.0")))) ;这个地方需要转化为浮点,不然cal函数会出错
- ;;然后采用vbs计算
- (if wcs
- (setq num (vlax-invoke wcs 'eval num))
- (setq num (CAL:Expr2Value Num))
- )
- )
- )
- )
- ;;; (setq Els (cons ent Els))
- ;;; (setq Nls (cons num Nls))
- (entmake (list '(0 . "TEXT") (cons 1 (rtos num)) (cons 10 p2) (cons 40 (* 0.3 wz_zg))))
- (setq i (1+ i))
- )
- (command "ucs" "")
- ;;; (list
- ;;; (reverse Els)
- ;;; (reverse Nls)
- ;;; )
- (prin1)
- )
- (prompt "\n根据高飞大神四则运算进行修改<c:cat>")
- (prin1)
|