Modify on text align lisp please

Modify on text align lisp please

Anonymous
Not applicable
2,511 Views
3 Replies
Message 1 of 4

Modify on text align lisp please

Anonymous
Not applicable

I've found this code from 2012 for aligning text to a user-selected line here: http://forums.autodesk.com/[...]/3480202

And see the portion where TopCenter alignment is called.

 

Does anyone know of a way to remove the TopCenter align and make it keep the alignment of the source text objects?

 

Already tried hiding the (progn it falls under, but it still TopCenter aligns somehow.

We would like to use this code for Cable Block Diagram labeling.

Aside from my own added notes and a command name change, here is the code.

 

; USE THIS COMMAND TO ALIGN TEXT BY ITS INSERTION POINT
(defun c:MT1 (/ l ss i sn v p e) (vl-load-com)
;;; Tharwat 31. May. 2012 ;;;
  (if (and (setq l (car (entsel "\n Select Line :")))
           (eq (cdr (assoc 0 (entget l))) "LINE")
           (progn
             (prompt "Select texts to move to selected line")
             (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
           )
      )
    (repeat (setq i (sslength ss))
      (setq sn (ssname ss (setq i (1- i))))
      (setq v (vlax-ename->vla-object sn))
      (setq p (vlax-curve-getclosestpointto
                l
                (cdr (assoc 10 (entget sn)))
              )
      )
      (if (eq (cdr (assoc 0 (setq e (entget sn)))) "MTEXT")
        (progn
          (entmod (subst (cons 71 2) (assoc 71 e) e))
          (vla-put-insertionpoint v (vlax-3d-point p))
        )
        (progn
          (vla-put-alignment v acAlignmentTopCenter)
          (vla-put-TextAlignmentPoint v (vlax-3D-point p))
        )
      )
    )
  )
; (prompt "MT1.lsp loaded")
  (princ)
)

Thank you!

 

0 Likes
Accepted solutions (1)
2,512 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... 

Does anyone know of a way to remove the TopCenter align and make it keep the alignment of the source text objects?

 

Already tried hiding the (progn it falls under, but it still TopCenter aligns somehow.

.....

 

....
      (setq p (vlax-curve-getclosestpointto
                l
                (cdr (assoc 10 (entget sn)))
              )
      )
....
        (progn
          (vla-put-alignment v acAlignmentTopCenter)
          (vla-put-TextAlignmentPoint v (vlax-3D-point p))
        )
....

If the objects are not all of the same justification, that 10-code will be the insertion point only for Mtext and for left-justified Text, not for Text of other justifications, for which the 11-code entry is what you want.  Depending on the justification involved, that may be why it seems to change alignment though you hid the part you thought was doing that, but it could also be related to the different Property names for Text and Mtext.  Unless this has changed since the older version where I am now, Mtext doesn't have a TextAlignmentPoint property [= (assoc 11) in entity data], and again, for Left-justified Text that's always 0,0,0, and the insertion point is the InsertionPoint property.  I would suggest changing that line to this instead [minimally tested]:

 

(vlax-get v

  (if

    (or

      (= (vla-get-ObjectName v) "AcDbMText")

      (= (vla-get-Alignment v) 0); left-justified regular Text

    ); or

    'InsertionPoint ; then

    'TextAlignmentPoint ; else -- all other justifications of regular Text

  ); if

); vlax-get

 

which should get the right point, for any justification of either Text or Mtext.

 

Don't hide/remove the entire (progn) function, but only the line that changes the justification.  You still want the line that moves it, but again, it needs to use different Property names depending on the situation [also minimally tested]:

 

(vlax-put v
  (if
    (or
      (= (vla-get-ObjectName v) "AcDbMText")
      (= (vla-get-Alignment v) 0); left-justified regular Text
    ); or
    'InsertionPoint ; then
    'TextAlignmentPoint ; else
  ); if
  p
); vlax-put

Kent Cooper, AIA
Message 3 of 4

Anonymous
Not applicable

Thanks Kent! That makes more sense now that you show it broken out. I've added it to the base code but there is one thing still controlling the Justification, the section:

 

(entmod (subst (cons 71 2) (assoc 71 e) e))

 

Where 2 is the TopCenter call. In this part it is applied whenever any mtext is selected. Can this be replaced with a variant similar to the second portion of vlax-get? (I hope asking this way makes sense in the aim of the question).

 

Udpate: Hiding this line removes the override. The lisp is working as hoped now!

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

(entmod (subst (cons 71 2) (assoc 71 e) e))

 

Where 2 is the TopCenter call. In this part it is applied whenever any mtext is selected. ....

 

Udpate: Hiding this line removes the override. The lisp is working as hoped now!


Sorry -- I noticed one of their alignment-assignment lines, but not the other.  Good of you to figure it out.

 

And of course, since both the 'then' expression and the 'else' expression in that (if) test consist of only one function, you could also remove the (progn) "wrapping" functions from around them.  But even more than that, since the check on entity type is built into the (vlax-put... function at the end of my other Reply, you could replace the entire  (if (eq ... "MTEXT")  function, with its 'then'/'else' expressions, with that (vlax-put... function.

Kent Cooper, AIA
0 Likes