@ramimann wrote:
....
I need a code that can align text (from X or Y of insertion point) to "x" or "y" of a picked point. ....
To do so with as many Text objects as you want at once, try this [lightly tested, and without the usual enhancements yet]:
(defun textalign (coord / ss ali n txt txtobj inspt); subroutine used in both commands
(if
(and
(setq ss (ssget '((0 . "TEXT"))))
(setq ali (getpoint (strcat "\nPoint to align Text insertion points at its " coord " position: ")))
); and
(repeat (setq n (sslength ss))
(setq txt (ssname ss (setq n (1- n))))
(command "_.move" txt ""
"_none"
(setq inspt
(if (= (vla-get-Alignment (setq txtobj (vlax-ename->vla-object txt))) 0)
(vlax-get txtobj 'InsertionPoint); then - Left-justified
(vlax-get txtobj 'TextAlignmentPoint); else - other justifications
); if
); setq
"_none"
(list
(car (if (= coord "X") ali inspt)); X coordinate of second point
(cadr (if (= coord "Y") ali inspt)); Y coordinate
); list
); command
); repeat
); if
(princ)
); defun
(defun C:TAX () (textalign "X")); = Text Align at X coordinate
(defun C:TAY () (textalign "Y")); = Text Align at Y coordinate
(vl-load-com); if needed
If Text is of Fit or Aligned justification, it uses the right-end-of-baseline definition point. If you ever use those, and if desired, it could be adjusted to differentiate those justifications from other not-plain-Left justifications, and use the left-end point instead, or the middle of the baseline if that makes sense for your purposes.
It's for plain TEXT only -- accommodations would need to be made if you want to also use it with MTEXT, and/or Attribute Definitions.
Kent Cooper, AIA