0% found this document useful (0 votes)
1 views

03_text_alignment

The document contains a Lisp function for AutoCAD that aligns text or mtext based on user-selected points. It calculates the insertion point and angle for the text based on the distance and angle between two specified points. The function also handles the creation of new text entities and deletion of the original text after alignment.

Uploaded by

mandarinos
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

03_text_alignment

The document contains a Lisp function for AutoCAD that aligns text or mtext based on user-selected points. It calculates the insertion point and angle for the text based on the distance and angle between two specified points. The function also handles the creation of new text entities and deletion of the original text after alignment.

Uploaded by

mandarinos
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

(defun c:text_alignment (/ placed_text point1

point2 coordinates point_length


gonia x y z
gonia1
)
(setvar "cmdecho" 0)
;(defun *error* (msg) (vl-bt))
(vl-load-com)
(while
(progn
(setvar "errno" 0)
(setq placed_text (entsel " Please pick your text"))

(cond

((= (getvar "errno") 52) ; exit if user pressed ENTER


nil ; exit loop
)
((vl-consp placed_text)
(cond
((or (= (cdr (assoc 0 (entget (car placed_text)))) "MTEXT")
(= (cdr (assoc 0 (entget (car placed_text)))) "TEXT")
)
(setq placed_text (car placed_text))
(setq point1 (getpoint "\n Get the start point"))
(setq point2 (getpoint "\n Get the end point"))
(setq coordinates (list point1 point2))
(setq point_length (distance point1 point2))
(setq gonia (angle point1 point2))
(setq x (/ point_length 2))
(setq y (/ (cdr (assoc 40 (entget placed_text))) 1.50))
(setq z (sqrt (+ (* x x) (* y y))))
(setq gonia1 (atan (/ y x)))
(setq tan1 (+ gonia1 gonia))

(if (and (>= gonia (/ pi 2)) (<= gonia (* pi 1.5)))


(progn
(setq tan1 (+ pi tan1))
(setq coordinates (reverse coordinates))
(setq gonia (+ pi gonia))
)
)
(setq coordinates (trans (car coordinates) 0 1))
(setq point_insertion (polar coordinates tan1 z))

(if (member (cdr (assoc 0 (entget placed_text))) '("MTEXT"))


(progn
(setq
new_ent
(entmakex
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 point_insertion)
;(cons 11 point_insertion)
(cons 1 (cdr (assoc 1 (entget placed_text))))
(cons 71 5)
(cons 50 gonia)
(cons 7 (cdr (assoc 7 (entget placed_text))))
(cons 8 (cdr (assoc 8 (entget placed_text))))
(cons 40
(cdr (assoc 40 (entget placed_text)))
)
(cons 41 point_length)
(cons 43
(cdr (assoc 40 (entget placed_text)))
)
)
)
)
(entdel placed_text)
)
)

(if (member (cdr (assoc 0 (entget placed_text))) '("TEXT"))


(progn
(setq
new_ent
(entmakex
(list
(cons 0 "TEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbText")
(cons 10 point_insertion)
(cons 11 point_insertion)
(cons 1 (cdr (assoc 1 (entget placed_text))))
(cons 71 0)
(cons 72 4)
(cons 73 2)
(cons 50 gonia)
(cons 7 (cdr (assoc 7 (entget placed_text))))
(cons 8 (cdr (assoc 8 (entget placed_text))))
(cons 40
(cdr (assoc 40 (entget placed_text)))
)
(cons 41
(cdr (assoc 41 (entget placed_text)))
)
)
)
)
(entdel placed_text)
)
)
t
);;end condition1
((/= (cdr (assoc 0 (entget (car placed_text)))) "MTEXT")
(alert "\n It is not a text or mtext")
t
);;end condition2

((/= (cdr (assoc 0 (entget (car placed_text)))) "TEXT")


(alert "\n It is not a text or mtext")
t
);;end condition3
) ;;end inner condition
);;end check if it is a list
(t
(alert "\n** Nothing Selected **")
t
);;end condition1
);;end general condition
);;end progn
);;end while
(princ)
);;end function

;|(setq e111 (entget e11))


(setq plinelength (vlax-curve-getdistatparam e11(vlax-curve-getendparam e11)))
;;Get points of the polyline
(setq pts (mapcar 'cdr
(vl-remove-if-not
(function (lambda (pt) (= (car pt) 10)))
(entget e11)
)
)
)|;

You might also like