TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: PM on April 27, 2022, 01:54:01 PM

Title: Alay Text,Mtrext to line
Post by: PM on April 27, 2022, 01:54:01 PM
Hi i use Tharwat to alay text ,mtext on line. This code at the beginning work only for mtext. I add text and i change acAlignmentTopCenter to acAlignmentMiddleCenter. After this changes text work fine. But when i try to select mtext gives me this error

Quote
; error: ActiveX Server returned the error: unknown name: Alignment

I don't know why. Can any one help

Thanks

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Atcl (/ l ss i sn v p e)
  2. ;;; Tharwat 31. May. 2012 ;;;
  3.   (if (and (setq l (car (entsel "\n Select Line :")))
  4.            (eq (cdr (assoc 0 (entget l))) "LINE")
  5.            (progn
  6.              (prompt "SelectText,Mtext ")
  7.              (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
  8.            )
  9.       )
  10.     (repeat (setq i (sslength ss))
  11.       (setq sn (ssname ss (setq i (1- i))))
  12.       (setq v (vlax-ename->vla-object sn))
  13.                 l
  14.                 (cdr (assoc 10 (entget sn)))
  15.               )
  16.       )
  17.       (if (eq (cdr (assoc 0 (setq e (entget sn)))) "TEXT,MTEXT")
  18.         (progn
  19.           (entmod (subst (cons 71 5) (assoc 71 e) e))
  20.           (vla-put-insertionpoint v (vlax-3d-point p))
  21.         )
  22.         (progn
  23.          ;(vla-put-alignment v acAlignmentTopCenter)
  24.           (vla-put-alignment v acAlignmentMiddleCenter)
  25.         )
  26.       )
  27.     )
  28.   )
  29.   (princ)
  30. )
  31.  
  32.  
Title: Re: Alay Text,Mtrext to line
Post by: ronjonp on April 27, 2022, 02:32:56 PM
As the error states alignment is not one of the properties of MTEXT. You will need to check if the item is MTEXT or TEXT then apply the appropriate properties.

Use this to inspect what properties are available.
Code - Auto/Visual Lisp: [Select]
  1. (if (setq e (car (entsel)))
  2.   (vlax-dump-object (vlax-ename->vla-object e) t)
  3. )
  4. ;; or
  5. (dumpallproperties (car (entsel)))
  6. ;; or
https://help.autodesk.com/view/ACD/2023/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30
Title: Re: Alay Text,Mtrext to line
Post by: PM on April 28, 2022, 10:45:03 AM
I don't know how to fix it.Can any one help?

Thanks
Title: Re: Alay Text,Mtrext to line
Post by: BIGAL on April 28, 2022, 08:11:52 PM
like this

Code: [Select]
(setq ent (cdr (assoc 0 (setq e (entget sn)))))
(if (or (eq ent  "TEXT") (eq ent "MTEXT"))
        (progn
          (entmod (subst (cons 71 5) (assoc 71 e) e))
          (vla-put-insertionpoint v (vlax-3d-point p))
       
(if (eq ent "TEXT)
        (progn
         ;(vla-put-alignment v acAlignmentTopCenter)
          (vla-put-alignment v acAlignmentMiddleCenter)
          (vla-put-TextAlignmentPoint v (vlax-3D-point p))
        )
(progn
       ;  do the mtext stuff here
        )
)
)
      )
Title: Re: Alay Text,Mtrext to line
Post by: PM on April 29, 2022, 02:53:25 AM
Hi BIIGAL. Thanks for the replay. I try your code. Move Text and Mtext on the line but rotate upside down all the Text and i don't know why?


Code - Auto/Visual Lisp: [Select]
  1.     (defun c:test (/ l ss i sn v p e)
  2.     (vl-load-com)
  3.     ;;; Tharwat 31. May. 2012 ;;;
  4.       (if (and (setq l (car (entsel "\n Select Line :")))
  5.                (eq (cdr (assoc 0 (entget l))) "LINE")
  6.                (progn
  7.                  (prompt "SelectText,Mtext ")
  8.                  (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
  9.                )
  10.           )
  11.         (repeat (setq i (sslength ss))
  12.           (setq sn (ssname ss (setq i (1- i))))
  13.           (setq v (vlax-ename->vla-object sn))
  14.                     l
  15.                     (cdr (assoc 10 (entget sn)))
  16.                   )
  17.           )
  18.  
  19.  
  20. (setq ent (cdr (assoc 0 (setq e (entget sn)))))
  21. (if (or (eq ent  "TEXT") (eq ent "MTEXT"))
  22.         (progn
  23.           (entmod (subst (cons 71 5) (assoc 71 e) e))
  24.           (vla-put-insertionpoint v (vlax-3d-point p))
  25.        
  26.                 (if (eq ent "TEXT")
  27.         (progn
  28.          ;(vla-put-alignment v acAlignmentTopCenter)
  29.           (vla-put-alignment v acAlignmentMiddleCenter)
  30.         )
  31.         (progn
  32.        ;  do the mtext stuff here
  33.                  (vla-put-alignment v acAlignmentMiddleCenter)
  34.         )
  35.                 )
  36.                 )
  37.       )
  38.  
  39.  
  40.          
  41.         )
  42.       )
  43.       (princ)
  44.     )
  45.      
  46.  

Thanks
Title: Re: Alay Text,Mtrext to line
Post by: PM on May 03, 2022, 07:00:01 PM
Any ideas?

Thanks