Align text to a picked point

Align text to a picked point

ramimann
Contributor Contributor
5,361 Views
27 Replies
Message 1 of 28

Align text to a picked point

ramimann
Contributor
Contributor

Hello Everyone
I need a code that can align text (from X or Y of insertion point) to "x" or "y" of a picked point.In fact, when I pick a point,the word will move to that X,maintaining the Y coordinate or to the Y of picked point,maintaining the X coordinate. Does anybody have such a lisp?
Thanks in advance

0 Likes
Accepted solutions (1)
5,362 Views
27 Replies
Replies (27)
Message 2 of 28

ВeekeeCZ
Consultant
Consultant

Perhaps THIS Lee's routine?

0 Likes
Message 3 of 28

Kent1Cooper
Consultant
Consultant

I kind-of think I understand what you're asking, but can you post an image with some before-and-after illustrations?  Also, are you talking about separate commands for the change-the-X and change-the-Y versions, or one command that would change whichever is the greater change [similarly to what happens when you draw a Line with ORTHO on]?

Kent Cooper, AIA
0 Likes
Message 4 of 28

TomBeauford
Advisor
Advisor

http://www.theswamp.org/index.php?action=post;topic=55138.0

https://forums.augi.com/showthread.php?173555-Align-Text-to-picked-point

https://www.cadtutor.net/forum/topic/67495-align-text-to-a-picked-point/

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 5 of 28

ramimann
Contributor
Contributor

Hello

This is an illustrationIllustration2.png

This is for the "X" alignment.

Sure, I want a separate command for each: X and Y...

0 Likes
Message 6 of 28

ramimann
Contributor
Contributor

Hello

Sorry, that doesn't help me,that code aligns texts to each other.I just want to align text to a picked point.

0 Likes
Message 7 of 28

SEANT61
Advisor
Advisor
That type of operation is way more applicable to operations/entities than just moving text.  It may make sense to set up some Point/Coordinate Filter macros to have on hand during the full operational day.
 
OnlyX macro as demoed:
.yz;non;@;

 

 


************************************************************
May your cursor always snap to the location intended.
Message 8 of 28

ВeekeeCZ
Consultant
Consultant

OnlyX ... this name makes sense!

0 Likes
Message 9 of 28

Kent1Cooper
Consultant
Consultant
Accepted solution

@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
Message 10 of 28

ramimann
Contributor
Contributor

Thanks a lot

That exactly what I wanted.It only lacks support for Mtext and attributes...Good work

 

 

 

 

 

 

 

 

0 Likes
Message 11 of 28

Kent1Cooper
Consultant
Consultant

@ramimann wrote:

....It only lacks support for Mtext and attributes...


 

If that's wanted, try this adjustment.  Attributes are defined the same way as regular Text in regard to these things, so it's just a matter of allowing them in selection.  Mtext has only the InsertionPoint property, regardless of justification, which means lumping all Mtext into a common category with only-Left-justified Text/Attdefs.  Minimally tested:

(defun textalign (coord / ss ali n txt txtobj inspt); subroutine used in both commands
  (if
    (and
      (setq ss (ssget '((0 . "*TEXT,ATTDEF"))))
      (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)))
        txtobj (vlax-ename->vla-object txt); [moved earlier instead of nested later]
      )
      (command "_.move" txt ""
        "_none"
        (setq inspt
          (if
            (or
              (= (vla-get-ObjectName txtobj) "AcDbMText"); any Mtext
              (= (vla-get-Alignment txtobj) 0); Left-justified Text/Attdef
            ); or
            (vlax-get txtobj 'InsertionPoint); then
            (vlax-get txtobj 'TextAlignmentPoint); else
          ); 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
Kent Cooper, AIA
0 Likes
Message 12 of 28

ronjonp
Advisor
Advisor

@Kent1Cooper I don't think you need to check alignment points when moving X Y or Z.

See this from my library:

(defun c:xy (/ a i k p s)
  ;; RJP » 01.03.2018
  (or (setq k (getenv "AlignStuff")) (setq k "X"))
  (cond
    ((and (not (initget "X Y Z"))
	  (setq	k (cond	((getkword (strcat "\nAlignment [X/Y/Z] <" k ">: ")))
			(k)
		  )
	  )
	  (setq p (getpoint "\nPick an alignment point: "))
	  (setq s (ssget ":L" '((0 . "attdef,insert,mtext,text"))))
     )
     (setenv "AlignStuff" k)
     (setq i (vl-position k '("X" "Y" "Z")))
     (setq a (nth i p))
     (foreach b	(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
       (vlax-put b
		 'insertionpoint
		 (mapcar '(lambda (x)
			    (if	(= i (vl-position x p))
			      a
			      x
			    )
			  )
			 (setq p (vlax-get b 'insertionpoint))
		 )
       )
     )
    )
  )
  (princ)
)
(vl-load-com)

**Nevermind about the alignment comment .. just saw THIS. 🙂

0 Likes
Message 13 of 28

ronjonp
Advisor
Advisor

See HERE too...

0 Likes
Message 14 of 28

ramimann
Contributor
Contributor

Thanks.That's nice,but the shortcut menu with every instance is not so clever.

0 Likes
Message 15 of 28

ramimann
Contributor
Contributor

Helo...It worked very well with text and mtext.At present I don't need it for  attributes, for wich I'll solve the problem with the shortcuts suggested by Tom Beauford  at :https://forums.augi.com/showthread.php?173555-Align-Text-to-picked-point&p=1341833#post1341833

I can say my problem is solved.

Thanks a lot

Message 16 of 28

Code_x
Advocate
Advocate

Hi , could you please explain step by step how you created this macro. This one you are showing in your video .XY snap. I tried different ways it doesn’t work for me. Thank you. 

Code_x_0-1654231243154.png

 

0 Likes
Message 17 of 28

SEANT61
Advisor
Advisor

@Code_x wrote:

. . . . This one you are showing in your video .XY snap. I tried different ways it doesn’t work for me. . . .

 

 


I'm a little confused on what you are looking to do. The Command Macro as shown in that screen capture  restricts

the acquired point to just the X coordinate (setup as shown in the attached image).  Or, are you trying to expand that coordinate restriction to both X and Y (i.e., ignoring Z coordinate)?


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 18 of 28

Code_x
Advocate
Advocate

Hi, 

Please see the video recording that i did to show you what i am trying to do. The first part of the video recording is the 3ds max and it has that function. That is what i am looking for. You script is similar to that.  For AutoCAD LT I tried using your script, but I can't get it to work, what is wrong with it? 

 

Link to the video recording : 

https://we.tl/t-iwXtJ5NmJA

 

I couldn't post video on this form; it doesn't let me.  Thank you! 

0 Likes
Message 19 of 28

ВeekeeCZ
Consultant
Consultant

.x;non;@

Moves vertices in Y direction nicely HERE 

A macro could be assigned to a keyboard shortcut. I used Ctrl+Alt+E for the show.

Message 20 of 28

SEANT61
Advisor
Advisor

Based on your screen recording it appears you are invoking the OnlyX macro too soon in the point acquisition process.  For instance, if I use a similar setup, this would be the command prompt sequence:

 

Command: _stretch
Select objects to stretch by crossing-window or crossing-polygon...
Select objects: Specify opposite corner: 1 found  - Crossing Window Selection of one side of Polyline -

Select objects:  - Enter to end geometry selection - 

Specify base point or [Displacement] <Displacement>:  - Select Base Point, then invoke OnlyX -
Specify second point or <use first point as displacement>: .yz
of non
@
(need X): - Select Next point that will have the appropriate "X" value -


************************************************************
May your cursor always snap to the location intended.