วันพุธที่ 12 สิงหาคม พ.ศ. 2552

Visual LISP: เขียนข้อความบอกขนาดเส้นตรงบนเส้นที่เลือก

โค้ดนี้แสดงถึงการ approch ด้วย Visual LISP 100% สังเกตถึงแนวทางการใช้จุดอ้างอิงบน WCS ใน VXX Function และการกำหนด Justify ของข้อความ รวมถึงการกำหนดแนวเขียนข้อความ

;;; Place TEXT (length of the selected line) on the selected line.
(vl-load-com)
(defun c:LL (/ *acaddoc* *modelspace* e obj pt len textobj textangle)
;; #texth=Plotted text height, Use with Annotative Text Style.
(if (not #texth)
(setq #texth 2.5) ;***PUT TEXT HEIGHT HERE****
)
(setq *acaddoc* (vla-get-activedocument (vlax-get-acad-object))
*modelspace* (vla-get-modelspace *acaddoc*)
)
(vla-startundomark *acaddoc*)
(while (setq e (entsel "\nSelect line: "))
(setq obj (vlax-ename->vla-object (car e)))
(if (= "AcDbLine" (vla-get-ObjectName obj))
(progn
(setq pt (vlax-curve-getClosestPointTo obj (trans (cadr e) 1 0))
len (rtos (vla-get-Length obj))
textobj (vlax-invoke *modelspace* 'AddText len pt #texth)
textangle (vlax-get obj 'Angle)
)
(cond
((and
(>= textangle pi)
(<= textangle (* 3.0 (/ pi 2.0)))
)
(setq textangle (- textangle pi))
)
((and (> textangle (/ pi 2.0)) (<= textangle pi))
(setq textangle (+ textangle pi))
)
)
(vlax-put textobj 'Rotation textangle)
(vlax-put textobj 'Alignment acAlignmentBottomCenter)
(vlax-put textobj 'TextAlignmentPoint pt)
)
(princ "\nNot LINE object!!!")
)
)
(vla-endundomark *acaddoc*)
(princ)
)