Jump to content

Set DTEXT TextAlignmentPoint to bottom center


3dwannab

Recommended Posts

Hi all,

 

I'm struggling to set DTEXT justification to bottom centre. I've put the alignment to bottomcenter in the code below but it's the alignment point I'm having difficulty with.

 

MTEXT is much more straight forward it seems.

 

(setq obj (vlax-ename->vla-object (setq en (car (entsel)))))
(setq ent (entget en))

(cond 

  ;; If it's TEXT
  ((eq (cdr (assoc 0 ent)) "TEXT")
   (princ "\nIS TEXT\n")
   (vla-put-Alignment obj acAttachmentPointBottomCenter)

   ;; Having trouble with DTEXT to set the TextAlignmentPoint to bottom center
   (vla-put-TextAlignmentPoint obj (vlax-3d-point 0 0 0))
  )

  ;; If it's MTEXT
  ((eq (cdr (assoc 0 ent)) "MTEXT")
   (princ "\nIS MTEXT\n")
   (vla-put-AttachmentPoint obj acAttachmentPointBottomCenter)
  )
)

 

Link to comment
Share on other sites

Try

(vla-put-Alignment obj 'acAttachmentPointBottomCenter)

 

You may be able to use a number also 1-9 rather than acAttachmentPointBottomCenter  2 or 8, not tested but works with some VL commands.

Link to comment
Share on other sites

This?

(setq obj (vlax-ename->vla-object (setq en (car (entsel)))))
(setq ent (entget en))

(cond 

  ;; If it's TEXT
  ((eq (cdr (assoc 0 ent)) "TEXT")
   (princ "\nIS TEXT\n")
    (setq pos (vla-get-InsertionPoint obj))
    (vla-put-Alignment obj 13)
    (vla-put-TextAlignmentPoint obj pos)
  )

  ;; If it's MTEXT
  ((eq (cdr (assoc 0 ent)) "MTEXT")
   (princ "\nIS MTEXT\n")
   (vla-put-AttachmentPoint obj acAttachmentPointBottomCenter)
  )
)

 

  • Like 1
Link to comment
Share on other sites

12 hours ago, Tsuky said:

This?

Thanks, yes, it does indeed work but I found a piece of code in Lee Macs DynamicTextAlign program that doesn't change the location of the DTEXT. So full credit to him for that once again.

 

With your example, it shifts the DTEXT to another position.

 

(setq obj (vlax-ename->vla-object (setq en (car (entsel)))))
(setq ent (entget en))

(cond 

  ;; If it's TEXT
  ((eq (cdr (assoc 0 ent)) "TEXT")
   (princ "\nIS TEXT\n")
   (vla-put-Rotation obj 0) ;; Set text rotation to 0
   (vla-put-Height obj (getvar "textsize")) ;; Set text rotation to 0

   ;; Alignment Taken from DynamicTextAlign by LeeMac
   ;; 8 below is bottomcenter
   (if (eq AcAlignmentLeft (vla-get-Alignment obj)) 
     (progn 
       (setq tmp (vla-get-InsertionPoint obj))
       (vla-put-Alignment obj (+ 8 5))
       (vla-put-TextAlignmentPoint obj tmp)
     )
     (vla-put-Alignment obj (+ 8 5))
   )
  )

  ;; If it's MTEXT
  ((eq (cdr (assoc 0 ent)) "MTEXT")
   (princ "\nIS MTEXT\n")
   (vla-put-Rotation obj 0) ;; Set text rotation to 0
   (vla-put-Height obj (getvar "textsize")) ;; Set text height to 0
   (vla-put-Width obj 0) ;; Set text width to 0
   (vla-put-AttachmentPoint obj 8)
  )
)

 

14 hours ago, BIGAL said:
(vla-put-Alignment obj 'acAttachmentPointBottomCenter)

 

 

That's what I did have. It's the vla-put-TextAlignmentPoint which needs to be there to alter the justification after vla-put-Alignment.

Link to comment
Share on other sites

Not sure if this is any help, I use these to justify text (single command, example JUBC - JUstify Bottom Centre). Should also work with a single entity rather than a selection set.

 

(defun c:jul()  (jut  "l"))
(defun c:juc()  (jut  "c"))
(defun c:jur()  (jut  "r"))
(defun c:jutl() (jut "tl"))
(defun c:jutc() (jut "tc"))
(defun c:jutr() (jut "tr"))
(defun c:juml() (jut "ml"))
(defun c:jumc() (jut "mc"))
(defun c:jumr() (jut "mr"))
(defun c:jubl() (jut "bl"))
(defun c:jubc() (jut "bc"))
(defun c:jubr() (jut "br"))

;;https://www.cadtutor.net/forum/topic/35569-text-justification-lisp/
(defun jut (just / ss)
  (princ (strcat "\nSelect Text"))
  (if (setq ss (ssget "_:L" '((0 . "ATTDEF,MTEXT,TEXT"))))
    (command "_.justifytext" ss "" just)
  )
  (princ)
)

 

 

 

  • Like 1
Link to comment
Share on other sites

Look carefully at these 2 lines they are different. Often a quote is needed. 

 

acAttachmentPointBottomCenter
'acAttachmentPointBottomCenter

 

(VLA-PUT-ATTACHMENTPOINT OBJ ACATTACHMENTPOINTBOTTOMCENTER)
; error : bad argument type <NIL> ; expected VLA-OBJECT at [vla-put-attachmentpoint]

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...