Sunday, October 14, 2012

Simple AutoLISP Code: Flip Dimension Text

This is a command I called D180, which function is rotating a dimension text by 180 degree.

(defun errD180 (msg)
(command)
(setq *error* localErrorD180)
(prompt "\nError. Program cancelled. ")
(princ)
)
(defun C:D180 (/ localErrorD180 dimProperty dimTxtRotationOld dimTxtRotationNew dimTxtRotationUpdate)
(setq localErrorD180 *error*)
(setq *error* errD180)
(setq dimProperty (entget (car (entsel "\nSelect dimension: "))))
(setq dimTxtRotationOld (cdr (assoc 51 dimProperty)))
(setq dimTxtRotationNew (+ dimTxtRotationOld (deg2rad 180)))
(setq dimTxtRotationUpdate (subst (cons 51 dimTxtRotationNew) (assoc 51 dimProperty) dimProperty))
(entmod dimTxtRotationUpdate)
(setq *error* localErrorD180)
(princ)
)
(defun deg2rad (d)
(* pi (/ d 180.0))
)

I must admit the codes are rather clumpy and crude. I've seen the same purpose achieved by lesser lines and much elegant codes, but that's beyond my programming skill. :-)

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...